It seems to me that the solution is to iterate a generator containing the switch entities. That would allow for accessing each item’s last_updated without resorting to string concatenation. I’ll give this a go later (after lunch).
That was due to a typo I made. There was an extra ( in the template. I have removed it from the example posted above. I have also tested it and confirmed it works. Make the same correction (or copy-paste the revised example) and try again.
We have now arrived at a point in this thread where we are discussing the behavior of a second Template Sensor (zone_wir_time_total) but have not received confirmation the first one works (zone_wir_time_remaining).
It’s important to learn if the first one works (to confirm the selected calculation technique is correct) before proceeding to analyze the operation of the second one (which is derived from the same technique).
Does “sensor.zone_wir_time_remaining” report correct values? If it does not, then we should return to correcting it before jumping ahead to the second Template Sensor.
NOTE
In your post’s screenshot, all switches are off. The template sums the switches that are on. If you want it to sum all switches, regardless of their state, then the template becomes even simpler:
zone_wir_time_total:
value_template: >
{% set update = states('sensor.time') %}
{% set ns = namespace(values=[]) %}
{% for i in expand('group.sprinkler_zones') | list %}
{% set ns.values = ns.values + [ states('input_number.'~i.object_id~'_run_time')|int ] %}
{% endfor %}
{{ ns.values | sum }}
unit_of_measurement: "min"
something doesn’t work for me.
It no longer shows me the sum of all input_number.
It only shows me the time of the active zones.
I need the remaining of all input_numbers.
The watering runs one after the other with a small time delay of 2 seconds
group:
zone_gesamt:
name: Zonen gesamt
entities:
- switch.zone_1
- switch.zone_2
- switch.zone_3
- switch.zone_4
- switch.zone_5
- switch.zone_6
- switch.zone_7
- switch.zone_8
- switch.zone_9
input_number:
zone_1_run_time:
name: Einfahrt
min: 0
max: 45
step: 1
unit_of_measurement: min
icon: mdi:clock-start
zone_2_run_time:
name: Eingang
min: 0
max: 45
step: 1
unit_of_measurement: min
icon: mdi:clock-start
zone_3_run_time:
name: Streifen Haus
min: 0
max: 45
step: 1
unit_of_measurement: min
icon: mdi:clock-start
zone_4_run_time:
name: Streifen Nachbar
min: 0
max: 45
step: 1
unit_of_measurement: min
icon: mdi:clock-start
zone_5_run_time:
name: Terasse
min: 0
max: 45
step: 1
unit_of_measurement: min
icon: mdi:clock-start
zone_6_run_time:
name: Mauer
min: 0
max: 45
step: 1
unit_of_measurement: min
icon: mdi:clock-start
zone_7_run_time:
name: Grieche
min: 0
max: 45
step: 1
unit_of_measurement: min
icon: mdi:clock-start
zone_8_run_time:
name: Garage
min: 0
max: 45
step: 1
unit_of_measurement: min
icon: mdi:clock-start
zone_9_run_time:
name: Hecke
min: 0
max: 45
step: 1
unit_of_measurement: min
icon: mdi:clock-start
sensor:
- platform: template
sensors:
zone_gesamt_time_remaining:
value_template: >
{% set update = states('sensor.time') %}
{% set ns = namespace(values=[]) %}
{% for i in expand('group.zone_gesamt') | selectattr('state', 'eq', 'on') | list %}
{% set t = [ (states('input_number.'~i.object_id~'_run_time')|int -
(now().timestamp() - i.last_changed.timestamp())/60) | round(0), 0 ] | max %}
{% set ns.values = ns.values + [ t ] %}
{% endfor %}
{% set t = ns.values | sum %}
{{ '{}h {}min'.format(t//60, t%60) }}