Help with time remaining from input number

I have an irrigation and I want to show how much time is left until the stop.
my configuration as it is unfortunately does not work.
no sensor is shown.
What am I doing wrong?

rainbird:
  - host: ###########
    password: ##########
    trigger_time: 0:40
    zones:
      1:
        friendly_name: zone_1

sensor:
  - platform: template
    sensors:
      zone_1_time_remaining:
        friendly_name: 'Time Remaining'
        entity_id:
          - input_number.zone_1_time_remaining
          - sensor.time
          - switch.zone_1
        value_template: >
          {% if is_state('switch.zone_1', 'on') %}
            {{ [ (states('input_number.zone_1_run_time')|int - (as_timestamp(now()) - as_timestamp(states.switch.zone_1.last_changed))/60)|round(0) ,0 ] | max }}
          {% else %}
            0
          {% endif %}
        unit_of_measurement: "min"

input_number:
  zone_1_run_time:
    name: Run Time
    min: 0
    max: 90
    step: 5
    unit_of_measurement: min
    icon: mdi:clock


That looks familiar. :slight_smile:

If you are running v0.115 this no longer works, remove it:

        entity_id:
          - input_number.zone_1_time_remaining
          - sensor.time
          - switch.zone_1

and adjust your template to:


        value_template: >
          {% set update = states('sensor.time') %}
          {% if is_state('switch.zone_1', 'on') %}
            {{ [ (states('input_number.zone_1_run_time')|int - (as_timestamp(now()) - as_timestamp(states.switch.zone_1.last_changed))/60)|round(0) ,0 ] | max }}
          {% else %}
            0
          {% endif %}

If you are running 0.114 or earlier make sure you actually have a sensor.time.

Thanks again,
will try in a moment
How can I display time remainig from a group of zones?

Thanks again,
will try in a moment

How can I display time remainig from a group of zones?

for example:

group:      
  zone_wir:
    name: Zonen wir
    entities:
      - switch.zone_5
      - switch.zone_6
      - switch.zone_7
      - switch.zone_8
      - switch.zone_9
      
  zone_schwiegereltern:
    name: Zonen schwiegereltern
    entities:
      - switch.zone_1
      - switch.zone_2
      - switch.zone_3
      - switch.zone_4

input_number:
  zone_1_run_time:
    name: Run Time
    min: 0
    max: 90
    step: 5
    unit_of_measurement: min
    icon: mdi:clock

  zone_2_run_time:
    name: Run Time
    min: 0
    max: 90
    step: 5
    unit_of_measurement: min
    icon: mdi:clock

  zone_3_run_time:
    name: Run Time
    min: 0
    max: 90
    step: 5
    unit_of_measurement: min
    icon: mdi:clock

  zone_4_run_time:
    name: Run Time
    min: 0
    max: 90
    step: 5
    unit_of_measurement: min
    icon: mdi:clock

  zone_5_run_time:
    name: Run Time
    min: 0
    max: 90
    step: 5
    unit_of_measurement: min
    icon: mdi:clock

  zone_6_run_time:
    name: Run Time
    min: 0
    max: 90
    step: 5
    unit_of_measurement: min
    icon: mdi:clock

  zone_7_run_time:
    name: Run Time
    min: 0
    max: 90
    step: 5
    unit_of_measurement: min
    icon: mdi:clock

  zone_8_run_time:
    name: Run Time
    min: 0
    max: 90
    step: 5
    unit_of_measurement: min
    icon: mdi:clock
    
  zone_9_run_time:
    name: Run Time
    min: 0
    max: 90
    step: 5
    unit_of_measurement: min
    icon: mdi:clock

It’s going to be the same as for any one of the switches in that zone, so use the same template.

your suggestion did not help.

I currently have home assistant v0.115
entity_id: I removed it, there is no sensor with zone_1_time_remaining

sensor:
  - platform: template
    sensors:
      zone_1_time_remaining:
        friendly_name: 'Time Remaining'
        value_template: >
          {% set update = states('sensor.time') %}
          {% if is_state('switch.zone_1', 'on') %}
            {{ [ (states('input_number.zone_1_run_time')|int - (as_timestamp(now()) - as_timestamp(states.switch.zone_1.last_changed))/60)|round(0) ,0 ] | max }}
          {% else %}
            0
          {% endif %} 
        unit_of_measurement: "min"
        
      zone_2_time_remaining:
        friendly_name: 'Time Remaining'
        value_template: >
          {% set update = states('sensor.time') %}
          {% if is_state('switch.zone_2', 'on') %}
            {{ [ (states('input_number.zone_2_run_time')|int - (as_timestamp(now()) - as_timestamp(states.switch.zone_2.last_changed))/60)|round(0) ,0 ] | max }}
          {% else %}
            0
          {% endif %}          
        unit_of_measurement: "min"

image

Did you restart?

Errors in the log?

now the second time.

now it worked
funny

Hi everyone,

How can I get total time from input number?

automation:
- id: 'start zone wir'
  alias: start zone wir
  description: ''
  trigger:
  - platform: state
    entity_id: input_boolean.zone_wir
    to: 'on'
  condition: []
  action:
  - service: script.sprinkler_zone_wir
    data: {}
  mode: single
    
- id: 'stop zone wir'
  alias: stop zone wir
  description: ''
  trigger:
  - platform: state
    entity_id: input_boolean.zone_wir
    to: 'off'
  condition: []
  action:
  - service: switch.turn_off
    data: {}
    entity_id: switch.zone_5
  - service: switch.turn_off
    data: {}
    entity_id: switch.zone_6
  - service: switch.turn_off
    data: {}
    entity_id: switch.zone_7
  - service: switch.turn_off
    data: {}
    entity_id: switch.zone_8
  - service: switch.turn_off
    data: {}
    entity_id: switch.zone_9
  mode: single

Use a template sensor with a value template that add up all the input numbers.

value_template: "{{ states('input_number.zone_1_run_time')|int + states('input_number.zone_2_run_time')|int + states('input_number.zone_3_run_time')|int + ... states('input_number.zone_9_run_time')|int }}"

Where I have written ... keep adding your input numbers.

it worked
great thank you.

hi, i don’t get the hang of how to integrate the switch group.
Can you give me an example

For one switch it is clear to me, but not for several.

As I said before, every member of the group is going to have the same time remaining. So just use any member of the group.

how do i define the members of the group.
With (if is state) or (and) or (is state)?

Do they have to define one after the other?
Or among each other?
Like here in the example?

- platform: template
  sensors: 
    luxtronik_id_web_wp_bz_akt:   
      value_template: >-
        {%- if is_state("luxtronik.id_web_wp_bz_akt", "heating") %}
          Heizen
        {%- elif is_state("luxtronik.id_web_wp_bz_akt", "hot water") %}
          Warmwasser
        {%- elif is_state("luxtronik.id_web_wp_bz_akt", "evu") %}
          EVU Sperre
        {%- elif is_state("luxtronik.id_web_wp_bz_akt", "defrost") %}
          Abtauen
        {% else %}
           Keine Anforderung
        {%- endif %}  

You cant use templates in group configurations.

Is that correct?

      zone_wir_time_remaining:
        friendly_name: 'Zone wir Time Remaining'
        value_template: >
          {% set update = states('sensor.time') %}
          {% if is_state('switch.zone_5', 'on') %}
          {% elif is_state('switch.zone_6', 'on') %}
          {% elif is_state('switch.zone_7', 'on') %}
          {% elif is_state('switch.zone_8', 'on') %}
          {% elif is_state('switch.zone_9', 'on') %}
            {{ [ (states('input_number.zone_5_run_time')|int - (as_timestamp(now()) - as_timestamp(states.switch.zone_5.last_changed))/60)|round(0) ,0 ] | max }}
            {{ [ (states('input_number.zone_6_run_time')|int - (as_timestamp(now()) - as_timestamp(states.switch.zone_6.last_changed))/60)|round(0) ,0 ] | max }}
            {{ [ (states('input_number.zone_7_run_time')|int - (as_timestamp(now()) - as_timestamp(states.switch.zone_7.last_changed))/60)|round(0) ,0 ] | max }}
            {{ [ (states('input_number.zone_8_run_time')|int - (as_timestamp(now()) - as_timestamp(states.switch.zone_8.last_changed))/60)|round(0) ,0 ] | max }}
            {{ [ (states('input_number.zone_9_run_time')|int - (as_timestamp(now()) - as_timestamp(states.switch.zone_9.last_changed))/60)|round(0) ,0 ] | max }}
          {% else %}
            0
          {% endif %} 
        unit_of_measurement: "min"