Help with a simple timer

I had it working fine then a update or restart…something… and now I get error. extra key not allowed @ data[‘condition’]. I’ve searched and tried different thing for days none… I give, I need help. it’s somewhere in the condition: condition: template, because if I remove that and the if, elif it works, and the if, elif works in the template check. Thanks

front_zone_timer_start:
  sequence:
  - service: timer.start
    data_template:
      entity_id: timer.front_zone_timer
      condition:
      - condition: template
        value_template: >
          {% if states('sensor.sprinkler_current_zone_front') == 'Zone 1' %}
            duration: 00:{{ states.input_number.sprinkler_zone_1_run_time.state | int }}:00
          {% elif states('sensor.sprinkler_current_zone_front') == 'Zone 2' %}
            duration: 00:{{ states.input_number.sprinkler_zone_2_run_time.state | int }}:00
          {% elif states('sensor.sprinkler_current_zone_front') == 'Zone 3' %}
            duration: 00:{{ states.input_number.sprinkler_zone_3_run_time.state | int }}:00
          {% elif states('sensor.sprinkler_current_zone_front') == 'Zone 4' %}
            duration: 00:{{ states.input_number.sprinkler_zone_4_run_time.state | int }}:00
          {% endif %}

The way you had it would never have worked. You can only template the value of a key: value pair. You can’t template the key. Do it like this:

front_zone_timer_start:
  sequence:
  - service: timer.start
    data_template:
      entity_id: timer.front_zone_timer
      duration: >
          {% if states('sensor.sprinkler_current_zone_front') == 'Zone 1' %}
            00:{{ states.input_number.sprinkler_zone_1_run_time.state | int }}:00
          {% elif states('sensor.sprinkler_current_zone_front') == 'Zone 2' %}
            00:{{ states.input_number.sprinkler_zone_2_run_time.state | int }}:00
          {% elif states('sensor.sprinkler_current_zone_front') == 'Zone 3' %}
            00:{{ states.input_number.sprinkler_zone_3_run_time.state | int }}:00
          {% elif states('sensor.sprinkler_current_zone_front') == 'Zone 4' %}
            00:{{ states.input_number.sprinkler_zone_4_run_time.state | int }}:00
          {% endif %}

Thanks for the help. It did work that way before… the way you have it didn’t work.

FWIW, I believe the template can be reduced to this:

  front_zone_timer_start:
    sequence:
    - service: timer.start
      data_template:
        entity_id: timer.front_zone_timer
        duration: >
          {% set z = states('sensor.sprinkler_current_zone_front')[-1:] %}
          {{ (states('input_number.sprinkler_zone_' ~ z ~ '_run_time') | int) * 60 }}

How it works:

First line gets the state value of sensor.sprinkler_current_zone_front and then slices the last character of the value. So if the value is Zone 3 it sets the variable z to 3.

Second line concatenates the string ‘input_number.sprinkler_zone_’ with the value of variable z and the string ‘_run_time’. So if z is 3, the result of the concatenation is an entity_id:

input_number.sprinkler_zone_3_run_time

It gets the state value of that entity, converts it from string to integer and then multiplies it by 60 (to convert minutes to seconds).

1 Like

Nope. Home assistant does not work like that.

I must have had spacing off… Sorry that did work.

Try 123’s template. It’s a lot more compact.

Newbie here I was going to get to that but was trying to do one step at a time. Thanks both of you… I was trying to do it myself learning along the way but got stumped along the way.