Shelly motion and door alarm via telegram bot

Sample flow demonstrates how to poll a shelly door and shelly motion device and issue an alarm whenever a motion or change in door state is detected.

The alarm is sent via telegram, but could by anything else.

Used nodes:

  • node-red-contrib-shelly
  • node-red-contrib-telegrambot
[{"id":"13474f6d.cfac91","type":"telegram sender","z":"5882ea6c.1d8c3c","name":"","bot":"59e305c4.e5a97c","haserroroutput":false,"outputs":1,"x":830,"y":80,"wires":[[]]},{"id":"b9e5cd2c.db49b","type":"function","z":"5882ea6c.1d8c3c","name":"send markdown","func":"var message = msg.payload;\nmsg.payload = {chatId : 138708568, type : 'message', content : message};\n\n// activate markdown\nmsg.payload.options = {disable_web_page_preview : true, parse_mode : \"Markdown\"};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":80,"wires":[["13474f6d.cfac91"]]},{"id":"f51fd3de.ede7c","type":"shelly-motion","z":"5882ea6c.1d8c3c","hostname":"192.168.178.250","description":"Motion","pollinginterval":"3000","hasextraoutputs":false,"outputs":1,"x":90,"y":60,"wires":[["316ec0eb.a1532"]]},{"id":"23011dc0.204432","type":"shelly-door","z":"5882ea6c.1d8c3c","hostname":"192.168.178.249","description":"Door","usepolling":true,"pollinginterval":"3000","inputs":0,"x":90,"y":120,"wires":[["99881d9e.bac2b"]]},{"id":"316ec0eb.a1532","type":"function","z":"5882ea6c.1d8c3c","name":"Alarm","func":"if(msg.payload.sensor !== undefined){\n    \n    var lastValue = flow.get(\"Bewegungsmelder\");\n    var newValue = msg.payload.sensor.motion;\n    \n    if(lastValue != newValue){\n\n        if(newValue === true){\n            msg.payload = \"Bewegunsgmelder Alarm\";\n        }\n        \n        flow.set(\"Bewegungsmelder\", newValue);\n        return msg;\n    }\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":60,"wires":[["b9e5cd2c.db49b"]]},{"id":"99881d9e.bac2b","type":"function","z":"5882ea6c.1d8c3c","name":"Alarm","func":"if(msg.payload.sensor !== undefined){\n    \n    var lastValue = flow.get(\"Garagentuere\");\n    var newValue = msg.payload.sensor.state;\n    \n    if(lastValue != newValue){\n\n        if(newValue === 'open'){\n            msg.payload = \"Garagentuere geöffnet\";\n        } \n        \n        if(newValue === 'close'){\n            msg.payload = \"Garagentuere geschlossen\";\n        }\n        \n        flow.set(\"Garagentuere\", newValue);\n        return msg;\n    }\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":120,"wires":[["b9e5cd2c.db49b"]]},{"id":"59e305c4.e5a97c","type":"telegram bot","botname":"MotzBot","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":false}]

Flow Info

Created 3 years, 8 months ago
Rating: 5 1

Owner

Actions

Rate:

Node Types

Core
  • function (x3)
Other

Tags

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