BertrumUK
(Neil B)
November 23, 2016, 4:46pm
1
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 ?
ih8gates
(Scott Reston)
November 23, 2016, 4:56pm
2
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.
silvrr
November 23, 2016, 5:42pm
3
check this link:
Thanks for this code, how can I drop the seconds from the readout and just have days hours minutes.
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
BertrumUK
(Neil B)
November 23, 2016, 7:26pm
4
Thank you very much. With the link you provided I was able to get it into a much better format
gsemet
(Gaetan Semet)
August 29, 2018, 5:04pm
5
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 -%}