Lost in automation template

It seems i dont get the semantics of automation “programming”.

While this condition with a literal “state” works on an input_select

- if:
    - condition: state
      entity_id: input_select.eg_wohnzimmer_szenen
      state: scene.eg_wohnzimmer_aus

this does not (where “scene.eg_wohnzimmer_aus” is the first option in the select helper)

- if:
    - condition: state
      entity_id: input_select.eg_wohnzimmer_szenen
      state: "{{ input_select.eg_wohnzimmer_szenen.options[0] }}"

What is the correct syntax to get “state” expanded?

Regards Michael

A State Condition’s state option doesn’t support templates.

However it does support a direct reference to an Input entity’s value.

What exactly do you want your condition to confirm (because it’s unclear what you want to do based on the last example you posted). Your last example checks if an Input Select’s value is equal to its own current value, which isn’t much of a test.

Thanks for pointing out that it is simply not supported.

For the mechanics of the test - it is just the generalization of the first, literal one. It checks if the current value is the first of the available options - which is a very useful abstraction imho. E.g. if you reuse this template, you only have to switch the input_select helper name, not the constant representing the first option (which is “…_aus” for me by convention.)

Not supporting templates for “state” is like not supporting expressions on the right hand in a programming language. Compare

if (foo.state == "myState") {
   ...
}

and

if (foo.state == computeStateInSomeWay(context)) {
   ...
}

Use a Template Condition.


Example


- if:
    - condition: template 
      value_template: >
        {{ states('input_select.eg_wohnzimmer_szenen') == 
          state_attr('input_select.eg_wohnzimmer_szenen', 'options')[0] }}
1 Like

Thanks a lot.

Pointing me to the “State Condition” reference made me work through the other ones and i was able to find the exact solution you gave above. I was just about to return and post it :slight_smile:

Happy new year!

1 Like