MQTT Alarmserver as a Lightswitch
Q: I want to use the cameras PIR sensor to switch on motion detection area 1 and link the area with the PIR sensor. Now, only when both - the PIR and Area1 - are triggered, I want to switch on an external light in front of my house.
A: Here is an example how this problem can be solved in Node-RED using the MQTT Alarmserver.
The PIR is triggered updating the alarm/triggered
MQTT topic with a payload value of 5. I am now using this trigger to switch the area1 alarm/area1/enable
on and link it to the PIR alarm/actions/linkareas
. They are switched off again once the alarm server falls back to idle with a payload value of 0 - this happens after 5 seconds, which might be a bit too fast for your use case. You can replace this with an personal timer.
Once area1 is active and linked the next alarm trigger will have the value 7) (PIR + Area1 triggered). This trigger will then be used to switch on a light that is also connected to Node-RED - this implementation is not part of the example flow.
Node-RED Flow Export
[{"id":"52d8de5c.878f4","type":"tab","label":"INSTAR Alarmserver","disabled":false,"info":""},{"id":"a071baf8.e4db18","type":"mqtt in","z":"52d8de5c.878f4","name":"status/alarm/triggered","topic":"cameras/117/status/alarm/triggered","qos":"1","datatype":"auto","broker":"7553a41d.22b8bc","x":107,"y":76,"wires":[["27e5d697.4c750a","a076e8c3.98bbd8"]]},{"id":"a076e8c3.98bbd8","type":"debug","z":"52d8de5c.878f4","name":"Alarmserver","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":297,"y":25,"wires":[]},{"id":"27e5d697.4c750a","type":"switch","z":"52d8de5c.878f4","name":"0 / 5 / 7","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"{\"val\":\"0\"}","vt":"str"},{"t":"eq","v":"{\"val\":\"5\"}","vt":"str"},{"t":"eq","v":"{\"val\":\"7\"}","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":287,"y":76,"wires":[["472c5b6d.4e03d4","a4e93b6b.595ed8"],["d1f7562c.1d9bf8","7bddd11d.f8ee2"],["b09b8001.82bf7"]]},{"id":"a4e93b6b.595ed8","type":"change","z":"52d8de5c.878f4","name":"0","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"val\":\"0\"}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":462,"y":81,"wires":[["3778f880.f4f898"]]},{"id":"b635569a.0f6418","type":"mqtt out","z":"52d8de5c.878f4","name":"alarm/actions/linkareas","topic":"cameras/117/alarm/actions/linkareas","qos":"1","retain":"false","broker":"7553a41d.22b8bc","x":669,"y":68,"wires":[]},{"id":"472c5b6d.4e03d4","type":"change","z":"52d8de5c.878f4","name":"off","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"val\":\"off\"}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":462,"y":43,"wires":[["b635569a.0f6418"]]},{"id":"b09b8001.82bf7","type":"change","z":"52d8de5c.878f4","name":"fiat lux","rules":[{"t":"set","p":"payload","pt":"msg","to":"fiat lux","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":459,"y":198,"wires":[["eb589db.cc37e6"]]},{"id":"eb589db.cc37e6","type":"debug","z":"52d8de5c.878f4","name":"Light Switch","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":599,"y":198,"wires":[]},{"id":"7bddd11d.f8ee2","type":"change","z":"52d8de5c.878f4","name":"1","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"val\":\"1\"}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":462,"y":156,"wires":[["3778f880.f4f898"]]},{"id":"d1f7562c.1d9bf8","type":"change","z":"52d8de5c.878f4","name":"on","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"val\":\"on\"}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":462,"y":118,"wires":[["b635569a.0f6418"]]},{"id":"3778f880.f4f898","type":"mqtt out","z":"52d8de5c.878f4","name":"alarm/area1/enable","topic":"cameras/117/alarm/area1/enable","qos":"1","retain":"false","broker":"7553a41d.22b8bc","x":650,"y":115,"wires":[]},{"id":"7553a41d.22b8bc","type":"mqtt-broker","name":"192.168.2.117","broker":"192.168.2.117","port":"8883","tls":"c411fab7.e16228","clientid":"","usetls":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"c411fab7.e16228","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"mqtt_client-new.crt","keyname":"","caname":"","servername":"","verifyservercert":false}]