M0AGX / LB9MG

Amateur radio and embedded systems

Getting Home Assistant uptime in minutes

My Home Assistant installation sends out several "device normal" notifications right after startup. I wanted to avoid being bombarded with useless notifications so I needed to filter out these events. The most obvious condition can be Home Assistant uptime. Basically: send a device status notification only 1-2 minutes after startup. Here is how to do it.

Adding "Uptime" device

  1. Go to Settings
  2. Select Devices & Services
  3. Press ADD INTEGRATION (bottom right blue button)
  4. Type "uptime" and add the integration with default settings

You should have an uptime entity (under Devices & Services, Entities). The problem is that the uptime is a timestamp with the date and time so you can't directly compare it to a number.

Getting uptime in minutes

Add this code to your configuration.yaml:

1
2
3
4
5
6
7
8
template:
  - sensor:
      - unique_id: ha_uptime_minutes
        name: Ha uptime minutes
        icon: mdi:history
        state: >-
          {%- set up = (now().timestamp()-as_timestamp(states('sensor.uptime')))/60 %}
          {{up}}

After restarting Home Assistant you should have an "Ha uptime minutes" entity that can be compared to numerical values and used as a condition in automations.

I release the code into public domain.