Help with template to obtain data

Hello I have a sensor by command that gives me the information on the operating system time, a RaspberryPi with symbian, but I am interested in modifying the result of the data that it offers me the sensor.

These are the data returned by the sensor

Y me gustaría que el resultado fuera como la siguiente imagen…

In other words, it is of the type Xd:Xh:Xm The same as the second image, I suppose that with a sensor template that collects that information, it can be adapted to the way I want it to be displayed

Thank’s!!

If it is up for less than 1 week, does your sensor show “up 0 weeks, 4 days, xxxx” or does it show “up 4 days, xxxx”? Same question for days, hours and minutes, does it show 0 (days / hours / minutes) or does it show nothing?

the week appears when 7 days pass, before week does not appear, but when I get home I restart the system and check it.

Try the following:

sensor:
  - platform: template
    sensors:
      uptime_symbian:
        friendly_name: "Uptime Symbian"
        value_template: >-
          {% set sensor = states('sensor.tiempo_encendido_trastero') %}
          {% set weeks = sensor.split(" week")[0][3:] | int %}
          {% set days = sensor.split(" day")[0][-1:] | int + (weeks * 7) %}
          {% set hours = sensor.split(" hour")[0][-2:] | int %}
          {% set minutes = sensor.split(" minute")[0][-2:] | int %}
          {% if days > 0 %}
            {{ days }}d:{{ hours }}h:{{ minutes }}m
          {% elif hours > 0 %}
            {{ hours }}h:{{ minutes }}m
          {% else %}
            {{ minutes }}m
          {% endif %}

This should work in both cases, if it shows 0 or nothing in your sensor.

1 Like

Ok, Thank you very much I will try it right away you are at home! And I will comment on the results, once again thanks for the reply!

This has been the solution to my problem, thank you very much for the help !!! a greeting

1 Like