A built in option if you reboot HA it remembers Time Stamps on Automations and not reset at reboot

id like to see a feature… that HA remembers time stamps easilly i did ask for help and there is a semi complicated way of work around

but it be nice built in
so say you have a Hot water tank … an automation for shuts off after 5 hrs you hitting the on button… and say its been 4hrs 20 min and you reboot HA well when it reboots that timer is now reset

it be nice that HA would remember that at 4hrs 20 min ha rebooted then takes in account the time it took to reboot and then say its 4hr 25min and then it has 35 min left on the timer to shut off instead of creating 5 hours agin…

i did my own work around so that if HA did reboot it would be 5 hours from time of HA boot up if the switch was already on… but was hoping for an easily built in option

its a sugesstion dunno if it will ever become but figured be nice… like a 1 line drop down option for automations something built in so its easy to remember…
like Keep track of automations after reboot something like that anyways

Don’t delay automations.
Set a helper with the time it should shut off and use this as your trigger in the “off”- automation

ok not sure how to do a helper… but ok what i mean be nice then all automations would have this helper built in easily… like a check box…

would you like a helper after HA reboot

but could u send me link to this helper setup… i still cant wrap my head around all this home assistant… still cant get my head around node red at all so i still work with the file editor etc… and try to learn

but i dont work with it everyday is probably why i cant get my head around… set it up and hope that the next updates dont break things lol

You’d set an input datetime to the time you wanted it to shut off.

Then you can use that in a time trigger.

I think a “behind-the-scenes” calculation that sets a timestamp for when the “for:”, “delay:”, “wait_for_trigger”, etc would be satisfied would be a very user friendly way of overcoming the horrible unreliability of timer functions in HA.

I’m no HA developer but I would think it should be trivial to set a timestamp.


  platform: state
  enty_id: switch.some_switch
  to: 'on'
    minutes: 45

in the above set the initial listener to the state change and once the state changes to ‘on’ then set a timestamp for 45 minutes from that time and create another listener for the time > timestamp to actually trigger the automation.

all of the pieces above already exist in the HA universe - we have states, entities with timestamps and triggers that rely on those timestamps to do something. And we even have conditions that use timestamps as well.

So I can’t see that putting those pieces together in the background shouldn’t be that hard for a real dev with the end result of fixing a huge reliability hole in HA for such a basic thing as using timed functions.

The only thing I see that would have to be worked out is in the fairly rare case where the system is restarted and the timestamp event occurs while the system is restarting.

One way to handle that is you could put an option in the automation config to say something like “continue_trigger_on_restart” and if true then if the timestamp is in the past (now >= timestamp) then trigger the automation otherwise do nothing.

right. and the reason we have to say that is solely because of the unreliability in the timer functions that this FR is asking to fix.

right again.

Again this is likely the workaround that the OP is referring to above. Which is very unsatisfying from a UX and reliability perspective.

Oh, and OP make sure you vote for your own FR. It’s not intuitive but your vote isn’t automatically counted.

1 Like

so i looked at link and i more confused… i couldnt figure how to add time in my automation…
what be nice is so you press Power Switch on your device… and your Logs Record it… but be nice that the automation Records that time stamp from the log or reads it and says at 6pm light switch was pressed and the automation needs to keep that light on from 6pm and if you reboot the HA or it has ti go down cuz it runs on Unraid for me… so could be down for 1 hour… that when HA comes back online that light switch automation for me Hot water tank checks the log of when it was Pressed at 6pm and if its still on the automation continues 5 hours from when it was pressed at 5pm

just like how any Battery operated Digital Timer works… it still works if timer was on and you change the battery and plug it back in the automation will still continue to run…

so something that does a check on the automation that doesnt confuse me like a check box… Do you wish the automation to Continue or Reset the timer on reboot… something like that… something really simple check box… as it can read a log faster then anything else…

i dont know what “hellis81” meant by Don;t delay automations

and i dont know what a FR or what i voting for?

so i tried to add it
time so it should work off the state change for 5 hours but there is no real option under Time for to time stamp it and i dont know how to add it in the gui part under time trigger

alias: Turn off House's Hot Water Tank after 5 hours
description: ''
  - platform: state
    entity_id: switch.h_hot_water_tank_switch
    for: '05:00:00'
    to: 'on'
  - platform: time
    at: '05:00:00'
condition: []
  - service: switch.turn_off
      entity_id: switch.h_hot_water_tank_switch
mode: single

and this is my reboot automation where it just counts 5 hours after HA reboots… as i dont know how to read a time stamp from the Log File of a switch to say when it was last toggeled and if its still on to turn off after 5 hours but this is my 2nd automation… be nice if you only needed it in the above… that it would be just a Check box On:off option to recurse or whatever that word you use so it recalls it after a reboot and it compares Real Time, State Change Time… and if its On still… and Whats left in the timer…

but here is my HA reboot work around i did … but the other one someomee told me about was a little hard for me to grasp and i dont try to bug people either i try to figure it out…as i know like the Pfsense community some people get really mad at you for asking questions that seem legit to you but they dont think soo…

alias: Turn off  Hot Water Tank after 5 hours HA Reboot
description: ''
  - platform: homeassistant
    event: start
  - condition: device
    type: is_on
    device_id: 9d241cf92747c4bef591d585192ff2de
    entity_id: switch.h_hot_water_tank_switch
    domain: switch
      hours: 5
      minutes: 0
      seconds: 0
      milliseconds: 0
  - service: switch.turn_off
      entity_id: switch.h_hot_water_tank_switch
mode: single

thats my work around but wanted something really simple just a check box that made these checks behind the scenes… that can quickly check the logs of the Switchs with the Automation… so figured id ask as i still cant get my head around all the settings i do try and trial and error google searches before asking in the forums as i dont wanna tick people off asking a question that may been answered… or because i just cant get my head around it like MQTT and Nodred i cant get my head around and there is no Dummy Books for that really step by step for a person with dislexia and learning disability like myself has that needs to re read things alot and is a visual learner opposed to reading learning…

FR stands for “feature request”. Which is the name of the category you wrote this post in.

at the top of this topic is a box that says “vote”. It allows others to indicate that they agree with the FR that is presented and would like to see it implemented. You can and should vote for your own FR.

But the problem still remains and it just kicks the can down the road.

What if in another hour you restart HA again?

At that point it resets the second automation for another 5 hours. And so on and so on.

Which is what hells81 was saying - that you shouldn’t put any (long) delays in automations that you want to reliably run at a certain delay time since they are unreliable if you do any significant amount of development that requires restarting or reloading automations.

oh ok … so i voted learn something new everyday…

and ok… ya so far its just my Hot water tank… so ya you mean like 5hour delay isnt good if your restarting HA alot cuz then it cant do it… reason i guess thats why my FR so that when you reboot HA it can check the Time of the Device Change, to the Time of the Automation and then can continue the Automation without resetting… i guess only other work around is to have 2 HA running remote and then the remote would have the 2nd automation copy right? i do have it but i never tested it if it works… i was hoping for a Load Balancing HA option so if one goes down it bounces off the 2nd one… but thats another day kinda thing…

but ya so far its just my hot water tank i wanted to shut off and an easy way it could read and then check oh this automation needs to continue running… so count down timer will keep counting down…

so i learn something new everyday … what FR is and Vote for myself lol… i appreciate it… maybe it will get higher vote of 3… how many votes does it take before they consider your feature request? like petitions you need 10k signatures before they even consider something… is that the same for FR?

and if i knew how to program in home assistant code… id help but my knowledge really stopped at Visual Basic 6/Net so i not much use these days lol

1 Like

The issue with creating a backend workaround for this is that if this does not work then we are in the same position again.

If this “thing” should run just before a restart to save all states then that is great until you get a power flicker and you get an unplanned restart.

If this “thing” is supposed to run and save the states when the automation triggers then there is a risk that it does not get saved since sometimes it just happens that an automation does not finnish/run, it’s not often but there is still a possibility/risk.

I don’t disagree with the request, I’m just saying there is always a risk that an automation fails, and when it’s a very important automation then I would rather create the automation to have failsafe(s) and not rely on the automation to work the first time.

As an example the automation to turn of the alarm automatically had (we don’t have an alarm in the new apartment) a second trigger a few minutes later that kept trying to turn it off until it succeeded and if it didn’t it would send me a notification just to be sure I didn’t open the door and trigger the alarm when I went to work while the family was still in bed.

In theory it only requires one developer that agrees with you and does the change.
On the other hand, your request can have thousands of votes but still nobody that is interested in fixing it.

that’s not what I sugggested.

But that is at least it’s closer.

I’m not saying to save the timestamp when the automation finishes.

I’m saying save the timestamp when the timed function is called. So in the example trigger i posted the timestamp at now() + 45 minutes (2700 seconds) would be set as soon as the switch goes to on in the trigger. At that instant a listener would be created so that as soon as now() >= the timestamp then the automation moves to the next step (check conditions or run actions as appropriate). It would end up exactly as if the trigger automatically changed itself from a state based trigger with a timer into a time based trigger with a value of now() >= timestamp as the listener.

If there is a restart/reload after the state based trigger created the timestamp but the timestamp hasn’t expired (reset it when the automation finishes) then retrigger the automation at the timestamp created previously.

Of course anything can happen and you can’t account for every failure scenario but the solution I propose would go a LONG way to solving one of the biggest reliability holes in HA right now for the standard user.

Ask yourself: why do you want to leave the heater on 5 hours? That seems to be entirely arbitrary. Why not switch it off when the water is hot?

I think we seem to be getting lost in the weeds and are missing the point of the FR.

It doesn’t matter why they need to do that. there are many other use cases that this issue impacts on.

the point is that HA has unreliably implemented timer functions and it needs to be fixed.

and work arounds are just a band aid to mitigate the failures.


ah ya thats what i was also saying above when you you press a switch the time stamp or the automation checks the logs of each switch or something

as for the reason for hot water tank…
i turn it on and set it for 5 hours so it least runs and heats up and so i dont forget to turn it off… so if i turn it on and working outside and i dont get a chance to use the hot water… least it shut off

here in ontario canada we have high hydro rates… i have have 700-1000 bucks a month for stupid hydro… got a 25k/kw furnance i set to 10 degress in my house and only use a ceramic heater in a room or 2 and try to keep the hydro low… and wear more clothes suffer in winter but u gotta do what you gotta do to keep your home… eat or hydro/heat u cant have both… as its 18cents a kilowatt or so… and i have now my freezers on timers so only goes on 7pm to 7am as thats the cheap rate of 15 cents or so… and i use in winter totes and put food in it and use winter as a free freezer…

and i try to use the hot water tank every 3 days to try to save money… as the water stays warm… anything to try to save money to get by…

so sometimes i forget to shut off hot water tank the automation is what i use to shut it off… and 5 hours gave me a good time to heat up and then shut off and i didnt have to worry about it… but i wanted a simple way that it could recall… and i figured making a log file then reads the log file and doing the comparioson well like i orginally mentioned…

but thats my reason for the hot water tank and a 5 hour… cuz the hydro is expensive and then we sell hydro to usa at a loss. So Ontarians pay for americans to have cheap hydro… and then our previous ontario premeier put money into solar and wind at a ridiculous rate … so we are paying for that too… so need to save money somewhere to keep ya home…

I’m not at my PC now so am typing this from memory but…

I learnt only a few days ago (it may be new or it may have been there forever and I just didn’t know) that a timer has a finishes_at attribute (or something similar).

One reason I wouldn’t have known is that it doesn’t seem to be documented and it only exists while the timer is active or paused.

Now… if that attribute were to persist wouldn’t it solve al these problems?

possibly for timers but only for timers.

all of the other time functions (“for”, “delay”, “wait_for_trigger”, etc) it wouldn’t make any difference.