Time remaining several input_numbers not working

Hi everyone,

something doesn’t work for me
It no longer shows me the sum of all input_number.
It just shows me the time of the active zones.
I need the sum of the time of all input_numbers regardless of whether the switches are on or not.
The watering takes place one after the other with a small time delay of 2 seconds

Taras helped me very well back then
but the whole thing somehow doesn’t work anymore.
What am I doing wrong?
Thanks.

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) }}	

In the original topic, you asked me for two different versions:

  1. The first one calculated the sum of only the zones that are on.
  2. The second one calculated the sum of all zones regardless if they are on or off.

The example you posted above is the first version, the one that calculates only the zones that are on. It is working exactly as designed.

If you want the second version, it is still posted in the original topic.

HINT: it simply removes this from the template:

selectattr('state', 'eq', 'on') 

Hi Taras,

something does not fit.
It shows me 45min instead of 1h !!
It’s really weird.


      zone_gesamt_time_remaining:
        friendly_name: 'Verbleibende Zeit'
        icon_template: 'mdi:clock-end'
        value_template: >
          {% set update = states('sensor.time') %}
          {% set ns = namespace(values=[]) %}
          {% for i in expand('group.zone_gesamt') | 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) }}	

That’s not the same template as the one in the second version posted in the other topic. Everything you need has already been created and given to you. Here is again, copied from the other topic:

  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"

Feel free to change it in whatever way you want.

Hi Taras,

I changed the template, especially the names.
Otherwise everything is the same.

What you just sent me is the total time.
That also fits so far.
Only the remaining time of the entire input_numbers does not work like that.

I wanted to represent the entire remaining time, regardless of whether the switches are on or not.

Unfortunately, I don’t know my way around as well as you do, I’ve tried a few things, but it doesn’t work.

Try this version (I don’t have the means to test it). The calculation now checks if the zone is on or off and handles the two states differently.

      zone_gesamt_time_remaining:
        friendly_name: 'Verbleibende Zeit'
        icon_template: 'mdi:clock-end'
        value_template: >
          {% set update = states('sensor.time') %}
          {% set ns = namespace(values=[]) %}
          {% for i in expand('group.zone_gesamt') | list %}
            {% set t1 = states('input_number.'~i.object_id~'_run_time')|int %}
            {% set t2= [ (t1 - (now().timestamp() - i.last_changed.timestamp())/60) | round(0), 0 ] | max %}
            {% set ns.values = ns.values + [ t2 if i.state == 'on' else t1 ] %}
          {% endfor %}
          {% set t =  ns.values | sum %}
          {{ '{}h {}min'.format(t//60, t%60) }}

You are a genius.
Thank you again.

1 Like

You’re welcome!

Hi Taras,
I was too hasty.
The template doesn’t work quite right.

The total remaining time of the input_numbers shows me.
The problem is when a zone is finished, the time jumps back again.
It doesn’t count down all zones.
Only one zone at a time.

For example see below.

Zone Einfahrt and Eingang set for 1 minute each.

Total 2 minutes.

When the Einfahrtzone is off, starts the Eingan zone.
In between, of course, with a delay of 3 seconds.

And there we have the problem.
The time jumps back to 2 minutes.

I no longer understand what you want because it seems like the requirements keep changing. Perhaps someone else will understand it better than me and can help you or maybe you will solve it yourself. Good luck.

the entire time of the input_number should simply decrease.
I wanted that from the beginning.
But that’s because of the language barriers I think.

Sorry for the disturbance again.