I need you help for one of my automation. I would like to use the value of an “input_select” in order to select one specific switch. To do that I created one “input_select” (name: heating_mode_week) with the following list: week, week with lunch, work at home, away.
For each choice, I would like to associate one specific switch (which is a scheduler switch).
I think the following is similar to what you are trying to achieve, in this case I have an input_select that has a number of lighting scenes that I can cycle up/down with a Zigbee remote control (there is another automation for the remote that uses input_select: next/previous to do this).
alias: Kitchen Light Scenes
description: Turn On Kitchen Scene Based on Input Select
trigger:
- entity_id: input_select.kitchen_scenes
platform: state
condition: []
action:
- data_template:
entity_id: scene.{{trigger.to_state.state}}
service: scene.turn_on
initial_state: "on"
mode: queued
max: 5
In the action you could try changing the entity_id to switch.{{trigger.to_state.state}} and the service to switch.turn_on to see if that works for you.
In this case it won’t work because the input_select’s value doesn’t match the desired switch’s object_id. For example, ‘Week with lunch’ is not the desired switch’s ‘heating_week_lunch_workinhome’.
You can take advantage of what Jonah1970 has suggested if you rename your switches to match the values in your input_select.
Instead of using a long chain of if-elif statements, it uses a dictionary. The variable values is a dictionary containing your input_select’s options and their corresponding text strings. The template uses the dictionary to get the matching text string.
- alias: Week selection
trigger:
- platform: state
entity_id: input_select.heating_mode_week
condition: []
action:
- service: switch.turn_on
target:
entity_id: >
{% set values = {'week': 'week', 'Week with lunch': 'week_lunch',
'Work in home': 'week_lunch_workinhome', 'Away': 'away'} %}
switch.heating_{{ values.get(trigger.to_state.state, 'week') }}
New requirement no… But, yes, when I posted my question I was only focus to find a solution to turn_on one switch from an input_select. But, as I have to selection only one switch, I have to turn_off the others…