Time elapsed since last boot

I’m trying to create a simple automation to reboot the host if the last boot was more than 3 days ago.

However, I’m going out of my mind trying to compare “now” and “last boot” timestamps.

Does anyone have such an automation already built?

Thanks.

trigger:
  - platform: template
    value_template: "{{ now() - as_datetime(states('sensor.last_boot')) > timedelta(days=3) }}"

Why are you rebooting the host every 3 days?

<3

Zigbee2mqtt tends to freeze every couple of days. I had it rebooting every 3 days when there’s nobody home but thought I might as well reboot the host instead.

It would be much better to only restart the Zigbee2mqtt container than the whole host.

It would be even better to work out what is wrong with zigbee2mqtt.

Quick question:

I’m putting this inside an “option” on the actions and I’m getting the following error:

1 Like

That’s way out of my league to sort out.

Another thing that often causes zigbee2mqtt to shut down is if a new update HA comes out. Until I’ve updated the Core, OS and Supervisor to the latest version, it refuses to work.

Sorry to pester you but any idea regarding the error above?

No idea sorry. I don’t use the automation editor.

It works in the template editor and I just double checked it by pasting it into my config and running a configuration check, which passed.

I think the issue is you have double ‘’ around sensor.last_boot - believe if you use " to surround then you’d need single ’ and if you use single ’ to surround, then you’d use double ‘’ inside.