At wits end keeping lights on after initial motion detection

On motion, I have our kitchen lights turn on soffit lighting. That motion event triggers a 30 minute timer, where if no motion after that 30 minutes, they turn off. Otherwise, if there’s motion at any time, the 30 minute timer resets.

It’s the last part that I’m struggling with. Below is my flow code, would anyone be willing to take a peek at it and see what I am missing? I was hoping to accomplish it by having that “Is light on” node capturing the state of a light, but that’s not working either :frowning:

It’s a real bummer with the WAF not having this work.

[{"id":"2c157019.38218","type":"server-state-changed","z":"e9f629c5.eedcc","name":"Kitchen Northeast Motion Sensor","server":"e204944a.31bc78","entityidfilter":"binary_sensor.kitchen_northeast_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,"x":198.5,"y":739.4000549316406,"wires":[["a29c6410.c5a2a8"]]},{"id":"a29c6410.c5a2a8","type":"switch","z":"e9f629c5.eedcc","name":"Motion or No Motion?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":563.5,"y":739,"wires":[["d9f997f0.955948","827cd944.af6de"],["d9f997f0.955948"]]},{"id":"63890857.598d6","type":"api-call-service","z":"e9f629c5.eedcc","name":"Kitchen Lights Off","server":"e204944a.31bc78","service_domain":"light","service":"turn_off","data":"{\"entity_id\":\"light.caseta_kitchen_island, light.caseta_kitchen_north, light.caseta_kitchen_southeast, light.caseta_kitchen_southwest, light.caseta_kitchen_west\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":1219.5,"y":794,"wires":[[]]},{"id":"5d18a48f.56f62c","type":"api-call-service","z":"e9f629c5.eedcc","name":"Kitchen Lights","server":"e204944a.31bc78","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.caseta_kitchen_island, light.caseta_kitchen_north, light.caseta_kitchen_southeast, light.caseta_kitchen_southwest, light.caseta_kitchen_west\",\"brightness_pct\":35}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":1210.5,"y":674.4999389648438,"wires":[[]]},{"id":"d9f997f0.955948","type":"stoptimer","z":"e9f629c5.eedcc","duration":"30","units":"Minute","payloadtype":"num","payloadval":"0","name":"30 Minute Timer","x":932.2000122070312,"y":790.2000122070312,"wires":[["63890857.598d6"],[]]},{"id":"827cd944.af6de","type":"api-current-state","z":"e9f629c5.eedcc","name":"Already On?","server":"e204944a.31bc78","outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.caseta_kitchen_island","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":896.11669921875,"y":669.449951171875,"wires":[["5d18a48f.56f62c","d4061411.a0b21"],[]]},{"id":"d4061411.a0b21","type":"debug","z":"e9f629c5.eedcc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1145.11669921875,"y":542.8499755859375,"wires":[]},{"id":"e204944a.31bc78","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

I can’t see what the problem is with that flow. If the timer node gets a new message then the timer should reset.

Does the light not turn off after 30 minutes or does it turn on after 30 minutes regardless?

1 Like
- alias: Boo to Node-red - easy in yaml 
  trigger:
    platform: state 
    entity_id: binary_sensor.kitchen_northeast_motion_sensor
    to: 'off' 
    for:
      minutes: 30
  action:
    service: homeassistant.turn_off
    entity_id:
      - light.caseta_kitchen_island
      - light.caseta_kitchen_north
      - light.caseta_kitchen_southeast
      - light.caseta_kitchen_southwest
      - light.caseta_kitchen_west
2 Likes

It turns off after 30 minutes regardless - I thought the exact same thing as you, too.

[{"id":"fff1c69a.8ef678","type":"server-state-changed","z":"84df0ed9.7598a","name":"Kitchen Northeast Motion Sensor","version":1,"entityidfilter":"binary_sensor.kitchen_northeast_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":false,"x":178,"y":208,"wires":[["57cdc638.0b7738","f2b83776.4c7bd8"]]},{"id":"2aaac733.fd76d8","type":"api-call-service","z":"84df0ed9.7598a","name":"Kitchen Lights Off","service_domain":"light","service":"turn_off","data":"{\"entity_id\":\"light.caseta_kitchen_island, light.caseta_kitchen_north, light.caseta_kitchen_southeast, light.caseta_kitchen_southwest, light.caseta_kitchen_west\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":634,"y":256,"wires":[[]]},{"id":"44ddbe46.2b27b","type":"api-call-service","z":"84df0ed9.7598a","name":"Kitchen Lights","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.caseta_kitchen_island, light.caseta_kitchen_north, light.caseta_kitchen_southeast, light.caseta_kitchen_southwest, light.caseta_kitchen_west\",\"brightness_pct\":35}","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":624,"y":208,"wires":[[]]},{"id":"57cdc638.0b7738","type":"api-current-state","z":"84df0ed9.7598a","name":"Already On?","version":"1","outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.caseta_kitchen_island","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":438,"y":208,"wires":[["44ddbe46.2b27b"],[]]},{"id":"f2b83776.4c7bd8","type":"trigger","z":"84df0ed9.7598a","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"30","extend":false,"units":"min","reset":"","bytopic":"all","name":"","x":438,"y":256,"wires":[["2aaac733.fd76d8"]]}]
1 Like

Maybe throw a check state node for motion in after the time. If motion is on, send it back to the timer, if off then turn off the lights

1 Like

All - thank you for your help! Unfortunately, none of the suggestions worked, but I did figure it out using this set of logic from here if anyone is running into this issue looking for a solution

[{"id":"5f9ebad9.6979a4","type":"server-state-changed","z":"5af080bd.59def","name":"Motion in Study","server":"10f4c357.f3da8d","entityidfilter":"binary_sensor.motion_sensor_158d000121a8d5","entityidfiltertype":"substring","haltifstate":"","x":180,"y":380,"wires":[["9da0140c.3cce08"]]},{"id":"b36195ab.f6bb78","type":"api-call-service","z":"5af080bd.59def","name":"ON","server":"10f4c357.f3da8d","service_domain":"light","service":"turn_on","data":"{ \"entity_id\":\"light.yeelight_rgb_34ce008fd378\"}","mergecontext":"","x":970,"y":380,"wires":[[]]},{"id":"9da0140c.3cce08","type":"switch","z":"5af080bd.59def","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":380,"y":380,"wires":[["ed8e6e0c.f4c4d","2923d082.5d4a"],["2923d082.5d4a"]]},{"id":"fd336c7c.e35f6","type":"api-call-service","z":"5af080bd.59def","name":"OFF","server":"10f4c357.f3da8d","service_domain":"light","service":"turn_off","data":"{ \"entity_id\":\"light.yeelight_rgb_34ce008fd378\"}","mergecontext":"","x":970,"y":480,"wires":[[]]},{"id":"ed8e6e0c.f4c4d","type":"api-current-state","z":"5af080bd.59def","name":"light on?","server":"10f4c357.f3da8d","halt_if":"on","entity_id":"light.yeelight_rgb_34ce008fd378","x":700,"y":380,"wires":[["b36195ab.f6bb78"]]},{"id":"2923d082.5d4a","type":"stoptimer","z":"5af080bd.59def","duration":"3","units":"Minute","payloadtype":"num","payloadval":"0","name":"","x":600,"y":480,"wires":[["a64d7929.bd7498"],[]]},{"id":"a64d7929.bd7498","type":"api-current-state","z":"5af080bd.59def","name":"motion on?","server":"10f4c357.f3da8d","halt_if":"on","entity_id":"binary_sensor.motion_sensor_158d000121a8d5","x":790,"y":480,"wires":[["fd336c7c.e35f6"]]},{"id":"10f4c357.f3da8d","type":"server","z":"","name":"Home Assistant","url":"https://yourname.duckdns.org:8123","pass":"pass"}]