Rainbird "Template rendered invalid entity IDs:"

Hi Friends, i have issue to modulize my rainbird irrigation

my idea is following

  • use a helper to change the order when which zone will start
  • use helpers to select on which days i wanna start irrigation
  • use helpers to adapt the irrigation duration and others

This is how my Dashboard looks like

i got now following error “Template rendered invalid entity IDs:”

so the Template which seems not working with service irrigation is following

{% set order0 = states('input_text.garden_sprinkler_order')[0]%}
{% set order1 = states('input_text.garden_sprinkler_order')[1]%}
{% set order2 = states('input_text.garden_sprinkler_order')[2]%}
{% set order3 = states('input_text.garden_sprinkler_order')[3]%}
{% set zone = order0 %}
{% set active = "switch.rain_bird_sprinkler_" ~zone%}
{{ zone != ' ' and states(active) != 'unknown' }}
{{ active }}

Does Anyone has an idea why?

Here is the complete Automation which works in generel great

  - if:
      - condition: template
        value_template: |-
          {% set order0 = states('input_text.garden_sprinkler_order')[0]%}
          {% set order1 = states('input_text.garden_sprinkler_order')[1]%}
          {% set order2 = states('input_text.garden_sprinkler_order')[2]%}
          {% set order3 = states('input_text.garden_sprinkler_order')[3]%}
          {% set zone = order0 %}
          {% set active = "switch.rain_bird_sprinkler_" ~zone%}
          {{ zone != ' ' and states(active) != 'unknown' }}
    then:
      - service: rainbird.start_irrigation
        data:
          duration: "{{states('input_datetime.garden_sprinkler_duration').split(':')[1]}}"
        target:
          entity_id: "{{ active }}"
      - wait_template: "{{ states(active) == \"on\" }}"
        continue_on_timeout: false
      - delay:
          hours: 0
          minutes: 0
          seconds: 10
          milliseconds: 0
      - wait_template: "{{ states(active) == \"off\" }}"
        continue_on_timeout: false

Variables don’t pass between templates. You have to use a variable action to do that. As for your error, it’s unrelated to the templates that you have posted here.

e.g.

- variables:
    order: "{{ states('input_text.garden_sprinkler_order').split() }}"
    zone: "{{ order[0] }}"
    active: switch.rain_bird_sprinkler_{{ zone }}
- if:
  - condition: template
    value_template: "{{ zone != ' ' and states(active) in ['on','off'] }}"
  then:
      - service: rainbird.start_irrigation
        data:
          duration: "{{states('input_datetime.garden_sprinkler_duration').split(':')[1]}}"
        target:
          entity_id: "{{ active }}"
      - wait_template: "{{ is_state(active, 'on') }}"
        continue_on_timeout: false
      - delay:
          hours: 0
          minutes: 0
          seconds: 10
          milliseconds: 0
      - wait_template: "{{ is_state(active, 'off') }}"
        continue_on_timeout: false

EDIT: Ah it looks like your error is comign from this entity_id: "{{ active }}" which would be fixed by using the variable action mentioned above.

Hi, @petro thx for the hint with Variables, never worked before with this, cause doesnt understood how to test Variables 1st in Developer Tools, seems theit not working.

    order: "{{ states('input_text.garden_sprinkler_order').split() }}"
    zone: "{{ order[0] }}"

When i test this kind of Code in Developer Tools i got Error UndefinedError: ‘order’ is undefined

you can’t test this in dev tools, you have to make changes to make it work in dev tools. This in variables

    order: "{{ states('input_text.garden_sprinkler_order').split() }}"
    zone: "{{ order[0] }}"
    active: switch.rain_bird_sprinkler_{{ zone }}

is eqivalent to this in dev tools

{% set order = states('input_text.garden_sprinkler_order').split() %}
{% set zone = order[0] %}
{% set active = 'switch.rain_bird_sprinkler_' ~ zone %}

@petro so when i tested with your Syntax, it doesnt show any error, but also no Sprinkler Zone starts.
Q: How i can debug this kind of Code, cause in developer tools i dont see any option to reverse engineer with variables?

You debug it by looking at the trace of your automation/script

@petro sure, but in Trace and Debug it doesnt show what results came out
what i saw is in Settings \ Logs that the order[0] seems not working correctly

helper is 1342
so order[0] should be 1
and it shows switch.rain_bird_sprinkler_1342

You can look at each variable step and see what variables are derived in the changed variables section when clicking on nodes.

@petro

it isnt working with this code

variables:
  order: "{{ states('input_text.garden_sprinkler_order').split() }}"
  zone: "{{ order[0] }}"
  active: switch.rain_bird_sprinkler_{{ zone }}

also not with

variables:
  order: "{{ states('input_text.garden_sprinkler_order').split() }}"
  zone: "{{ order[0] }}"
  active: switch.rain_bird_sprinkler_{{ order }}

seems a small issue in code but i dont see where, absolut strange

can you post the output or an error? I’m going off what you wrote above. That code will work assuming that you put a space between each number for your state on input_text.garden_sprinkler_order

@petro
sure

image

“Referenced entities switch.rain_bird_sprinkler_1342 are missing or not currently available”
which is clear cause correct will be switch.rain_bird_sprinkler_1342

Your previous code made this same assumption, so I did as well. Is this true or not?

so my code as template works 100% yes
mainly in variable it seems it doesnt split the 4 not.

change to

  order: "{{ states('input_text.garden_sprinkler_order') }}"

if you aren’t using spaces.

@petro it seems

zone: "{{ order[0] }}"
isnt working correctly

cause resulting switch.rain_bird_sprinkler_1342 instead switch.rain_bird_sprinkler_1

it’s working fine, please just change what I said in my last response.

And if that doesn’t work, you’ll have to use this:

  order: "{{ states('input_text.garden_sprinkler_order') | list }}"
if:
  - condition: template
    value_template: |-
      {% set order0 = states('input_text.garden_sprinkler_order')[0]%}
      {% set order1 = states('input_text.garden_sprinkler_order')[1]%}
      {% set order2 = states('input_text.garden_sprinkler_order')[2]%}
      {% set order3 = states('input_text.garden_sprinkler_order')[3]%}
      {% set zone = order0 %}
      {% set active = "switch.rain_bird_sprinkler_" ~zone%}
      {{ zone != ' ' and states(active) != 'unknown' }}
then:
  - variables:
      order: "{{ states('input_text.garden_sprinkler_order') | list }}"
      zone: "{{ order[0] }}"
      active: switch.rain_bird_sprinkler_{{ zone }}
  - service: rainbird.start_irrigation
    data:
      duration: "{{states('input_datetime.garden_sprinkler_duration').split(':')[1]}}"
    target:
      entity_id: "{{ active }}"
  - wait_template: "{{ states(active) == \"on\" }}"
    continue_on_timeout: false
  - wait_template: "{{ states(active) == \"off\" }}"
    continue_on_timeout: false

@petro your last tipp with using “list” helped out to get it working

you are my HERO :slight_smile:
thx a lot and Greetings from Poland :slight_smile:

You should really switch to what I wrote above. You’re accessing the same variables multiple times, there’s no reason to have that if condition use differently created variables

agree, this is next, 1st for me is allways important the syntax is working, which is now doing
next step is now to variablize all triggers and conditions and if statements , triggers and actions that i can simple reuse the codesnippets multiple times :slight_smile:

@petro as you see what i am doing, cause i work here with lot of helpers

alias: Garden - Sprinkler
description: ""
trigger:
  - platform: template
    value_template: >-
      {% set time_now = now().strftime('%H:%M') %}

      {% set time_timer = states('input_datetime.garden_sprinkler_timer_1')[:5]
      %}

      {{ time_now == time_timer }}
  - platform: template
    value_template: >-
      {% set time_now = now().strftime('%H:%M') %}

      {% set time_timer = states('input_datetime.garden_sprinkler_timer_2')[:5]
      %}

      {{ time_now == time_timer }}
  - platform: template
    value_template: >-
      {% set time_now = now().strftime('%H:%M') %}

      {% set time_timer = states('input_datetime.garden_sprinkler_timer_3')[:5]
      %}

      {{ time_now == time_timer }}
condition:
  - condition: template
    value_template: >-
      {% set today = now().strftime('%a') %}   

      {% set time_now = now().strftime('%H:%M') %}   

      {% set timer_mon = states('input_boolean.garden_sprinkler_timer_mon') %}  

      {% set timer_tue = states('input_boolean.garden_sprinkler_timer_tue') %}  

      {% set timer_wed = states('input_boolean.garden_sprinkler_timer_wed') %} 

      {% set timer_thu = states('input_boolean.garden_sprinkler_timer_thu') %} 

      {% set timer_fri = states('input_boolean.garden_sprinkler_timer_fri') %}  

      {% set timer_sat = states('input_boolean.garden_sprinkler_timer_sat') %}  

      {% set timer_sun = states('input_boolean.garden_sprinkler_timer_sun') %} 

      {% set today_timer = states('input_boolean.garden_sprinkler_timer_'
      ~today.lower()) %}  

      {% set time_timer03 =
      states('input_datetime.garden_sprinkler_timer_3')[:5] %} 

      {% set time_timer02 =
      states('input_datetime.garden_sprinkler_timer_2')[:5] %} 

      {% set time_timer01 =
      states('input_datetime.garden_sprinkler_timer_1')[:5] %}


      {{
       today_timer == "on"
       and
       time_now != "00:00:00"
       and (
         time_now == time_timer01
         or 
         time_now == time_timer02
         or
         time_now == time_timer03
         )
      }}
action:
  - if:
      - condition: template
        value_template: |-
          {% set order0 = states('input_text.garden_sprinkler_order')[0]%}
          {% set order1 = states('input_text.garden_sprinkler_order')[1]%}
          {% set order2 = states('input_text.garden_sprinkler_order')[2]%}
          {% set order3 = states('input_text.garden_sprinkler_order')[3]%}
          {% set zone = order0 %}
          {% set active = "switch.rain_bird_sprinkler_" ~zone%}
          {{ zone != ' ' and states(active) != 'unknown' }}
    then:
      - variables:
          order: "{{ states('input_text.garden_sprinkler_order') | list }}"
          zone: "{{ order[0] }}"
          active: switch.rain_bird_sprinkler_{{ zone }}
      - service: rainbird.start_irrigation
        data:
          duration: "{{states('input_datetime.garden_sprinkler_duration').split(':')[1]}}"
        target:
          entity_id: "{{ active }}"
      - wait_template: "{{ states(active) == \"on\" }}"
        continue_on_timeout: false
      - wait_template: "{{ states(active) == \"off\" }}"
        continue_on_timeout: false
  - if:
      - condition: template
        value_template: |-
          {% set order0 = states('input_text.garden_sprinkler_order')[0]%}
          {% set order1 = states('input_text.garden_sprinkler_order')[1]%}
          {% set order2 = states('input_text.garden_sprinkler_order')[2]%}
          {% set order3 = states('input_text.garden_sprinkler_order')[3]%}
          {% set zone = order1 %}
          {% set active = "switch.rain_bird_sprinkler_" ~zone%}
          {{ zone != ' ' and states(active) != 'unknown' }}
    then:
      - variables:
          order: "{{ states('input_text.garden_sprinkler_order') | list }}"
          zone: "{{ order[1] }}"
          active: switch.rain_bird_sprinkler_{{ zone }}
      - service: rainbird.start_irrigation
        data:
          duration: "{{states('input_datetime.garden_sprinkler_duration').split(':')[1]}}"
        target:
          entity_id: "{{ active }}"
      - wait_template: "{{ states(active) == \"on\" }}"
        continue_on_timeout: false
      - wait_template: "{{ states(active) == \"off\" }}"
        continue_on_timeout: false
  - if:
      - condition: template
        value_template: |-
          {% set order0 = states('input_text.garden_sprinkler_order')[0]%}
          {% set order1 = states('input_text.garden_sprinkler_order')[1]%}
          {% set order2 = states('input_text.garden_sprinkler_order')[2]%}
          {% set order3 = states('input_text.garden_sprinkler_order')[3]%}
          {% set zone = order2 %}
          {% set active = "switch.rain_bird_sprinkler_" ~zone%}
          {{ zone != ' ' and states(active) != 'unknown' }}
    then:
      - variables:
          order: "{{ states('input_text.garden_sprinkler_order') | list }}"
          zone: "{{ order[2] }}"
          active: switch.rain_bird_sprinkler_{{ zone }}
      - service: rainbird.start_irrigation
        data:
          duration: "{{states('input_datetime.garden_sprinkler_duration').split(':')[1]}}"
        target:
          entity_id: "{{ active }}"
      - wait_template: "{{ states(active) == \"on\" }}"
        continue_on_timeout: false
      - wait_template: "{{ states(active) == \"off\" }}"
        continue_on_timeout: false
  - if:
      - condition: template
        value_template: |-
          {% set order0 = states('input_text.garden_sprinkler_order')[0]%}
          {% set order1 = states('input_text.garden_sprinkler_order')[1]%}
          {% set order2 = states('input_text.garden_sprinkler_order')[2]%}
          {% set order3 = states('input_text.garden_sprinkler_order')[3]%}
          {% set zone = order3 %}
          {% set active = "switch.rain_bird_sprinkler_" ~zone%}
          {{ zone != ' ' and states(active) != 'unknown' }}
    then:
      - variables:
          order: "{{ states('input_text.garden_sprinkler_order') | list }}"
          zone: "{{ order[3] }}"
          active: switch.rain_bird_sprinkler_{{ zone }}
      - service: rainbird.start_irrigation
        data:
          duration: "{{states('input_datetime.garden_sprinkler_duration').split(':')[1]}}"
        target:
          entity_id: "{{ active }}"
      - wait_template: "{{ states(active) == \"on\" }}"
        continue_on_timeout: false
      - wait_template: "{{ states(active) == \"off\" }}"
        continue_on_timeout: false
mode: restart