Template Question - Multiple Input Select Options

I would like to simplify my automations but I’m having trouble with the templating.

Original code:

  condition:
    - condition: or
      conditions:
      - condition: state
        entity_id: input_select.woning_status_select
        state: 'Thuis'
      - condition: state
        entity_id: input_select.woning_status_select
        state: 'Juist Thuis'
      - condition: state
        entity_id: input_select.woning_status_select
        state: 'Juist Wakker'
      - condition: state
        entity_id: input_select.woning_status_select
        state: 'Dag Thuis'
      - condition: state
        entity_id: input_select.woning_status_select
        state: 'Vakantie'

New code with templating:

> condition:
>     - condition: template
>       value_template: '{{not is_state("input_select.woning_status_select","Weg") and not is_state("input_select.woning_status_select","Juist Weg") and not is_state("input_select.woning_status_select","Slapen")}}'

Question:
is it possible to combine the 3 options in one?

E.g.:

condition:
    - condition: template
      value_template: '{{not is_state("input_select.woning_status_select","Weg" or "Juist Weg" or "Slapen")}}'

This would simplify a lot of my automations.

Thanks for the help.

Yes, this would do the trick:

  condition:
    - condition: template
      value_template: "{{ states('input_select.woning_status_select') not in ['Weg', 'Juist Weg', 'Slapen'] }}"
2 Likes

Thank you so much petro!!
This will help me reduce my lines of code drastically.

I went in one Yaml from 430 lines to 278.
So thanks for the tip :slight_smile:

1 Like

Is it possible to simplify different input selects?

For example I have:

- input_select.alice_status_select
- input_select.bob_status_select
- input_select.david_status_select

I want to create something like:

value_template: "{{ states('input_select.****_status_select') not in ['Weg', 'Juist Weg', 'Slapen'] }}"

if you want the condition to work for other input selects inside an automation:

- alias: Do something w/ input selects
  trigger:
    platform: state
    entity_id:
      - input_select.alice_status_select
      - input_select.bob_status_select
      - input_select.david_status_select
  condition:
    condition: template
    value_template: "{{ states(trigger.entity_id) not in ['a', 'b', 'c'] }}"

Whatever triggers the automation will be supplied in trigger.entity_id

1 Like