I’m trying to achieve this logic:
- When the motion sensor
off -> on
, turn on the light(if the lightoff
) - Wait for either:
- Motion sensor
off -> on FOR 3min
, then turn off the light - Light is
off -> on
manually, do nothing
- Motion sensor
The logic can be perfectly implemented using HA automation:
##========== Auto kitchen light ==========##
- id: auto_kitchen_light
alias: "Auto kitchen light"
trigger:
platform: state
entity_id: binary_sensor.kitchen_motion_occupancy
from: "off"
to: "on"
condition:
condition: and
conditions:
- condition: state
entity_id: light.kitchen_light
state: "off"
action:
- service: light.turn_on
target:
entity_id: light.kitchen_light
# Wait for the motion to stop for 3 minute
# or the light is manually turned off
- alias: "wait"
wait_for_trigger:
- platform: state
entity_id: light.kitchen_light
from: "on"
to: "off"
- platform: state
entity_id: binary_sensor.kitchen_motion_occupancy
from: "on"
to: "off"
for:
minutes: 3
# Stop execution if the light is turned off manually
- condition: template
value_template: "{{ wait.trigger.idx == '1' }}"
- service: light.turn_off
target:
entity_id: light.kitchen_light
I’m trying to move some automations to Node RED, and the wait until FOR
logic is causing me headache. So far I have implemented every other logic like this, but cannot find an elegant way to “wait till motion OFF -> ON for 3 min
”
Note that the cross between two
wait_for
is to cancel the other wait to avoid Node RED using too much resources. A little overkill.
I found a similar post Wait until FOR? but it uses wait_until
as the trigger of the flow, whereas I’m using it in the middle of the flow, so the solution doesn’t really apply.
I guess an ugly workaround is to set the wait untill
timeout to, e.g., 5s, and add a loop feedback from its output to inputs, but that’s not very efficient.
Any ideas? Thanks!