Multiple input selects in automation

Hello,

I have three A/C units which I would like to “control” via multiple input_selects.

First input_select holds the actual units
Second input_select holds the swing mode
Third input_select holds the fan mode

My goal is to create a “flexibel” automation and/or script which can control each device and each setting without creating many automation/scripts for each unit.

For example, I can set the swing mode via a boolean with this code;

- alias: Set swing mode on AC unit
  trigger:
    platform: state
    entity_id: input_boolean.ac_set_swing_mode

  action:
    - service: climate.set_swing_mode
      data_template:
        entity_id: >
          {% if is_state("input_select.ac_device", "Unit 1") %} climate.unit1
          {% elif is_state("input_select.ac_device", "Unit 2") %} climate.unit2
          {% elif is_state("input_select.ac_device", "Unit 3") %} climate.unit3
          {% endif %}
      data:
        swing_mode:  "{{ states('input_select.swing_mode') }}"

This code sets the swing mode selected (in input_select.swing_mode) at the correct unit (chosen from input_select.ac_device by switching a boolean. No problem so far…

I want to make my automation fault proof. As for now, if somebody hits the boolean, the AC unit it switch on to set fan mode or swing mode. This is not my intent. I want the automation to run only if the selected AC unit is on (so status != “off”). Normally I would say, you need to create a condition for this, but I can’t seem to find out how.

I need a condition where the entity_id is based on input_select.ac_device value and status is different then off

Anybody who can help me out?

I haven’t done much with the climate integration, but I think this is a step toward what you are looking for.

As long as you are using the naming convention from your example, you can avoid all those “if/elifs”. Just extract the last character from your ac_device input select with a template, then set the entity id as a variable to use in your condition and action.

- alias: Set swing mode on AC unit
  trigger:
    platform: state
    entity_id: input_boolean.ac_set_swing_mode
  condition: "{{ 'True' if states(id) != 'off' else 'False'}}"
  action:
    - service: climate.set_swing_mode
      data_template:
        entity_id: "{{id}}"
      data:
        swing_mode:  "{{ states('input_select.swing_mode') }}"
  variables:
    id: "climate.unit{{ states('input_select.ac_device')[-1] }}"

Exactly what I needed and it works like a charm! Thanks!

I can now control 3 units with 1 automation, inputs based on multiple input.select options

1 Like