Help Needed- Motion Sensor Lights Issue

Noob here so I apologize in advance if this is not formatted properly or if I forget to include a specific detail. I’m setting up a Hue motion sensor to turn on different scenes based on time of day. I want the lights to stay on as long as there is motion and then turn off after 3 minutes of no motion. If it is between 5:30 and 22:00, it should turn on the Bathroom Daytime scene and if it is outside those hours, it should turn on the Bathroom Overnight scenes.

The time of day is working and the motion turns on the appropriate lights. Once the lights turn on, the Hue motion sensor has about a 5 second cooldown and then the stoptimer kicks in for 3 minutes and turns off after the 3 minutes as it should. The issue is that if the Hue motion sensor notices additional motion during the 3 minute stoptimer, it turns the lights off. I can’t figure out why the additional motion is turning the lights off rather than restarting the stoptimer and keeping the lights on.

I apologize if this has been answered before, but I looked through the topics posted and followed the instructions on multiple posts, but cannot get this to work properly. Pics posted to Imgur. Thanks in advance for any help you can provide!!

Is the issue that there is nothing to cancel the timer in the event that it has started and motion is detected? I’m not sure what that timer node is, but it’s probably got some cancellation control

If you paste the code (surrounded by ```) as well as the pic it is easier for people to look into the issue.

I’m assuming that your “motion detected” node has “is on”. Therefore the timer is only started when motion turns off, and additional motion will not do anything with the timer.

Indeed that is probably the reason. You can check in the timer node what the cancel message will be. Simply connect a change node between the ON and the Timer and change it to the cancel message. Whenever the Motion sensor then detects new motion the original timer will be cancelled.

You don’t need the stoptimer node at all. Set the event state node to not output anything until the motion sensor state is off for 3 (or whatever) minutes.

1 Like

Thanks! Does that time reset if more motion is detected?

You’re welcome. And yes.

1 Like

@michaelblight Thanks for replying. Here is the code I think you said would help diagnose what’s going on here.

*** [{“id”:“d1b07e8af9668d43”,“type”:“tab”,“label”:“Bathroom”,“disabled”:false,“info”:"",“env”:[]},{“id”:“7a338a2b.30a4f4”,“type”:“server”,“name”:“Home Assistant”,“addon”:true},{“id”:“88868838f9b4eceb”,“type”:“server-state-changed”,“z”:“d1b07e8af9668d43”,“name”:“Motion Detected?”,“server”:“7a338a2b.30a4f4”,“version”:4,“exposeToHomeAssistant”:false,“haConfig”:[{“property”:“name”,“value”:""},{“property”:“icon”,“value”:""}],“entityidfilter”:“binary_sensor.hue_motion_sensor_1_motion”,“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”:“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”:110,“y”:240,“wires”:[[“a47ba3e861542682”,“0880bca2b6d13f68”],[“1c5992f96585c7e5”]]},{“id”:“a47ba3e861542682”,“type”:“time-range-switch”,“z”:“d1b07e8af9668d43”,“name”:“Overnight”,“lat”:"",“lon”:"",“startTime”:“22:00”,“endTime”:“05:30”,“startOffset”:0,“endOffset”:0,“x”:340,“y”:120,“wires”:[[“61cb0d675eaab9c1”],[]]},{“id”:“0880bca2b6d13f68”,“type”:“time-range-switch”,“z”:“d1b07e8af9668d43”,“name”:“Daytime”,“lat”:"",“lon”:"",“startTime”:“05:30”,“endTime”:“22:00”,“startOffset”:0,“endOffset”:0,“x”:340,“y”:180,“wires”:[[“26083d45844b5710”],[]]},{“id”:“61cb0d675eaab9c1”,“type”:“api-call-service”,“z”:“d1b07e8af9668d43”,“name”:“Turn On Overnight Scene”,“server”:“7a338a2b.30a4f4”,“version”:5,“debugenabled”:false,“domain”:“scene”,“service”:“turn_on”,“areaId”:[],“deviceId”:[],“entityId”:[“scene.bathroom_overnight”],“data”:"",“dataType”:“jsonata”,“mergeContext”:"",“mustacheAltTags”:false,“outputProperties”:[],“queue”:“none”,“x”:550,“y”:100,“wires”:[[]]},{“id”:“26083d45844b5710”,“type”:“api-call-service”,“z”:“d1b07e8af9668d43”,“name”:“Turn On Daytime Scene”,“server”:“7a338a2b.30a4f4”,“version”:5,“debugenabled”:false,“domain”:“scene”,“service”:“turn_on”,“areaId”:[],“deviceId”:[],“entityId”:[“scene.bathroom_daytime”],“data”:"",“dataType”:“jsonata”,“mergeContext”:"",“mustacheAltTags”:false,“outputProperties”:[],“queue”:“none”,“x”:550,“y”:160,“wires”:[[]]},{“id”:“1c5992f96585c7e5”,“type”:“stoptimer”,“z”:“d1b07e8af9668d43”,“duration”:“3”,“units”:“Minute”,“payloadtype”:“num”,“payloadval”:“0”,“name”:“3 Minute Timer”,“x”:320,“y”:300,“wires”:[[“d17d75cd36e0df4d”],[]]},{“id”:“d17d75cd36e0df4d”,“type”:“api-call-service”,“z”:“d1b07e8af9668d43”,“name”:“Turn Off Lights”,“server”:“7a338a2b.30a4f4”,“version”:5,“debugenabled”:false,“domain”:“light”,“service”:“turn_off”,“areaId”:[],“deviceId”:[],“entityId”:[“light.bathroom_lights”],“data”:"",“dataType”:“jsonata”,“mergeContext”:"",“mustacheAltTags”:false,“outputProperties”:[],“queue”:“none”,“x”:520,“y”:280,“wires”:[[]]}] ***

The flow can’t be pasted into NR because the double-quotes are wrong. Surround your code with 3 back-ticks (```) so they don’t get converted. This is the same a.s </> in the toolbar

@michaelblight Thanks! I wasn’t sure exactly what to do. Is this formatted correctly so that you might be able to assist me? Thanks again!!

[{"id":"d1b07e8af9668d43","type":"tab","label":"Bathroom","disabled":false,"info":"","env":[]},{"id":"6e3eb787783e4c74","type":"tab","label":"Bathroom Closet","disabled":false,"info":"","env":[]},{"id":"7a338a2b.30a4f4","type":"server","name":"Home Assistant","addon":true},{"id":"88868838f9b4eceb","type":"server-state-changed","z":"d1b07e8af9668d43","name":"Motion Detected?","server":"7a338a2b.30a4f4","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.hue_motion_sensor_1_motion","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":"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":110,"y":240,"wires":[["a47ba3e861542682","0880bca2b6d13f68"],["1c5992f96585c7e5"]]},{"id":"a47ba3e861542682","type":"time-range-switch","z":"d1b07e8af9668d43","name":"Overnight","lat":"","lon":"","startTime":"22:00","endTime":"05:30","startOffset":0,"endOffset":0,"x":340,"y":120,"wires":[["61cb0d675eaab9c1"],[]]},{"id":"0880bca2b6d13f68","type":"time-range-switch","z":"d1b07e8af9668d43","name":"Daytime","lat":"","lon":"","startTime":"05:30","endTime":"22:00","startOffset":0,"endOffset":0,"x":340,"y":180,"wires":[["26083d45844b5710"],[]]},{"id":"61cb0d675eaab9c1","type":"api-call-service","z":"d1b07e8af9668d43","name":"Turn On Overnight Scene","server":"7a338a2b.30a4f4","version":5,"debugenabled":false,"domain":"scene","service":"turn_on","areaId":[],"deviceId":[],"entityId":["scene.bathroom_overnight"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":550,"y":100,"wires":[[]]},{"id":"26083d45844b5710","type":"api-call-service","z":"d1b07e8af9668d43","name":"Turn On Daytime Scene","server":"7a338a2b.30a4f4","version":5,"debugenabled":false,"domain":"scene","service":"turn_on","areaId":[],"deviceId":[],"entityId":["scene.bathroom_daytime"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":550,"y":160,"wires":[[]]},{"id":"1c5992f96585c7e5","type":"stoptimer","z":"d1b07e8af9668d43","duration":"3","units":"Minute","payloadtype":"num","payloadval":"0","name":"3 Minute Timer","x":320,"y":300,"wires":[["d17d75cd36e0df4d"],[]]},{"id":"d17d75cd36e0df4d","type":"api-call-service","z":"d1b07e8af9668d43","name":"Turn Off Lights","server":"7a338a2b.30a4f4","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":["light.bathroom_lights"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":520,"y":280,"wires":[[]]},{"id":"444b2ddc3992fdce","type":"server-state-changed","z":"6e3eb787783e4c74","name":"Motion Detected","server":"7a338a2b.30a4f4","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.bathroom_closet_motion_sensor","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"20","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":100,"y":240,"wires":[["84d1119756333d9d"]]},{"id":"84d1119756333d9d","type":"api-call-service","z":"6e3eb787783e4c74","name":"Toggle Light","server":"7a338a2b.30a4f4","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":["39649909fb3b65adb53c0af17c7eaf5a"],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":330,"y":240,"wires":[[]]}]

Below is what is being suggested. Get rid of the “3 minute timer” and just put it as a “for” condition in a “No Motion Detected?” event-state node. Note that I don’t have the time-range node, so I don’t know how successfully that will paste from my code back into yours.

image

[{"id":"88868838f9b4eceb","type":"server-state-changed","z":"d1b07e8af9668d43","name":"Motion Detected?","server":"7a338a2b.30a4f4","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.hue_motion_sensor_1_motion","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":"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":120,"y":240,"wires":[["a47ba3e861542682","0880bca2b6d13f68"],[]]},{"id":"a47ba3e861542682","type":"time-range-switch","z":"d1b07e8af9668d43","name":"Overnight","lat":"","lon":"","startTime":"22:00","endTime":"05:30","startOffset":0,"endOffset":0,"x":340,"y":120,"wires":[["61cb0d675eaab9c1"],[]]},{"id":"0880bca2b6d13f68","type":"time-range-switch","z":"d1b07e8af9668d43","name":"Daytime","lat":"","lon":"","startTime":"05:30","endTime":"22:00","startOffset":0,"endOffset":0,"x":340,"y":180,"wires":[["26083d45844b5710"],[]]},{"id":"61cb0d675eaab9c1","type":"api-call-service","z":"d1b07e8af9668d43","name":"Turn On Overnight Scene","server":"7a338a2b.30a4f4","version":5,"debugenabled":false,"domain":"scene","service":"turn_on","areaId":[],"deviceId":[],"entityId":["scene.bathroom_overnight"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":670,"y":100,"wires":[[]]},{"id":"26083d45844b5710","type":"api-call-service","z":"d1b07e8af9668d43","name":"Turn On Daytime Scene","server":"7a338a2b.30a4f4","version":5,"debugenabled":false,"domain":"scene","service":"turn_on","areaId":[],"deviceId":[],"entityId":["scene.bathroom_daytime"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":670,"y":160,"wires":[[]]},{"id":"d17d75cd36e0df4d","type":"api-call-service","z":"d1b07e8af9668d43","name":"Turn Off Lights","server":"7a338a2b.30a4f4","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":["light.bathroom_lights"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":640,"y":320,"wires":[[]]},{"id":"4998a10b2f46bc72","type":"server-state-changed","z":"d1b07e8af9668d43","name":"No Motion Detected?","server":"7a338a2b.30a4f4","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.hue_motion_sensor_1_motion","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":"3","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":140,"y":320,"wires":[["d17d75cd36e0df4d"],[]]},{"id":"7a338a2b.30a4f4","type":"server","name":"Home Assistant","addon":true}]

Another suggestion - when you copy code from NR for the forum, click on the export’s JSON tab and click “compact”. Then it will paste as one line as I have done above.

1 Like