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
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.
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.
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.