Motion Detection, Light Automation & shut-off timer

In what should be one of the easier automations I do, I’m struggling with some light control via automation, and it’s really killing the WAF:

I have a bayesian sensor in my garage that is comprised of a door sensor and 2 motion sensors. If the door is open or one of the motion sensors has detected motion, the bayesian gets set to on.

I have a flow in NodeRed that turns the light on when the bayesian turns on. This works flawlessly.

I then want the light to turn off after 10 minutes of inactivity. However, what I’m finding is if I’m in the garage moving around for 10+ straight minutes, meaning that the bayesian always stays to on, the light still turns off after 10 minutes. If I leave the garage for a period of time after the light has turned on, meaning that the bayesian tuns off, the timer will reset when I re-enter the garage and all’s good.

Am I missing something here? I’ve used the DIYFuturism example of as the basis for my method, and I think I’ve copied it verbatim.

[{"id":"578f4dc6.638ab4","type":"server-state-changed","z":"91bccc5.005dd3","name":"Garage Motion Detection - Bayesian","server":"20f36b65.1b39b4","version":1,"entityidfilter":"binary_sensor.garage_bayesian_motion_sensor","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":180,"y":180,"wires":[["c24c271c.5a5d78"]],"info":"binary_sensor.motion_sensor_158d00036d5a35_garage_workbox"},{"id":"ce96400c.9433c","type":"stoptimer","z":"91bccc5.005dd3","duration":"10","units":"Minute","payloadtype":"num","payloadval":"0","name":"10 minutes til off","x":620,"y":220,"wires":[["f93afcc0.4e406"],[]]},{"id":"f93afcc0.4e406","type":"api-call-service","z":"91bccc5.005dd3","name":"Turn them off","server":"20f36b65.1b39b4","version":1,"service_domain":"homeassistant","service":"turn_off","entityId":"switch.zooz_willis_electric_unknown_type_1e01_id_1e01_switch_ceiling_garage","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":870,"y":220,"wires":[[]]},{"id":"b578a905.f2a398","type":"api-call-service","z":"91bccc5.005dd3","name":"No?  Turn them on","server":"20f36b65.1b39b4","version":1,"service_domain":"homeassistant","service":"turn_on","entityId":"switch.zooz_willis_electric_unknown_type_1e01_id_1e01_switch_ceiling_garage","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":950,"y":160,"wires":[[]]},{"id":"c24c271c.5a5d78","type":"switch","z":"91bccc5.005dd3","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":180,"wires":[["ce96400c.9433c","cae5077b.d88088"],["ce96400c.9433c"]]},{"id":"cae5077b.d88088","type":"api-current-state","z":"91bccc5.005dd3","name":"Are the lights already on?","server":"20f36b65.1b39b4","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"switch.zooz_willis_electric_unknown_type_1e01_id_1e01_switch_ceiling_garage","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":650,"y":160,"wires":[[],["b578a905.f2a398"]]},{"id":"59482fcf.d25f9","type":"comment","z":"91bccc5.005dd3","name":"Garage Motion Detection","info":"","x":150,"y":140,"wires":[],"icon":"node-red/bluetooth.png"},{"id":"20f36b65.1b39b4","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

I would suggest to add the “wait until” between your switch and your timer.
This way you can wait until your Bayesian sensor see’s no presence, and then start your 10 minute timer.

image

I think that will get you the desired result.
You might need to run the switch to the timer still though so that if you walk back into the room, it resets… you’d want it to actually stop the timer I believe… so that it starts again when the Bayesian sensor “wait until” triggers it to start.

See if that gets you where you are trying to go :slight_smile:

Cheers!
DeadEnd

1 Like

Thank you, @DeadEnd. That worked perfectly. It’s been running for 2 days now and behaves exactly how I was hoping.

From what i see, the issue is that you trigger the timer also when you turn on the bayesian sensor.
If you turn on the sensor, it should actually send a CANCEL to the timer so it will be stopped.
Only the sensor turning off should activate the timer.

Hi
Could you show you flow?
Are you getting a reset of the timer when you enter the garage again?