Hi all,
some version ago i had a simple automation condition that verify the uptime of home assistant and it was like this:
condition:
- 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?
Thanks
Hellis81
(Hellis81)
January 26, 2021, 8:34am
2
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 }}
3 Likes
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.
2 Likes
thanks everyone for the fast reply.
Did you have an alredy done template to create this sensor?
Thanks
something like this
- platform: template
sensors:
uptime_minutes:
friendly_name: UpTime Minutes
value_template: >
{{ (as_timestamp(now()) - as_timestamp(states('sensor.uptime'))) // 60| round (0) }}
6 Likes
Hellis81
(Hellis81)
January 26, 2021, 8:54am
7
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.
simonk
March 5, 2021, 2:44pm
10
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?
dohlin
April 20, 2021, 4:43pm
11
@simonk
You probably don’t have the uptime platform sensor configured. Uptime - Home Assistant
This work fine for me:
condition:
- condition: template
value_template: >-
{{ as_timestamp(now()) - as_timestamp(states.sensor.uptime.last_changed) |
int > 60 }}
4 Likes