Last_boot sensor not updated in weeks

Hey guys I have set up the last_boot sensor in the systemmonitor

e.g.

- platform: systemmonitor
  resources:
    - type: last_boot

but it seems to be stuck to 13 weeks ago even though I have restarted countless times since then.

image

was 13 weeks ago the last time you booted the system or the last time you restarted Home Assistant? They are different things.

1 Like

As @silvrr said, this sensor shows when you last booted the host system, not Home Assistant.

Also you may find the code below useful, it converts the last boot sensor to a more "readable "sensor, showing e.g. 5 minutes or 3 hours or 5 days instead of the timestamp.

- platform: template
    sensors:
      uptime_nuc:
        friendly_name: Uptime NUC
        icon_template: mdi:server
        value_template: >-
          {% set lb = states('sensor.last_boot') %}
          {% if lb != 'unknown' %}
            {% set seconds = (as_timestamp(now()) - as_timestamp(lb))|int %}
            {% set days = (seconds / 86400)|int %}
            {% set seconds = seconds % 86400 %}
            {% set hours = (seconds / 3600)|int %}
            {% set seconds = seconds % 3600 %}
            {% set minutes = (seconds / 60)|int %}
            {% set seconds = seconds % 60 %}
            {% if hours == 0 and minutes == 0 %}
              {{ time }} seconds
            {% else %}
              {%- if days > 0 -%}
                {%- if days == 1 -%}
                  1 day
                {%- else -%}
                  {{ days }} days
                {%- endif -%}
              {%- endif -%}
              {%- if hours > 0 and days < 7 -%}
                {%- if days > 0 -%}
                  {{ ', ' }}
                {%- endif -%}
                {%- if hours == 1 -%}
                  1 hour
                {%- else -%}
                  {{ hours }} hours
                {%- endif -%}
              {%- endif -%}
              {%- if days == 0 and minutes > 0 -%}
                {%- if hours > 0 -%}
                  {{ ', ' }}{{ minutes }} min
                {%- else -%}
                  {%- if minutes == 1 -%}
                    1 minute
                  {%- else -%}
                    {{ minutes }} minutes
                  {%- endif -%}
                {%- endif -%}
              {%- endif -%}
            {% endif %}
          {% else %}
            unknown
          {% endif %}
2 Likes

Ah! well I am an idiot! That definitely explains it. I don’t really restart the host system as I am running on a RPi I just restart Hass.io through the command prompt, which would explain why that sensors says 13 weeks ago

and thanks @Burningstone for the template.

Any of you using something equivalent for HA uptime? I have template from @kregg but it uses the uptime platform and it updates every 14mins so not 100% accurate but much better than 0.07 days

Personally I use this in my sensors.yaml:

- platform: uptime

Results in this:
image

1 Like

I use the uptime platform as well, you can set a scan interval, mine looks like this:

  - platform: uptime
    name: HASS uptime
    scan_interval: 60
    unit_of_measurement: hours
1 Like

I am also using the uptime sensor but then I added a template which converts it like this

you can provide template, thanks

See my config here for the uptime:
It creates a sensor that shows the uptime like this 2d4h12min and it only shows the d/h/min if there’s a value >0. If uptime is less than 1 minutre, it shows “Less than 1 min”.

1 Like