Condition UpTime

Hi all,
some version ago i had a simple automation condition that verify the uptime of home assistant and it was like this:

   - condition: numeric_state  
     entity_id: sensor.uptime
     above: 0.10

based on the sensor

  - platform: uptime
    unit_of_measurement: hours

now is not working anymore… someone have similar problem?


Yes, everyone had that problem but most read the breaking changes of 2020.12 update and made a template sensor.

Since you want six minutes I believe this should work.

{{ as_timestamp(now()) - as_timestamp(states.sensor.uptime.state) >= 600 }}


A few versions ago was a breaking change that changed the uptime sensor from a sensor that shows time since last boot to a sensor that shows when the last boot was. You need a template sensor that converts the timestamp to a sensor that shows time since last boot or adjust your automation condition to chevk now - timestamp of last boot.


thanks everyone for the fast reply.
Did you have an alredy done template to create this sensor?

something like this

  - platform: template
        friendly_name: UpTime Minutes
        value_template: >
          {{ (as_timestamp(now()) - as_timestamp(states('sensor.uptime'))) // 60| round (0)  }}

Yes, exactly.

1 Like

Or just add it as a template condition in your automation.

This is fine if it is only used in one automation, otherwise I recommend creating the sensor and reuse it across multiple automations/scripts.

I’m just trying to implement this code but it just shows Unavailable.

I’ve copied the code from above and put it into my configuration.yaml, restarted HA, added a entity card but just shows Unavailable still.

Any ideas what I’ve done wrong?


You probably don’t have the uptime platform sensor configured. Uptime - Home Assistant

This work fine for me:

  - condition: template
    value_template: >-
      {{ as_timestamp(now()) - as_timestamp(states.sensor.uptime.last_changed) |
      int > 60 }}