esphome / esphome/feature-requests
Support restore_mode or similar in (Template) Switches
- Dominant language
- No language data
- Stars
- 450
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the problem you have/What new integration you would like**
It would be nice if the Template Switch Platform (or the Switch Component) supported `restore_mode`, just like GPIO Switch Platform does:
```yaml
# Config example feature
switch:
- platform: template
id: chime_active
name: Doorbell Chime Active
optimistic: true
restore_mode: RESTORE_DEFAULT_ON
```
**Please describe your use case for this integration and alternatives you've tried:**
Currently, with only the `restore_state` option allowed:
```yaml
# Config example current - wrong initial state
switch:
- platform: template
id: chime_active
name: Doorbell Chime Active
optimistic: true
restore_state: true
```
on the first boot (or if it cannot restore the state) this switch is turned off (thought, I would prefer to be able to have it turned on in this case).
A workaround it detailed in [Frenck's Blog](https://frenck.dev/diy-smart-doorbell-for-just-2-dollar/):
```yaml
# Config example current - correct initial state but cumbersome
globals:
- id: chime
type: bool
restore_value: true
initial_value: 'true'
switch:
- platform: template
name: Doorbell Chime Active
id: chime_active
restore_state: false
turn_on_action:
- globals.set:
id: chime
value: 'true'
turn_off_action:
- globals.set:
id: chime
value: 'false'
lambda: |-
return id(chime);
```
I would argue that supporting `restore_mode` would simplify the config file dramatically whilst also making it more easily understandable.
**Additional context**
Alternatively to a `restore_mode` option, could be a combination of `restore_value` and `initial_value`, as done for `globals`. As this is a switch, maybe `initial_state` would be a better option name. Yet, anything besides `restore_mode` would defer from the GPIO switch configuration. It is probably good to have switches to be configured similarly.
Maybe, `restore_mode` (or the alternative mechanism mentioned) could be implemented in the Switch Component as it could be useful for any switch, independent of platform.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the Template Switch Platform and Switch Component entry points, then compare their configuration with the GPIO Switch Platform's restore_mode behavior. Decide whether the option belongs at the platform or component level, and verify that the YAML example supports a configurable initial state when restoration is unavailable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- yaml
- Domain
- embedded-iot
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100