Domoticz Capture Dahua Image and pass to Telegram

This is my first try with Node-Red.

Based on node-red-contrib-telegrambot, I wanted to grab an image, from one or more of my Dahua IP Cameras ,in case of an event (Door Opened, Doorbell pressed) and have that image transferred to me via Telegram.

Dahua has different types of Authentication Mechanisms (Basic , Digest e.g.) and each camera has it's own Capture URL. To achieve this I created several http-request nodes with for each camera its own url + authentication type.

Workings:

  • It all starts with Domoticz/Out (the trigger), that Data is parsed into a JSON.
  • Next I check if msg.payload.name has the item I'm interested in.
  • I connect the msg.payload.name output with the Camera's names I want to trigger.
  • The message that will be the telegram image caption will be created in the function.
  • Next (and in my case it is a sub-flow) the camera selector calls the appropriate camera (url).
  • In parallel in generates additional information for Telegram (put your clientid in here).
  • The Join function will wait for message + image and if received create the message towards Telegram.

If all goes well you will receive an image with caption in Telegram.

[{"id":"86fe9b81.31c418","type":"http request","z":"6bd7f13b.b61ad","name":"","method":"GET","ret":"bin","paytoqs":"ignore","url":"http://192.168.20.3/cgi-bin/snapshot.cgi?Channel=0","tls":"","persist":false,"proxy":"","authType":"basic","x":1310,"y":1260,"wires":[["1d782852.063468"]]},{"id":"e84e953f.c70fe8","type":"http request","z":"6bd7f13b.b61ad","name":"","method":"GET","ret":"bin","paytoqs":"ignore","url":"http://192.168.20.4/cgi-bin/snapshot.cgi?1","tls":"","persist":false,"proxy":"","authType":"digest","x":1310,"y":1340,"wires":[["f711e5ec.5d4f78"]]},{"id":"dbcd435e.78d45","type":"http request","z":"6bd7f13b.b61ad","name":"","method":"GET","ret":"bin","paytoqs":"ignore","url":"http://192.168.20.9/cgi-bin/snapshot.cgi?Channel=0","tls":"","persist":false,"proxy":"","authType":"digest","x":1310,"y":1420,"wires":[["763884e.a87d37c"]]},{"id":"b80cdb94.ccae18","type":"http request","z":"6bd7f13b.b61ad","name":"","method":"GET","ret":"bin","paytoqs":"ignore","url":"http://192.168.20.6/cgi-bin/snapshot.cgi?1","tls":"","persist":false,"proxy":"","authType":"digest","x":1310,"y":1500,"wires":[["acbc5e23.3c77c"]]},{"id":"cf3a332d.60c39","type":"http request","z":"6bd7f13b.b61ad","name":"","method":"GET","ret":"bin","paytoqs":"ignore","url":"http://192.168.20.2/cgi-bin/snapshot.cgi?1","tls":"","persist":false,"proxy":"","authType":"digest","x":1310,"y":1580,"wires":[["93ac899a.8a9778"]]},{"id":"f2e0cb5f.45b7c8","type":"switch","z":"6bd7f13b.b61ad","name":"Camera Selector","property":"payload.camera","propertyType":"msg","rules":[{"t":"eq","v":"Voordeur Rechts","vt":"str"},{"t":"eq","v":"Voordeur Links","vt":"str"},{"t":"eq","v":"Hal","vt":"str"},{"t":"eq","v":"Keuken","vt":"str"},{"t":"eq","v":"Berging","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":1010,"y":1420,"wires":[["86fe9b81.31c418","54ecd869.a2ead8"],["e84e953f.c70fe8","54ecd869.a2ead8"],["dbcd435e.78d45","54ecd869.a2ead8"],["b80cdb94.ccae18","54ecd869.a2ead8"],["cf3a332d.60c39","54ecd869.a2ead8"]]},{"id":"54ecd869.a2ead8","type":"function","z":"6bd7f13b.b61ad","name":"Create Telegram Message","func":"var message = msg.payload.message;\n\nmsg.payload = {\n    \"caption\": message,\n    \"type\": \"photo\",\n    // Put your Chat ID in here:\n    \"chatId\": \"xxxxxxxxxxx\"\n}\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1360,"y":1200,"wires":[["e8055f05.e5e4f"]]},{"id":"93f05e40.350ce","type":"join","z":"6bd7f13b.b61ad","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1670,"y":1580,"wires":[["4adbde36.75fd2"]]},{"id":"1d782852.063468","type":"change","z":"6bd7f13b.b61ad","name":"Move Payload","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.content","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1480,"y":1260,"wires":[["f6693e43.092d9"]]},{"id":"f6693e43.092d9","type":"join","z":"6bd7f13b.b61ad","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1670,"y":1260,"wires":[["4adbde36.75fd2"]]},{"id":"f711e5ec.5d4f78","type":"change","z":"6bd7f13b.b61ad","name":"Move Payload","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.content","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1480,"y":1340,"wires":[["bcdd71f8.aa603"]]},{"id":"bcdd71f8.aa603","type":"join","z":"6bd7f13b.b61ad","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1670,"y":1340,"wires":[["4adbde36.75fd2"]]},{"id":"763884e.a87d37c","type":"change","z":"6bd7f13b.b61ad","name":"Move Payload","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.content","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1480,"y":1420,"wires":[["554d039f.3a72ec"]]},{"id":"554d039f.3a72ec","type":"join","z":"6bd7f13b.b61ad","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1670,"y":1420,"wires":[["4adbde36.75fd2"]]},{"id":"acbc5e23.3c77c","type":"change","z":"6bd7f13b.b61ad","name":"Move Payload","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.content","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1480,"y":1500,"wires":[["c3f9570f.bd6b78"]]},{"id":"c3f9570f.bd6b78","type":"join","z":"6bd7f13b.b61ad","name":"","mode":"custom","build":"merged","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1670,"y":1500,"wires":[["4adbde36.75fd2"]]},{"id":"93ac899a.8a9778","type":"change","z":"6bd7f13b.b61ad","name":"Move Payload","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.content","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1480,"y":1580,"wires":[["93f05e40.350ce"]]},{"id":"e8055f05.e5e4f","type":"link out","z":"6bd7f13b.b61ad","name":"","links":["cba4991a.750998","d972aadc.94cb78","693af8b9.876e28","dc24617f.29c84","83b60540.55b568"],"x":1535,"y":1200,"wires":[]},{"id":"cba4991a.750998","type":"link in","z":"6bd7f13b.b61ad","name":"","links":["e8055f05.e5e4f"],"x":1615,"y":1200,"wires":[["f6693e43.092d9"]]},{"id":"d972aadc.94cb78","type":"link in","z":"6bd7f13b.b61ad","name":"","links":["e8055f05.e5e4f"],"x":1615,"y":1300,"wires":[["bcdd71f8.aa603"]]},{"id":"693af8b9.876e28","type":"link in","z":"6bd7f13b.b61ad","name":"","links":["e8055f05.e5e4f"],"x":1615,"y":1380,"wires":[["554d039f.3a72ec"]]},{"id":"dc24617f.29c84","type":"link in","z":"6bd7f13b.b61ad","name":"","links":["e8055f05.e5e4f"],"x":1615,"y":1460,"wires":[["c3f9570f.bd6b78"]]},{"id":"83b60540.55b568","type":"link in","z":"6bd7f13b.b61ad","name":"","links":["e8055f05.e5e4f"],"x":1615,"y":1540,"wires":[["93f05e40.350ce"]]},{"id":"4adbde36.75fd2","type":"telegram sender","z":"6bd7f13b.b61ad","name":"Botje","bot":"6f7be851.bfd838","haserroroutput":false,"outputs":1,"x":1850,"y":1420,"wires":[[]]},{"id":"8ccddb9a.a55f38","type":"inject","z":"6bd7f13b.b61ad","name":"Testknop","props":[{"p":"payload.name","v":"Mailbox","vt":"str"},{"p":"payload.nvalue","v":"1","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":520,"y":860,"wires":[["56264842.4fc4b8","47f23fca.fc06a","ff09e329.8292","6be9d6b4.9ea278","c65068a9.4007d8"]]},{"id":"56264842.4fc4b8","type":"change","z":"6bd7f13b.b61ad","name":"Camera Hal","rules":[{"t":"set","p":"payload.camera","pt":"msg","to":"Hal","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":900,"wires":[["cf3de818.e1ec08"]]},{"id":"cf3de818.e1ec08","type":"function","z":"6bd7f13b.b61ad","name":"Determine message content","func":"var name = msg.payload.name;\nvar nvalue = msg.payload.nvalue;\nvar camera = msg.payload.camera;\nvar message = \"\";\nvar messagetail = \"\";\n\nif (name == \"Mailbox\") { message = \"Er is zojuist post bezorgd\"; }\nelse if (name == \"Deurbel (Bernini 15)\") { message = \"Er is zojuist aangebeld\"; }\nelse \n{\n    if (msg.payload.nvalue === 1)\n    {\n        if (name.includes(\"Deur\")) { messagetail = \" geopend\"; }\n        else message = name+\" Ingeschakeld\";\n    }\n    else if (msg.payload.nvalue === 0)\n    {\n        if (name.includes(\"Deur\")) { messagetail = \" gesloten\"; }\n        else message = name+\" Uitgeschakeld\";\n    }\n}\n\nmsg.payload = {\n    \"camera\": camera,\n    \"message\": message+messagetail,\n    \"devicename\" : name,\n    \"nvalue\" : nvalue\n}\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1180,"y":980,"wires":[["f2e0cb5f.45b7c8"]]},{"id":"47f23fca.fc06a","type":"change","z":"6bd7f13b.b61ad","name":"Camera Keuken","rules":[{"t":"set","p":"payload.camera","pt":"msg","to":"Keuken","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":940,"wires":[["cf3de818.e1ec08"]]},{"id":"ff09e329.8292","type":"change","z":"6bd7f13b.b61ad","name":"Camera Voordeur Links","rules":[{"t":"set","p":"payload.camera","pt":"msg","to":"Voordeur Links","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":980,"wires":[["cf3de818.e1ec08"]]},{"id":"6be9d6b4.9ea278","type":"change","z":"6bd7f13b.b61ad","name":"Camera Voordeur Rechts","rules":[{"t":"set","p":"payload.camera","pt":"msg","to":"Voordeur Rechts","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":1020,"wires":[["cf3de818.e1ec08"]]},{"id":"c65068a9.4007d8","type":"change","z":"6bd7f13b.b61ad","name":"Camera Berging","rules":[{"t":"set","p":"payload.camera","pt":"msg","to":"Berging","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":1060,"wires":[["cf3de818.e1ec08"]]},{"id":"bdad5023.deccd","type":"mqtt in","z":"6bd7f13b.b61ad","name":"","topic":"domoticz/out","qos":"2","datatype":"auto","broker":"df52700c.0c65c","x":150,"y":980,"wires":[["3896e89a.366ee8"]]},{"id":"3896e89a.366ee8","type":"json","z":"6bd7f13b.b61ad","name":"json convert","property":"payload","action":"","pretty":false,"x":330,"y":980,"wires":[["2dbcdb7f.55db24"]]},{"id":"2dbcdb7f.55db24","type":"switch","z":"6bd7f13b.b61ad","name":"idx_check","property":"payload.name","propertyType":"msg","rules":[{"t":"eq","v":"Deur Voordeur","vt":"str"},{"t":"eq","v":"Mailbox","vt":"str"},{"t":"eq","v":"Deur (Schuifpui)","vt":"str"},{"t":"eq","v":"Deurbel","vt":"str"}],"checkall":"false","repair":false,"outputs":4,"x":520,"y":980,"wires":[["ff09e329.8292","6be9d6b4.9ea278"],["56264842.4fc4b8"],["47f23fca.fc06a"],["ff09e329.8292","6be9d6b4.9ea278"]]},{"id":"6f7be851.bfd838","type":"telegram bot","botname":"Telegrambot","usernames":"","chatids":"","baseapiurl":"","updatemode":"polling","pollinterval":"300","usesocks":false,"sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","botpath":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","useselfsignedcertificate":false,"sslterminated":false,"verboselogging":true},{"id":"df52700c.0c65c","type":"mqtt-broker","name":"MQTT","broker":"192.168.1.11","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Flow Info

Created 4 years, 9 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x10)
  • function (x2)
  • http request (x5)
  • inject (x1)
  • join (x5)
  • json (x1)
  • link in (x5)
  • link out (x1)
  • mqtt in (x1)
  • mqtt-broker (x1)
  • switch (x2)
Other

Tags

  • node-red-contrib-telegrambot
  • dahua
  • domoticz
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option