Help to rest motion sensor light flow when switch is manually pressed

Hi

I’ve just started using node-red and I have a very basic flow with my motion sensor and light.

Between sunset and sunrise, if motion is detected in the toilet on the sensor, the toilet light goes on. After 5 minutes it goes off, unless it detects another motion in that time and resets the timer. (The 5 minutes determined by my partner and is non-negotiable).

As 5 minutes is a long time, we will manually switch off the light using our wall mounted tablet dashboard. In doing so, this then stops the motion being picked up again if you were to walk in, say 30 seconds after.

How can I add a node in to the flow so if the light is manually turned off via the wall tablet, it is open to detect movement again at any opportunity?

[{"id":"b9531343880e604b","type":"server-state-changed","z":"0f294f53a3b13b68","g":"88c6a46ec3ce8ade","name":"motion","server":"ad57766.0cc8988","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.toilet_movement_sensor_occupancy","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":270,"y":460,"wires":[["aa3b4bf1b1c2da38"]]},{"id":"a9bc0b890a8dcc16","type":"api-call-service","z":"0f294f53a3b13b68","g":"88c6a46ec3ce8ade","name":"Toilet Light","server":"ad57766.0cc8988","version":5,"debugenabled":false,"domain":"light","service":"turn_{{payload}}","areaId":[],"deviceId":[],"entityId":["light.toilet"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":930,"y":460,"wires":[[]]},{"id":"b59223b488dabf96","type":"trigger","z":"0f294f53a3b13b68","g":"88c6a46ec3ce8ade","name":"","op1":"on","op2":"off","op1type":"str","op2type":"str","duration":"5","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":750,"y":460,"wires":[["a9bc0b890a8dcc16"]]},{"id":"aa3b4bf1b1c2da38","type":"time-range-switch","z":"0f294f53a3b13b68","g":"88c6a46ec3ce8ade","name":"lux","lat":"50","lon":"-0.18","startTime":"sunset","endTime":"sunrise","startOffset":"-60","endOffset":"+60","x":510,"y":460,"wires":[["b59223b488dabf96"],[]]},{"id":"ad57766.0cc8988","type":"server","name":"Home Assistant","addon":true}]

Not sure to understand what you want to achieve.
But if you add a switch in NodeRED, between motion and lux, you should be able to trigger or not the flow depending on a binary sensor (lets say so) and, after the 5 minutes, you just have to switch the binary_sensor back to off (or on, depending of your logic). And when the switch is on/off, you wait a few seconds, like 30, to allow the exit of the toilet before rearming the switch for the next motion.

It is good to try NodeRED but I’m doing the opposite, get back everything inside HA (except for very complex flows).

What you try to do is very easy to do in HA directly.

EDIT: I realise that I mix switch, binary_sensor in my reply. the switch in NodeRED is this image
Everything else in my answer is the binary_sensor, aka switch on your wall mounted tablet.

you could use an event:state node from your toilet.light entity when it turns off pass this into a change node to set msg.reset to true then pass this to the input of the trigger node which will reset the timer ready for next motion event.
you may need to change your motion event node to when state is on to prevent it turning the light back on for 5 minutes when the motion clears depending on the inbuilt delay to your sensor.
sorry I don’t have access to a NR instance to create the flow for you at the moment hopefully you can get the idea from this.

I wrote this flow to preserve manual control. (I am new to Node red)
It uses a luminance sensor for light (no need for lights if its already light).
It essentially checks to see if the light is already on when a motion is triggered. If it is it sets the flow variable to disable the motion. The function node checks the flow variable and before it hits the light off timer. If the variable is set to disabled the function node sends a msg.reset=“true” to “cancel” the delay timer.

Let me know what you think :slight_smile:

[{"id":"3888b8b0b40fa5ce","type":"server-state-changed","z":"64270b0ef811be4a","name":"NBedroomMotion","server":"bf831ac7.585868","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.north_bedroom_motion_iaszone_2","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":820,"y":360,"wires":[["707351860c6a455e"],["a3331074af833429"]]},{"id":"b12b42b976f2e3ac","type":"api-call-service","z":"64270b0ef811be4a","name":"devicesOff","server":"bf831ac7.585868","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":["light.living_room_recessed_light"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1310,"y":400,"wires":[[]]},{"id":"3ffcaa3a94a6abdb","type":"api-current-state","z":"64270b0ef811be4a","name":"Is it Dark?","server":"bf831ac7.585868","version":3,"outputs":2,"halt_if":"50","halt_if_type":"num","halt_if_compare":"lt","entity_id":"sensor.lumi_lumi_motion_ac02_illuminance_2","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"stop","valueType":"str"},{"property":"nBedroomlightmotion","propertyType":"flow","value":"enabled","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1140,"y":340,"wires":[["4e839496a3ee8be6"],["a3331074af833429"]]},{"id":"06b92bd0e914a790","type":"delay","z":"64270b0ef811be4a","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1140,"y":400,"wires":[["b12b42b976f2e3ac"]]},{"id":"4e839496a3ee8be6","type":"api-call-service","z":"64270b0ef811be4a","name":"devicesOn","server":"bf831ac7.585868","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.living_room_recessed_light"],"data":"","dataType":"jsonata","mergeContext":"brightness_pct=50","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1310,"y":340,"wires":[[]]},{"id":"707351860c6a455e","type":"api-current-state","z":"64270b0ef811be4a","name":"lightStaysOn","server":"bf831ac7.585868","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.living_room_recessed_light","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"nBedroomlightmotion","propertyType":"flow","value":"disabled","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":990,"y":340,"wires":[[],["3ffcaa3a94a6abdb"]]},{"id":"a3331074af833429","type":"function","z":"64270b0ef811be4a","name":"lightStaysOn","func":"msg.lightOn = flow.get(\"nBedroomlightmotion\");\nif (msg.lightOn == \"disabled\"){\nmsg.topic = \"someone wants the light on\"\nmsg.payload=\"cancel the motion off\";\nmsg.reset = \"true\";\n}\nelse{msg.payload=\"off\";\nmsg.topic = \"start timer off\"}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":990,"y":400,"wires":[["06b92bd0e914a790"]]},{"id":"bf831ac7.585868","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false}]