Hello,
maybe someone can help me.
I want to restart a timer when
either the timer is in idle state or
when the remaining time is less than 90 seconds.
my code so far:
I have a lamp in the hallway, this should be
via a motion detector when needed
be switched on for 90sec via a timer.
In addition, I want to switch on and off this lamp with an extra switch.
For this I set the timer to 360sec.
This is done in an extra automation for the switch.
But if now the motion detector is triggered, then the timer is set again to 90sec. I want to prevent this by:
- condition: state
entity_id: timer.hallwaylightoff
state: idle
so that in normal mode, triggered by motion, the light does not go out and then come back on, the automation should reset the timer to 90sec when motion is detected and the remaining time is less than 90sec.
This shall be done by:
I don’t quite understand the logic, but for a Timer of 90sec, if the timer is in state active, it means it is running, and thus < 90 sec.
There is no way to check the actual remaining time easily (you could use the last_changed value of the Timer, and compare to now() but not sure you actually need it).
I’ll try to describe it again.
The motion detector loads the timer with 90sec.
and the light goes on.
When a new movement is detected, e.g. after 70sec,
(the timer has now 20sec left) the timer is set again to
90sec so that the light does not go out.
When the timer has expired (idle status) the light is switched off.
The brightness is here 5%
Now I would like to have the possibility to switch on the lamp with a switch longer time.
I do this with a Zigbee switch and set the timer to 360sec and brightness 90%.
Pressing the switch again cancels the timer and the light goes out again.
If I forget, then it goes off after an hour.
If I turned on the light with the switch, the timer was loaded to 360sec and the brightness is 90% then it should not happen that the motion detector sets the timer to 90sec and the brightness to 5%. That would be bad.
The most straightforward way would be to have 2 timers, I think. One for the motion sensor (90sec) and one for the switch (360sec).
When either reach their timeout, only shut down the light if the other one is not running.
If you like a one timer solution, add a condition like
what I noticed,
I make the syntax, as written by you,
in my automation.
I then looked at it in the visual editor and then back to ‘Edit YAML’.
Then I saw that: