Automation with Input_select

I have been trying to use the device listed in an input_select in an automation. I’ve had problems with that so I created a simple automation with a button trying to read the value selected and simply place it in a input_text field to iron out my other automation but that does not work either. I’m not sure if I’m using input_select wrong or what’s going on. I see some sample automatons where the selection triggers the automation but I’m wanting to use that data do determine which device the automation is acted upon. Will it work that way? Here is my simple test automation

alias: "Input Select Test "
description: ""
trigger:
  - platform: state
    entity_id:
      - input_button.input_select_test_button
condition: []
action:
  - service: input_select.select_option
    data: {}
    target:
      entity_id: input_select.timed_off_device_selector
  - service: input_text.set_value
    data: input_select.timed_off_device_selector
    target:
      entity_id: input_select.timed_off_device_selector
mode: single

Neither of your service calls are correct.

You need to specify which option to select:

  - service: input_select.select_option
    data: 
      option: Your Option Here
    target:
      entity_id: input_select.timed_off_device_selector

See: https://www.home-assistant.io/integrations/input_select/#services

You need to template the value to get the state when setting the text sensor:

  - service: input_text.set_value
    data: 
      value: "{{ states('input_select.timed_off_device_selector') }}"
    target:
      entity_id: input_select.timed_off_device_selector

See: https://www.home-assistant.io/integrations/input_text/#services

If you post the original automation that just uses the input_select we can help you with that. There is no need for an input text helper a well.

The automation is simply a list of several switches and my intent was to select one switch from the dropdown and only turn on the one selected with an action button. With you defining the option value, does that mean that i have to pre-define each switch in the input_select and then match the selected value with that? I was thinking it would “read” the selected switch name and simply input that name value into the defined action.

The input text helper isn’t part of that intended automation. It’s just my attempt to try to see how HA reads the input_select.

I mean it would help if they were similar. e.g.

Input select options:

  • Kitchen
  • Laundry
  • Lounge Room

Switch entity_ids:

switch.kitchen
switch.laundry
switch.lounge_room

Automation to turn on a switch when selected in the input select

trigger:
  - platform: state
    entity_id: input_select.switch_to_turn_on
    to:  
action:
  - service: switch.turn_on
    target:
      entity_id: "switch.{{ states('input_select.switch_to_turn_on')|slugify }}"

The |slugify filter changes capital letters to lower case and replaces spaces with underscores. Making your input select option match the object_id of the switch entity_id. Lounge Room → lounge_room.

FYI an entity_id is composed of domain.object_id e.g. in switch.laundry “switch” is the domain and “laundry” is the object_id.

If your select options are significantly different from the switch entity_id’s object_id then you have to use a lot of if/elif statements to select the correct entity to turn on.

e.g.

Input select options:

  • Kitchen
  • Laundry
  • Lounge Room

Switch entity_ids:

switch.kitchen_bench_lights
switch.laundry_spotlight
switch.lounge_room_downlights

Automation:

trigger:
  - platform: state
    entity_id: input_select.switch_to_turn_on
    to:  
action:
  - service: switch.turn_on
    target:
      entity_id: >
        {% if trigger.to_state.state = "Kitchen" %}
          switch.kitchen_bench_lights
        {% elif trigger.to_state.state = "Laundry" %}
          switch.laundry_spotlight
        {% else %}
          switch.lounge_room_downlights
        {% endif %}

Thank you! Your example helps a lot. It does clear up my misunderstanding that I could “read” the selected device from the list and populate that directly into the entity_id.

1 Like