Multiple Uptime sensor in hours instead of seconds

Hi,

I’m fairly new to HA. and have been reading up to using time and template sensors. It seems that I can get it to work halfway, but seem to get stuck at the following. I think I’m not understanding things correctly, but not sure what.

I have 2 uptime sensor in my config (sensor.uptime for HA and another sensor.sensor.ex5601_t1_uptime). I’d like both to give uptime in Days, hours, minutes, seconds). I got that working for sensor.uptime, but not for the second one:

This is what I got in my configuration.yaml:

template:
    sensors:
      uptime_days:
        entity_id: sensor.uptime
        value_template: >-
          {% set minutes = states('sensor.uptime')|int %}
          {% set hours = minutes / 60 %}
          {% if minutes / 60 > 1 %}
            {{ minutes //  60  }} hours ago
          {% else %}
            {{ minutes }} minutes ago
          {% endif %}      
        entity_id: sensor.ex5601_t1_uptime
        value_template: >-
          {% set minutes = states('sensor.ex5601_t1_uptime')|int %}
          {% set hours = minutes / 60 %}
          {% if minutes / 60 > 1 %}
            {{ minutes //  60  }} hours ago
          {% else %}
            {{ minutes }} minutes ago
          {% endif %}

You only have one template sensor called uptime_days where you first set the sensor equal to an entity and a value template and then you do that once more.
I do not know how HA reacts to the second definition of the entity and value_template.
It might ignore the second definition or it might over write the first or it might go all haywire and do something totally unexpected

It looks like you have misunderstood the naming in the template.
Each sensor should have a name, so add a line with a name before the second entity line and make sure the indentation of only that line is on par with the line uprime_days:

Your YAML is a mix of old and new formats along with a dose of formatting mistakes as well.

Take a look at the examples in the docs, particularly the first one which shows the basic formatting you need.

Specifically, this is what you should be following:

template:
  - sensor:
      - name: "Friendly name of sensor #1"
        state: "{{ single line template }}"
      - name: "Friendly name of sensor #2"
        state: >
          {{ multi-line template }}

Edit: your sensors are also simple enough that you can just use the UI (Integrations → Helpers → Template) instead of adding them in YAML.

Hm, think then maybe going with creating a helper would be the best way. I’ll see what I can do there. Thanks for pointing in the right direction