Hi,
i’m trying to set an automation that fires up 3 days after my HA latest reboot, but at a specific hour of the night.
My hardware is slow and unsupported and sometimes RAM gets filled and a restart of HA is needed.
Originally I did an automation that fires up every three nights at 4:00 AM but sometimes I restart HA manually for changing some config and the nightly restart becomes useless. So my idea was to create a trigger that adds 3 days to sensor.uptime PLUS… “some hours to reach 4 AM”.
by the way, if your issue is that it craps out when ram gets filled, system monitor has info about ram usage and available swap. instead of doing a random reboot at some time, you could trigger off low ramp/high swap or something more directly the problem.
no, i mean sensor.uptime
I don’t need to reboot my hardware, only HA process
But this is not important, I need to understand how to do something at sensor.uptime + 3 days + some hours until 4 AM
my actual test trigger is:
{{ (states(‘sensor.uptime’) | as_datetime + timedelta(days=+3)).isoformat() }}
I wish to understand how to do better templates as it is a totally new language for me, my idea was to convert sensor.uptime to a simple YYYY-MM-DD trimming out the hours and minutes, but maybe there is a better approach.
So far I was able to create this:
{{ (states(‘sensor.uptime’) | as_datetime + timedelta(days=+3)).isoformat() }}
For instance I did a HA reboot (only my docker instance, not the whole hardare!) at 18:15 today (february 17) and I want to automatically restart HA on february 20 at 00:00.
If tomorrow I will restart it manually to adjust some configuration, the automation should restart HA on february 21 instead of 20
same problem, how to set a calendar event 3 days after a sensor state plus some hours to 4 AM?
i need some formula that transforms this: {{ states('sensor.uptime') }}
which now is: 2024-02-17T20:41:17+00:00
i get that you’re trying to do all the math to set a time and then prob create a trigger on that time. but i’m still thinking that’s overly complicated. does this do what you want and much simplier in 1 automation? no calendar event, no additional automation, etc.
I have used the following code to send notifications when a Zigbee device goes offline. To prevent messages when HA has been restarted, I used your template as a condition and changed it from “days” to “minutes”.
But it doesn’t work - what am I doing wrong?
Thank you for any help.
You cannot invent your own attributes. A timedelta object, which would be the result of the preceding calculation, has no minutes attribute. Only days, seconds and microseconds because those are what it uses internally.
Well do you actually have a sensor.system_monitor_last_boot entity? I don’t, mine is called only sensor.last_boot and I am pretty sure I am not responsible for that shorter name. Substitute with that and the template works for me. Go to Settings > Devices & services > System Monitor to make sure the Last boot sensor is enabled and what its ID is.