Skalar
November 7, 2023, 8:31pm
1
I’m looking for a way to use a select template to switch different outputs depending on the choice of a scene. The selection works, I just don’t know how to branch after the selection.
select:
- platform: template
name: "Scenes"
id: sce
optimistic: true
options:
- Scene0
- Scene1
- Scene2
- Scene3
- Scene4
initial_option: Scene0
on_value:
# How does it go on here?
Here’s a chopped-up code example which is in production use:
select:
# define a select for the device state control
# https://esphome.io/components/select/template.html?highlight=template
- platform: template
name: "Heat Mode"
optimistic: true
id: heat_mode
options:
- "Off"
- "Low"
- "Medium"
- "High"
initial_option: "Off"
on_value:
then:
- logger.log:
format: "Heat Mode: %s (index %d)"
args: ["x.c_str()", "i"]
- if:
condition:
lambda: |-
return (id(heat_mode).active_index() == 0);
then:
- logger.log: "Off"
- if:
condition:
lambda: |-
return (id(heat_mode).active_index() == 1);
then:
- logger.log: "Low"
- if:
condition:
lambda: |-
return (id(heat_mode).active_index() == 2);
then:
- logger.log: "Medium"
- if:
condition:
lambda: |-
return (id(heat_mode).active_index() == 3);
then:
- logger.log: "High"
If this helps, this post!
1 Like
Skalar
November 7, 2023, 9:10pm
3
Happy - you made my day
I was looking for that since hours but found nothing.
I had to post an example after this simple block of code took almost week to get working!
YAML indentation is the cause of most ESPhome errors, but docs without example code must be second.
Happy to help
Skalar
November 8, 2023, 7:14pm
5
this is my finale code
select:
- platform: template
name: "Modus"
id: modus_mode
optimistic: true
options:
- Auto
- 30°C
- -5°C
initial_option: Auto
on_value:
then:
- lambda: |-
if (id(modus_mode).active_index() == 0) {
id(rly_temp).turn_off();
id(rly_hand).turn_off();
} else if (id(modus_mode).active_index() == 1) {
id(rly_temp).turn_on();
id(rly_hand).turn_off();
} else if (id(modus_mode).active_index() == 2) {
id(rly_temp).turn_on();
id(rly_hand).turn_on();
}