Purpose of the flow
This flow manages the switching of one light in a room through the use of multiple sensors and also optionally allows, when you leave the room, the usage of a physical button to avoid waiting for the sensors to switch off the light .
The motion sensors (in this example there are three but you can be increase them) are divided into “trigger” sensors, that is, those that, if simultaneously active, turn on the light and “maintain” sensors, that is, those that, if active, only prevent the light from turning off .
How it works
The top of the flow represents a typical implementation of a multisensor motion light app.
Not being able to act on the occupancy status of the sensors to deactivate them when the physical button of the switch is pressed, I decided to store the status of the sensors and of the switch in global variables of the flow type using those variables in the flow logic. Switching off via the switch button simply clears the variables.
The user, after having switched off the light with the physical button, has 3 seconds to exit the detection zone of the trigger sensors and therefore prevent the light from switching on again due to the implemented automation.
Points of attention
The implementation of the physical button management is dependent on the user legacy switch. I used a bticino zigbee inwall switch, but the underlying logic should also apply to other brands of switches, as long as they send a notification message if the physical button is used.
[{"id":"7fbbdba721a89b97","type":"tab","label":"CUCINA","disabled":false,"info":"","env":[]},{"id":"8620dc0d8e48a371","type":"group","z":"7fbbdba721a89b97","name":"TRIGGER SENSORS","style":{"label":true},"nodes":["49d68c3813d21451","f2e80f0725395bb8","b5b3ad1c197baf30","6e018b218495f9ee","51968669ebef358d","40759a3f13e8fe06"],"x":74,"y":79,"w":592,"h":122},{"id":"8d37ea1c4d078adf","type":"group","z":"7fbbdba721a89b97","name":"OTHER MOTION SENSORS TO KEEP ","style":{"label":true},"nodes":["4d660266de9b78e0","74b66901806ca4ef","b6b4a396e0b772f7"],"x":74,"y":219,"w":592,"h":82},{"id":"d98c385ff654245a","type":"group","z":"7fbbdba721a89b97","name":"PHYSICAL BUTTON MANAGEMENT","style":{"label":true},"nodes":["c90b36c3d663ef7f","ea64e6b165473af4","0602fa6f2943036d","20d50f7f1d5b50d4","cc1d12dcc73ef143","14c798dea7e7e233","f7f16a90f3ff98af","bbac0bf76575a6ec"],"x":74,"y":359,"w":1052,"h":202},{"id":"a4f62693605d3f46","type":"stoptimer2","z":"7fbbdba721a89b97","duration":"60","durationType":"num","units":"Second","payloadtype":"num","payloadval":"0","name":"45","x":1430,"y":240,"wires":[["34de61f10d1f2d4b"],[]]},{"id":"ebb8697785586fa4","type":"switch","z":"7fbbdba721a89b97","name":"MT09","property":"#:(ram)::MT09.occupancy","propertyType":"flow","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":950,"y":240,"wires":[["d02c49c182a2ff15"]]},{"id":"d02c49c182a2ff15","type":"switch","z":"7fbbdba721a89b97","name":"MT08","property":"#:(ram)::MT08.occupancy","propertyType":"flow","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":1090,"y":240,"wires":[["e07349ea7dcb8a64"]]},{"id":"15ed7a39e934c805","type":"change","z":"7fbbdba721a89b97","name":"STOP ","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1250,"y":160,"wires":[["a4f62693605d3f46"]]},{"id":"49d68c3813d21451","type":"change","z":"7fbbdba721a89b97","g":"8620dc0d8e48a371","name":"set flow.MT09","rules":[{"t":"set","p":"#:(ram)::MT09","pt":"flow","to":"payload","tot":"msg","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":120,"wires":[["62523b067ec79220"]]},{"id":"f2e80f0725395bb8","type":"change","z":"7fbbdba721a89b97","g":"8620dc0d8e48a371","name":"set flow.MT08","rules":[{"t":"set","p":"#:(ram)::MT08","pt":"flow","to":"payload","tot":"msg","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":160,"wires":[["62523b067ec79220"]]},{"id":"e07349ea7dcb8a64","type":"change","z":"7fbbdba721a89b97","name":"START","rules":[{"t":"set","p":"payload","pt":"msg","to":"START","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1240,"y":240,"wires":[["a4f62693605d3f46"]]},{"id":"1a42ca03847b6f72","type":"change","z":"7fbbdba721a89b97","name":"On","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"state\":\"on\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":1570,"y":140,"wires":[["f664f8a4ba9feb1f"]]},{"id":"34de61f10d1f2d4b","type":"change","z":"7fbbdba721a89b97","name":"Off","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"state\":\"off\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":1570,"y":180,"wires":[["f664f8a4ba9feb1f"]]},{"id":"84f94a2842617025","type":"comment","z":"7fbbdba721a89b97","name":"Get sensor occupancy value, if it changed store new status. ----------------------------------------------- Check occupancy status","info":"","x":480,"y":40,"wires":[]},{"id":"75e1c42c6eaf158b","type":"comment","z":"7fbbdba721a89b97","name":"NO: If all sensors are false, start delay timer before to switch off","info":"","x":1130,"y":200,"wires":[]},{"id":"3d0a636787c908e4","type":"comment","z":"7fbbdba721a89b97","name":"Send ON/OFF commands","info":"","x":1630,"y":80,"wires":[]},{"id":"4d660266de9b78e0","type":"change","z":"7fbbdba721a89b97","g":"8d37ea1c4d078adf","name":"set flow.MT07","rules":[{"t":"set","p":"#:(ram)::MT07","pt":"flow","to":"payload","tot":"msg","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":260,"wires":[["62523b067ec79220"]]},{"id":"eeb0ae772ade2e13","type":"switch","z":"7fbbdba721a89b97","name":"MT09","property":"#:(ram)::MT09.occupancy","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":950,"y":120,"wires":[["67b8d7abb150f9a0"]]},{"id":"67b8d7abb150f9a0","type":"switch","z":"7fbbdba721a89b97","name":"MT08","property":"#:(ram)::MT08.occupancy","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":1090,"y":120,"wires":[["0dddb466211984ac"]]},{"id":"a9bce4c7075ac5db","type":"comment","z":"7fbbdba721a89b97","name":"YES: stop pending timer if any, if all trigger sensors are true, switch on","info":" 1. ","x":1150,"y":80,"wires":[]},{"id":"b5b3ad1c197baf30","type":"zigbee2mqtt-in","z":"7fbbdba721a89b97","g":"8620dc0d8e48a371","name":"MT09-CUCINA-MURO","server":"411e2b8e9bdac70b","friendly_name":"MT09-CUCINA-MURO (SNZB-03)","device_id":"0x00124b001f90d0ed","state":"0","outputAtStartup":true,"filterChanges":false,"enableMultiple":false,"x":200,"y":120,"wires":[["51968669ebef358d"]]},{"id":"6e018b218495f9ee","type":"zigbee2mqtt-in","z":"7fbbdba721a89b97","g":"8620dc0d8e48a371","name":"MT08-CUCINA-CAPPA","server":"411e2b8e9bdac70b","friendly_name":"MT08-CUCINA-CAPPA (9290030675)","device_id":"0x001788010bcfe767","state":"0","outputAtStartup":true,"filterChanges":false,"enableMultiple":false,"x":200,"y":160,"wires":[["40759a3f13e8fe06"]]},{"id":"74b66901806ca4ef","type":"zigbee2mqtt-in","z":"7fbbdba721a89b97","g":"8d37ea1c4d078adf","name":"MT07-CUCINA-TAVOLO","server":"411e2b8e9bdac70b","friendly_name":"MT07-CUCINA-TAVOLO (SNZB-03)","device_id":"0x00124b001f90d701","state":"0","outputAtStartup":true,"filterChanges":false,"enableMultiple":false,"x":210,"y":260,"wires":[["b6b4a396e0b772f7"]]},{"id":"62523b067ec79220","type":"switch","z":"7fbbdba721a89b97","name":"occupied?","property":"payload.occupancy","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":790,"y":180,"wires":[["15ed7a39e934c805","eeb0ae772ade2e13"],["ebb8697785586fa4"]]},{"id":"0dddb466211984ac","type":"switch","z":"7fbbdba721a89b97","name":"<= LUX","property":"#:(ram)::MT08.illuminance_lux","propertyType":"flow","rules":[{"t":"lt","v":"55","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1240,"y":120,"wires":[["1a42ca03847b6f72"]]},{"id":"f664f8a4ba9feb1f","type":"zigbee2mqtt-out","z":"7fbbdba721a89b97","name":"SW05-CUCINA","server":"411e2b8e9bdac70b","friendly_name":"SW05-CUCINA (K4003C/L4003C/N4003C/NT4003C)","device_id":"0x000474000113e511","command":"state","commandType":"z2m_cmd","payload":"payload","payloadType":"msg","optionsValue":"","optionsType":"nothing","x":1720,"y":160,"wires":[]},{"id":"c90b36c3d663ef7f","type":"zigbee2mqtt-in","z":"7fbbdba721a89b97","g":"d98c385ff654245a","name":"SW05-CUCINA","server":"411e2b8e9bdac70b","friendly_name":"SW05-CUCINA (K4003C/L4003C/N4003C/NT4003C)","device_id":"0x000474000113e511","state":"0","outputAtStartup":true,"filterChanges":true,"enableMultiple":false,"x":180,"y":480,"wires":[["0602fa6f2943036d"]]},{"id":"ea64e6b165473af4","type":"comment","z":"7fbbdba721a89b97","g":"d98c385ff654245a","name":"Check if physical button was pushed ","info":"","x":240,"y":400,"wires":[]},{"id":"0602fa6f2943036d","type":"switch","z":"7fbbdba721a89b97","g":"d98c385ff654245a","name":"physical button?","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"identify","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":360,"y":480,"wires":[["14c798dea7e7e233"],["20d50f7f1d5b50d4"]]},{"id":"20d50f7f1d5b50d4","type":"change","z":"7fbbdba721a89b97","g":"d98c385ff654245a","name":"","rules":[{"t":"set","p":"#:(ram)::SW05","pt":"flow","to":"payload","tot":"msg","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":520,"wires":[[]]},{"id":"cc1d12dcc73ef143","type":"function","z":"7fbbdba721a89b97","g":"d98c385ff654245a","name":"delete flow.MT*","func":"flow.set(\"MT09\");\nflow.set(\"MT08\");\nflow.set(\"MT07\");\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":740,"y":440,"wires":[[]]},{"id":"14c798dea7e7e233","type":"stoptimer2","z":"7fbbdba721a89b97","g":"d98c385ff654245a","duration":"3","durationType":"num","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":560,"y":440,"wires":[["cc1d12dcc73ef143"],[]]},{"id":"51968669ebef358d","type":"switch","z":"7fbbdba721a89b97","g":"8620dc0d8e48a371","name":"changed?","property":"payload.occupancy","propertyType":"msg","rules":[{"t":"neq","v":"#:(ram)::MT09.ccupancy","vt":"flow"}],"checkall":"true","repair":false,"outputs":1,"x":400,"y":120,"wires":[["49d68c3813d21451"]]},{"id":"40759a3f13e8fe06","type":"switch","z":"7fbbdba721a89b97","g":"8620dc0d8e48a371","name":"changed?","property":"payload.occupancy","propertyType":"msg","rules":[{"t":"neq","v":"#:(ram)::MT08.occupancy","vt":"flow"}],"checkall":"true","repair":false,"outputs":1,"x":400,"y":160,"wires":[["f2e80f0725395bb8"]]},{"id":"b6b4a396e0b772f7","type":"switch","z":"7fbbdba721a89b97","g":"8d37ea1c4d078adf","name":"changed?","property":"payload.occupancy","propertyType":"msg","rules":[{"t":"neq","v":"#:(ram)::MT07.occupancy","vt":"flow"}],"checkall":"true","repair":false,"outputs":1,"x":400,"y":260,"wires":[["4d660266de9b78e0"]]},{"id":"f7f16a90f3ff98af","type":"comment","z":"7fbbdba721a89b97","g":"d98c385ff654245a","name":"YES: delay few seconds (to avoid sensor rebouncing), and delete all motion flow variables ","info":"","x":790,"y":400,"wires":[]},{"id":"bbac0bf76575a6ec","type":"comment","z":"7fbbdba721a89b97","g":"d98c385ff654245a","name":"NO: store status of the switch","info":"","x":600,"y":480,"wires":[]},{"id":"411e2b8e9bdac70b","type":"zigbee2mqtt-server","name":"CORE","host":"10.10.2.1","mqtt_port":"1883","mqtt_username":"","mqtt_password":"","mqtt_qos":"0","tls":"","usetls":false,"base_topic":"zigbee2mqtt"}]
The comments inside the flow should help to understand the internal logic.
Curiosities
The “in line” check of the occupancy state of the trigger sensors is the equivalent of an AND.
If you would like to make an equivalent of the HE zones, you could insert also the maintain nodes.