I guess you chose the restart mode in order to start over again if the motion sensor is activated again and been off for 2 minutes. But I am not sure whether there could be an issue in the logic if you start over before completing all steps.
So, could you please try first to change the automation mode from restart to single and see whether this has any effect.
And are you sure you don’t have other automations related to the light entity? You can see that on the device page like here
Actually, I will suggest instead of doing the delay, that you have two triggers in the same automation. One for the sensor has been off for 2 min, and the other for being off for 4 minutes.
Then the automations is completed by one action. No delay that holds the thread and might impact the performance and no more need for using the restart mode.
I made the following version for you, please make sure I spelled your entity names correct
first of all I checked whether there is another automation that crossfires my one.
I have another one that regulates the brightness of all lights in the house. Whenever one light is switched on. The brightness is set by a template in this general automation
I switched it off and my automation works as charm. So the problem seems to be the sequence.
I guess as long as my “switch off” automation is running (delay) the general brightness automation is waiting for it until its finished and fires its own brightness level. But I’m not 100% sure. But it would explain the behaviour.
I tried it with your code as well. I deleted your first action. (it didn’t work with it). Afterwards the behaviour seems to be the same. It works when general brightness automation is off. And it doesn’t when it is on.
Nevertheless. Thanks for your help. You put my nose to the right point. And a second thank you for the inspiration of 2 triggers. I wasn’t aware that this is an option in home assistant. I will further investigate on this.
Ok. I made some adjustments. And I think I got it. I put now everything in one automation.
Multiple triggers in combination with choose are pure gold. Thanks again @ghassan.
Solution is to switch off the impacting automation and switch it on again when everything is done.
My last hurdle was the transition in light.switch_off. It seems to execute light.turn_on services for every step. And the automation seems not to wait until transition is completed. So I needed a last delay.
Maybe it helps someone else. So I add my code here.
This following automation works just fine for me, without delays and have no issues with the light automatically turning on again after turning off, eve though i use the transition.
So I guess you make it more complex than necessary, and if using my code does not eliminate the issue with auto turning the light on, after turning it off, there might be a reason that need to be found. What kind of light bulbs/integration is it (Philips Hue, Tuya, other )
Example of unnecessary code complexity is that the default choose condition will never be entered as the trigger can only be 0,1 or 2 which are handled already.
for this room I use innr bulbs (zigbee) with deCONZ Stick.
Regarding the complexity you are right. This is just a spleen not to use the else condition. I prefer to have all options as elif. The idea is that in case I change code there is some kind of “emergency exit”.
As I wrote my problem is that there is a second automation responsible for brightness of all lights including the lights in the motion automation.
And when transition is like a sequence …
light.turn_on (brightness 50)
light.turn_on (brightness 25)
and so on
then the second automation starts working and this behaviour could be the result. I’ll have another look tomorrow.