esphome / esphome/feature-requests
Templatable `icon` setting
- 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**
Allow (at least for template components) to use the icon templatable: For example:
```yaml
icon: !lambda: |-
if (x == 1) {
return {"mdi:lightbulb-on"};
} else {
return {"mdi:lightbulb"};
}
```
or:
```yaml
icon: !lambda: |-
if (id(pump_status).state == 1 and id(valve_status).state == 0) {
return {"mdi:hand-water"};
} else if (id(pump_status).state == 1 and id(valve_status).state == 1) {
return {"mdi:hydro-power"};
} else if (id(pump_status).state == 0 and id(valve_status).state == 0) {
return {"mdi:radiator-off"};
} else {
return {"mdi:alert"};
}
```
The rendering of the labmdas could be taken directly from the Template Text Sensor. API needs to be extended to update this too when changed.
**Please describe your use case for this integration and alternatives you've tried:**
Home Assistant supports `icon_template` or `icon` configuration option for their template sensors, which can set different icons based on jinja templates - referring to states of self, or other entities from the system.
This could be beneficial in ESPHome too.
**Additional context**
https://www.home-assistant.io/integrations/switch.template/
https://www.home-assistant.io/integrations/light.template/
https://www.home-assistant.io/integrations/template/
etc.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the template components and the Template Text Sensor behavior mentioned in the request, then trace how the API publishes entity updates. Define the implementation scope and tests needed so a templated icon can change with state and the updated icon is exposed through the API.
Written by the indexing model from the issue text.
Assessment
- Domain
- api, embedded-iot
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100