Reload of automation

i have a automation with a sensor that turn off the light after no motion i 3 minutes, but
when i reload automations or restart HA , the light dont turns off , because it dont rememeber the state -
is there a way to fix this ?

You could save the time value in a input_time instead of delaying the automation.

So one automation to turn on and set a datetime with now + 3 minutes
And one automation to trigger when the current time is more than the datetime to turn of the light.

Show it, using code formatter of this editor (grafik )