That’s why I set the mode to restart. I cancel the running the timer, and restart it when motion is detected, that way the timer will keep running for as long as there is motion. I then react to timer.finished which will only fire when no motion has been detected for the duration of the timer. mode: restart is crucial to making that work.
And I use door contact sensors, and motion sensors. Here is how I turn up the volume as I walk past a speaker when I am playing music across the house, and how I reset the volume to almost muted after a period of time:
You also don’t need two triggers of the same source and state to look at different conditions. Was there something additional in this automation that wasn’t listed? I would +1 looking at the timer finished event. Looking at the timer idle state would evaluate as true and trigger when starting up home assistant.
At first let me thank you all again for trying to help. I did try the solution of restart which totally makes sense, however, timer finished and it didn’t restart resulting into turning the lights off even if there is movement. I set the restart on the first automation that is turning the lights on and starts the timer.
The way that I solved it is by changing the automation that turns the light off. Originally, it had a trigger when the timer expires (by state). Now I added a trigger when the motion sensor has off state.
That way, even when the timer expires but the sensor reports movement the automation triggers uppon expiration but it doesn’t turn the lights off. When the movement stops it triggers again and the lights turn off.
For a beginner I think that it’s fine even if I would like to have everything within one automation. I will study yours and create a test automation to join everything!
That’s because you were originally listening to the state of the timer, rather than the timer finished event. With the timer state, even if you cancel the timer and then start the timer every time motion is detected, briefly the timer state will change from active to idle which would trigger the automation to turn the lights off.
Listen for timer.finished instead that will only fire when the timer actually completes the countdown.
I also had a problem with a light controlled by a motion sensor, which also had to work in different modes.
With just 1 automation and a helper, I couldn’t get it to work as wanted.
Now I have 2 automations:
1 that turns the light on at motion
the second that turns it off when there is no motion after some time
With a helper, you could influence the second automation from firing or not.
Don’t know if this is the ‘best’ way but it seems to do the job - only a few days in place now.
Unfortunately i cannot set it up… I would like please your help if you have the patience. I started from the beginning removing all automations and set up the first one that is supposed to turn the light on, when motion is detected. Please keep in mind that depending on the time, different scenes should activate. Here is what i have so far:
It seems to be evaluating correctly (so it is choosing the correct scene) however, even when set to restart, it doesn’t replenish the timer and therefore, even if there is motion the timer expires.
Let’s fix this at first and then we go to the automation that turns the lights off.
The trigger will ALWAYS either be the first or second trigger because the ID is just how you refer to the trigger. Your time checks need to be in the choose blocks, in order to decide what scene is activated.
You should only have ONE trigger for this, because both triggers are pointing to the same device.
The way I did mine was to set up scenes for the lights for different brightness.
Then 2 scripts to turn on/off the lights and in the ON script manage the time of day logic to call each the required scene.
Then use the automation just to decide when to call the on/off scripts.
e.g. is there motion: yes, is it dark enough: yes, call script ceiling.light.on
In the ON script, is the house set to “sleep”: no, is it after midnight: yes, call the 30% brightness scene
The script logic looks for a match from the top down, so best to set your dimmest setting first then gradually brighter until you get to 100% at the bottom of the script (found that out the hard way)
In case you’re wondering why there are double OFF commands, my Ikea Tradfri bulbs sometimes don’t fully switch off but running the request twice fixes that.
I will try to revive this topic.
How about his automation:
if motion is not detected for 2 minutes dim lights to 50% of its current value.
if no motion is detected for another minute, turn lights off.
if motion is detected within that 1 minute bring lights to original brightness and start waiting cycle again.
I am new to HA, played with some automations, but here I am reaching my current limit, could somebody please point me to right direction?
Yes you are correct, although I didn’t reply to this post I have solved it like you propose. The motion sensor turns the light on when motion is detected and then instead of turning the light off immediately, it reduces the brightness to lower percentage twice to give a visual indication that the light will eventually turn off.
Although the ultimate solution would be an mmWave sensor, this is the best workaround I have found so far.
So, i figured it out thanks to your post, however I am using timer helpers instead of bulit in timer, so it sholud survive restart, that is just technicality.
However there is one issue I can’t figure out yet. I want the lights to dim to 50% of their actual brightness and then bring them back to that original brightness (rather than 100%)
I created an input helper to store original brightness into before dimming, but when calling a service in automation I don’t know how to use that value in brightness_pct and how to store the brightness in it. How to properly handle that in automation?
I have code like that above but instead of hardcoded value of 100% and 50% I want yo use value stored in input_number.bedroom_lights_brigtness and half of that value.
So before the lights is dimmed I need to read brightness of that light, sotre into helper and dim it to half of that brightness.
When motion is detected I need to restore brightness to the value stored in that helper.
I haven’t used it myself as I have hardcodwd values but there is a service called: scene: create. It’s function is to create a temporary scene with the brightness/color of your light.
If you use this, just before the lights will dim, you can then re-apply it to restore the original brightness.
Please give it a try in the developer tools to understand how it works. Then you can apply it in your automation via a call service
Only thing left to figure out is how to store the initial brightness before the automation even starts, otherwise on motion it will restore light to brightness level stored in the helper on previous run.
One solution could be to run separate trigger every time brightness of those lights changes that will store actuall brightness into input helper. But this will also rewrite my stored value even when the brightness is changed within the original automation.