1 Trigger. Something happens/changes that triggers the automation.
2 Condition. Optional. One or more conditions that must be met to continue. If not met, the automation stops here
3 Actions. One or more actions that are done
You seem to have an automation that react to motion not happening for a certain time. That logic only makes sense if there has been motion followed by a time period without.
If it was not like that, your trigger would fire non stop contuinously. Several times per second, always. There has to be a starting time for a trigger to define a single event where the motion has been off for X seconds. You need to rethink your automation and also consider turning on the light as a trigger to something that times out.
You could add a second trigger to your light off automation:
trigger:
- platform: template
value_template: |-
{% set b = 'binary_sensor.YOUR_HUE_SENSOR' %}
{% set l = states('light.YOUR_LIGHT') == 'on' %}
{% set no_motion = states(b) == 'off' and now() - states[b].last_changed >
timedelta(minutes=2) %}
{{ l and no_motion }}
And yes, it does not work like I think the OP wants it. The automation can only turn the light off with this. So then you need another automation to turn it on. If that other automation is the hue motion sensor then it works.
But you cannot turn the light on from HA UI or a zigbee switch. The minute the light turns on with motion sensor not detecting anything the trigger hits and turns the light off instantly. I am sure this is not what the OP wanted. He was concerned that when the UI is used to turn light on, the automation would not run. And I understand that as he wants the same timeout as when you enter the room.
Automation works like this:
If there is no motion detected start timer for 4 minutes.
If there is still no motion after that turn lights off.
And I want the same if lights were turned on by UI. It means if there is no motion after lights were turned on, start the same timer and at the end of it turn lights off.
I understand, that there must be a moment which will be considered as no motion and it seems like, the sensor is reporting only change of state, it means that no motion is triggered only after there was a motion and vice versa.
Is there a way to “force” the state of sensor to motion detected after the light is turned on via UI, so after that automation will run normally?
hello.
did you manage to get this to work.
I also wants that if there is no motion for x mins then turn off a light but if durning that x mins there was a motion then restart the x mins timer.