Node RED & Light on motion - how to bypass smart button?

Hello everyone,

I have been relying a lot on the community for the past two years, since I started playing with HA, to get things going. So far, I’ve been able to find ressources and help across many posts and topics that could fit my needs. But today is a first : after spending hours and days looking for pointers, I wasn’t able to dig out anything relevant for my usecase. Hopefully someone will have an idea !

What I’m trying to achieve
I have a philips hue lightbulb in my kitchen, controlled buy a Philips smart button. So far, so good.
I put an aqara motion sensor in the kitchen, to turn on light when there is motion and to turn off when no more motion is detected after 2 minutes.
Thanks to Node RED, it works like it should, except for one thing :

The issue
I want the smart button to remain where it is and to keep working the normal way, in case some guests are searching for a traditionnal way to turn off the light. So, in other terms :

  • If the light is turned on via the motion sensor, it can be turned off manually via one press on the button
  • If the light is already turned on, several presses on the button can switch to other scenes (standard configuration of the Philips Hue smart button)

My issue is that when someone enters to the kitchen, there is small delay before the motion sensor detects it. The person will then press the smart button to turn on the light, but just one seconds after the motion detection happened and as a result, the light will be turned on via the motion detection and will be turned off right away after the press on the button.

Which obviously is not the way to go…

What I imagined

  • I tried to configure my Node RED to bypass the smart button during only 2 seconds after the light turning on via motion detection, but I wasn’t able to achieve this (I als tried with the HueMagic node, but couldn’t find a way to go)
  • I tried to imagine another workaround : if the press on the button turns off the light, the motion detection automation should turn it back on as there is motion in the kitchen and the lightbulb is not on ; I wasn’t able to make it work either… in that case the only way to go to get light was to switch it on traditionnaly via the button.

Here is my flow :

[{"id":"5f9ebad9.6979a4","type":"server-state-changed","z":"a41e9994a85eece5","name":"Motion in Kitchen","server":"99be5be3.e4f478","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.lumi_lumi_sensor_motion_aq2_ias_zone","entityidfiltertype":"substring","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":200,"y":260,"wires":[["9da0140c.3cce08"]]},{"id":"b36195ab.f6bb78","type":"api-call-service","z":"a41e9994a85eece5","name":"ON","server":"99be5be3.e4f478","version":3,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.cuisine_2","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[{"property":"topic","propertyType":"msg","value":"14.0","valueType":"str"}],"queue":"none","x":1050,"y":200,"wires":[["c8109d4394132d75"]]},{"id":"9da0140c.3cce08","type":"switch","z":"a41e9994a85eece5","name":"motion on/off?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":400,"y":260,"wires":[["ed8e6e0c.f4c4d","2923d082.5d4a"],["2923d082.5d4a"]]},{"id":"fd336c7c.e35f6","type":"api-call-service","z":"a41e9994a85eece5","name":"OFF","server":"99be5be3.e4f478","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.cuisine_2","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1050,"y":260,"wires":[[]]},{"id":"ed8e6e0c.f4c4d","type":"api-current-state","z":"a41e9994a85eece5","name":"light on?","server":"99be5be3.e4f478","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.cuisine_2","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":600,"y":200,"wires":[[],["13eb35128dc03458"]]},{"id":"2923d082.5d4a","type":"stoptimer","z":"a41e9994a85eece5","duration":"2","units":"Minute","payloadtype":"num","payloadval":"0","name":"","x":620,"y":260,"wires":[["a64d7929.bd7498"],[]]},{"id":"a64d7929.bd7498","type":"api-current-state","z":"a41e9994a85eece5","name":"motion on?","server":"99be5be3.e4f478","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.lumi_lumi_sensor_motion_aq2_ias_zone","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":850,"y":260,"wires":[[],["fd336c7c.e35f6"]]},{"id":"f3168075b2481afd","type":"inject","z":"a41e9994a85eece5","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":210,"y":220,"wires":[["9da0140c.3cce08"]]},{"id":"2b080db3c3331535","type":"inject","z":"a41e9994a85eece5","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":210,"y":180,"wires":[["9da0140c.3cce08"]]},{"id":"13eb35128dc03458","type":"api-current-state","z":"a41e9994a85eece5","name":"Dark?","server":"99be5be3.e4f478","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.lumi_lumi_sensor_motion_aq2_illuminance","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":770,"y":200,"wires":[["cd8aa67e49194803"]]},{"id":"cd8aa67e49194803","type":"switch","z":"a41e9994a85eece5","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"87","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":910,"y":200,"wires":[["b36195ab.f6bb78"]]},{"id":"c8109d4394132d75","type":"debug","z":"a41e9994a85eece5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1070,"y":100,"wires":[]},{"id":"48c61a6381cf6099","type":"comment","z":"a41e9994a85eece5","name":"KITCHEN - Motion Lightning","info":"","x":240,"y":100,"wires":[]},{"id":"99be5be3.e4f478","type":"server","name":"","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":""}]

If anyone has an idea to suggest that will allow me either to bypass my button, or anything that would fit my needs, that would be so great ! I’m obviously open to other structural changes of my flow, I’m convinced that there are so many better ways to make this work !

Thanks a lot, I hope a diddn’t forget to mention something critical. I will add more context if needed !

Florian

I wonder why you experience that delay between motion detection and turning on the light in the first place. In my setup (several rooms with motion sensors and lights) this happens almost instantly.

Anyway I have a similar setup with a light switch which when pressed overrides the automic switch-off even when no motion is detected.

To achieve this I‘m using a boolean Helper (see Automations → Helpers ) to keep track of the state overridden by the physical switch together with a few automations.

Maybe a Helper can get you going here…

You’ll need to stop a new motion event from triggering the sequence. There is a 5s timeout period set in the trigger node, you may need to adjust it depending where the switch is in the room.

[{"id":"5f9ebad9.6979a4","type":"server-state-changed","z":"f80b6c338afd5483","name":"Motion in Kitchen","server":"","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.lumi_lumi_sensor_motion_aq2_ias_zone","entityidfiltertype":"substring","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":500,"y":2420,"wires":[["4e0c92143f87886c"]]},{"id":"b36195ab.f6bb78","type":"api-call-service","z":"f80b6c338afd5483","name":"ON","server":"","version":3,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.cuisine_2","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[{"property":"topic","propertyType":"msg","value":"14.0","valueType":"str"}],"queue":"none","x":1550,"y":2360,"wires":[["c8109d4394132d75"]]},{"id":"9da0140c.3cce08","type":"switch","z":"f80b6c338afd5483","name":"motion on/off?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":900,"y":2420,"wires":[["ed8e6e0c.f4c4d","2923d082.5d4a"],["2923d082.5d4a"]]},{"id":"fd336c7c.e35f6","type":"api-call-service","z":"f80b6c338afd5483","name":"OFF","server":"6b1110b5.183a4","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.cuisine_2","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1550,"y":2420,"wires":[[]]},{"id":"ed8e6e0c.f4c4d","type":"api-current-state","z":"f80b6c338afd5483","name":"light on?","server":"","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.cuisine_2","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":1100,"y":2360,"wires":[[],["13eb35128dc03458"]]},{"id":"2923d082.5d4a","type":"stoptimer","z":"f80b6c338afd5483","duration":"2","units":"Minute","payloadtype":"num","payloadval":"0","name":"","x":1120,"y":2420,"wires":[["a64d7929.bd7498"],[]]},{"id":"a64d7929.bd7498","type":"api-current-state","z":"f80b6c338afd5483","name":"motion on?","server":"","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.lumi_lumi_sensor_motion_aq2_ias_zone","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":1350,"y":2420,"wires":[[],["fd336c7c.e35f6"]]},{"id":"f3168075b2481afd","type":"inject","z":"f80b6c338afd5483","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":710,"y":2380,"wires":[["9da0140c.3cce08"]]},{"id":"2b080db3c3331535","type":"inject","z":"f80b6c338afd5483","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":710,"y":2340,"wires":[["9da0140c.3cce08"]]},{"id":"13eb35128dc03458","type":"api-current-state","z":"f80b6c338afd5483","name":"Dark?","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.lumi_lumi_sensor_motion_aq2_illuminance","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":1270,"y":2360,"wires":[["cd8aa67e49194803"]]},{"id":"cd8aa67e49194803","type":"switch","z":"f80b6c338afd5483","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"87","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1410,"y":2360,"wires":[["b36195ab.f6bb78"]]},{"id":"c8109d4394132d75","type":"debug","z":"f80b6c338afd5483","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1570,"y":2260,"wires":[]},{"id":"48c61a6381cf6099","type":"comment","z":"f80b6c338afd5483","name":"KITCHEN - Motion Lightning","info":"","x":740,"y":2260,"wires":[]},{"id":"4e0c92143f87886c","type":"traffic","z":"f80b6c338afd5483","name":"","property_allow":"payload","filter_allow":"allow","ignore_case_allow":false,"negate_allow":false,"send_allow":false,"property_stop":"payload","filter_stop":"stop","ignore_case_stop":false,"negate_stop":false,"send_stop":false,"default_start":true,"differ":false,"x":710,"y":2420,"wires":[["9da0140c.3cce08"]]},{"id":"ab26f98bf5683d67","type":"server-state-changed","z":"f80b6c338afd5483","name":"switch","server":"6b1110b5.183a4","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"stop","valueType":"str"}],"x":510,"y":2560,"wires":[["2923d082.5d4a","fd336c7c.e35f6","3097726d13461722"],[]]},{"id":"3097726d13461722","type":"trigger","z":"f80b6c338afd5483","name":"","op1":"stop","op2":"allow","op1type":"str","op2type":"str","duration":"5","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":520,"y":2480,"wires":[["4e0c92143f87886c"]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]