Truncate system monitor "Since Last Boot"

I am using the System Monitor component however I am trying to remove the extra seconds at the end

I have tried playing with the value_template: but I cannot make it work. Only want to see days:hours:minutes without the seconds. Can this be done ?

The template dev tool (icon at bottom of left-hand sidebar) is helpful to troubleshoot the correct syntax for value templates. Post some code for what you have so far.

check this link:

I turncated mine down to just days and hours. Minutes and seconds seemed overkill.

  - platform: template
      since_last_boot_templated:
        value_template: >-
          {%- set slb = states.sensor.since_last_boot.state.split(' ') -%}
          {%- set count = slb | length -%}
          {%- set hms = slb[count - 1] -%}
          {%- set hms_trimmed = hms.split('.')[0] -%}
          {%- set hms_split = hms_trimmed.split(':') -%}
          {%- set hours = hms_split[0] | int -%}
     
          {%- if count == 3 -%}
            {{ slb[0] ~ ' ' ~ slb[1] ~ ' ' }}
          {%- endif -%}
          {%- if hours > 0 -%}
            {%- if hours == 1 -%}
              1 hour
            {%- else -%}
              {{ hours }} hours
            {%- endif -%}
          {%- endif -%}
2 Likes

Thank you very much. With the link you provided I was able to get it into a much better format :slight_smile:

My version that works on 0.76:

  - platform: template
    sensors:
      domot_since_last_boot_templated:
        value_template: >-
          {%- set slb = states('sensor.domot_since_last_boot').split(' ') -%}
          {%- set count = slb | length -%}
          {%- set hms = slb[count - 1] -%}
          {%- set hms_trimmed = hms.split('.')[0] -%}
          {%- set hms_split = hms_trimmed.split(':') -%}
          {%- set hours = hms_split[0] | int -%}

          {%- if count == 3 -%}
            {{ slb[0] ~ ' ' ~ slb[1] ~ ' ' }}
          {%- endif -%}
          {%- if hours > 0 -%}
            {%- if hours == 1 -%}
              1 hour
            {%- else -%}
              {{ hours }} hours
            {%- endif -%}
          {%- endif -%}