Motion trigger Lighting automation question

Hi Guys, need some help here as I am new to motion lights automation.

I have a motion sensor and I want to trigger the light to turn on after 15s, and it will turn off if no presence detected after 30s (for example).

I used the trigger to wait 30s to turn lights off and if msg.payload is on then reset the trigger. This works ok initially but I found out that there’re scenarios the msg.payload couldn’t send it quickly enough to cancel the trigger timer (since I have set the condition to turn on as 15s). So sometimes the light will turn off and turn on even there’s presence. Is there any way to improve this? Thanks.


[{"id":"c1200a75d886372c","type":"api-call-service","z":"77a82869577d2280","name":"","server":"ab275ce0.0e1d7","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":["b2c373f45b480a4d4ba260433327d28b"],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":830,"y":540,"wires":[[]]},{"id":"37593fc5d17ecfd9","type":"server-state-changed","z":"77a82869577d2280","name":"Sensor Zone 1 is ON for 15s","server":"ab275ce0.0e1d7","version":5,"outputs":2,"exposeAsEntityConfig":"05c648e743c02a9e","entityId":"binary_sensor.presence_sensor_fp2_81af_zone_1","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"on","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"15","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"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":520,"wires":[["e9e91a1b08ad1ca6"],["e9e91a1b08ad1ca6"]]},{"id":"1bc5e9343099b801","type":"trigger","z":"77a82869577d2280","name":"","op1":"","op2":"10s test","op1type":"nul","op2type":"str","duration":"30","extend":true,"overrideDelay":false,"units":"s","reset":"on","bytopic":"all","topic":"topic","outputs":1,"x":630,"y":540,"wires":[["c1200a75d886372c"]]},{"id":"e9e91a1b08ad1ca6","type":"switch","z":"77a82869577d2280","name":"ON or 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":390,"y":520,"wires":[["187596e180ab6f09","1bc5e9343099b801"],["1bc5e9343099b801"]]},{"id":"187596e180ab6f09","type":"api-call-service","z":"77a82869577d2280","name":"","server":"ab275ce0.0e1d7","version":5,"debugenabled":false,"domain":"scene","service":"turn_on","areaId":[],"deviceId":[],"entityId":["scene.dining_room_mavis_focus"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":640,"y":460,"wires":[[]]},{"id":"ab275ce0.0e1d7","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false},{"id":"05c648e743c02a9e","type":"ha-entity-config","server":"ab275ce0.0e1d7","deviceConfig":"","name":"Dining Light Zone 1 Motion","version":"6","entityType":"switch","haConfig":[{"property":"name","value":"Dining Light Zone 1 Motion"},{"property":"icon","value":""},{"property":"entity_picture","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""}],"resend":false,"debugEnabled":false}]

You could add a wait in this.

Sorry how does it work? Do you mean to add a “wait until” to replace the trigger node?

Why trigger the off sequence when the motion sensor turns on? Wait for the motion sensor to turn off.

[{"id":"c1200a75d886372c","type":"api-call-service","z":"0a325c35fc29f44e","name":"","server":"","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":["b2c373f45b480a4d4ba260433327d28b"],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":930,"y":5000,"wires":[[]]},{"id":"37593fc5d17ecfd9","type":"server-state-changed","z":"0a325c35fc29f44e","name":"Sensor Zone 1 is ON for 15s","server":"","version":5,"outputs":2,"exposeAsEntityConfig":"05c648e743c02a9e","entityId":"binary_sensor.presence_sensor_fp2_81af_zone_1","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"on","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"15","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":420,"y":4980,"wires":[["187596e180ab6f09"],["1bc5e9343099b801"]]},{"id":"1bc5e9343099b801","type":"trigger","z":"0a325c35fc29f44e","name":"","op1":"","op2":"10s test","op1type":"nul","op2type":"str","duration":"30","extend":true,"overrideDelay":false,"units":"s","reset":"on","bytopic":"all","topic":"topic","outputs":1,"x":730,"y":5000,"wires":[["c1200a75d886372c"]]},{"id":"187596e180ab6f09","type":"api-call-service","z":"0a325c35fc29f44e","name":"","server":"","version":5,"debugenabled":false,"domain":"scene","service":"turn_on","areaId":[],"deviceId":[],"entityId":["scene.dining_room_mavis_focus"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":740,"y":4920,"wires":[[]]},{"id":"05c648e743c02a9e","type":"ha-entity-config","server":"","deviceConfig":"","name":"Dining Light Zone 1 Motion","version":"6","entityType":"switch","haConfig":[{"property":"name","value":"Dining Light Zone 1 Motion"},{"property":"icon","value":""},{"property":"entity_picture","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""}],"resend":false,"debugEnabled":false}]

Because someone could be temporarily away. My initially setup is, during the 30s trigger node wait, if presence is ON again and inject into the trigger node, the 30s trigger will be cancelled and the light will not turn off. Right?

And what would be the expected behavior? The light would turn off for the few seconds they are away or that the light stays on? It would only make sense for the first scenario but then you would get the behavior you are seeing now that the light turns off to quick. At least that is the way I see it.

The light will only turn off if the presence is OFF for 30s. If during that 30s count, someone is back, then the light will not go off. The light stays turn on if only a few seconds away. I think this make sense?

What is the motion sensor blind time / dwell time? Is it adjustable? If yes, you should not use the 30 second count - adjust the blind time.

It’s the presence sensor FP2. I don’t think I can adjust anything?