An input_select
currently allows you to specify a selection list:
input_select:
my_selector:
name: My Selector
options:
- Kitchen
- Garage
- Bedroom
- Office
The options (Kitchen, Garage, Bedroom, Office) will appear as choices in the selector’s list. However there are situations where the chosen option is not the value we wish to use (in an automation).
For example, “Garage” may represent the temperature value to set for the garage. However, input_select only allows you to define “Garage” but not its associated value. The way to achieve this now is to use a map (key-value pairs) in the automation’s template.
{% set temp_map =
{ 'Kitchen':'20',
'Garage':'10',
'Bedroom':'22',
'Office':'23' } %}
{% set state = states('input_select.my_selector') %}
{% set temp = temp_map[state] if state in temp_map %}
{{temp}}
Ideally, the mapping should reside with the selector. Automations can refer to the selector and use either the chosen option’s key (Kitchen) or its value (20). Here’s an example of how it would appear:
input_select:
my_selector:
name: My Selector
options:
- option: Kitchen
value: '20'
- option: Garage
value: '10'
- option: Bedroom
value: '22'
- option: Office
value: '23'
For reference, this feature was discussed in this thread.
EDIT
Based on discussions in this thread, instead of using key-value pairs, which make the input_select verbose, the neater solution is a list.
input_select:
my_selector:
name: My Selector
options:
- Kitchen, 20
- Garage, 10
- Bedroom, 22
- Office, 23
input_select:
my_selector:
name: My Selector
options:
- Low, level1
- Medium, level2
- High, level3