esphome / esphome/feature-requests
Expose backlight state for `lcd_pcf8574`
- 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**
I'd like the backlight state (on/off) for the `lcd_pcf8574` platform to be exposed publicly so it can be referenced in lambdas.
**Please describe your use case for this integration and alternatives you've tried:**
I have an ESP8266 hooked up to an LCD and I have backlight controls exposed to Home Assistant through a template sensor:
```yaml
switch:
- platform: template
name: "Bug Counter Backlight"
optimistic: true
turn_on_action:
- lambda: "id(counter_display)->backlight();"
turn_off_action:
- lambda: "id(counter_display)->no_backlight();"
```
Ideally, you should be able to poll for the state using something like this:
```cpp
if (id(counter_display)->backlight_state()) {
return true;
} else {
return false;
}
```
However, since there's no way to get the actual state of the backlight it's not possible to return the true state via the sensor. So as a workaround I enabled `optimistic` mode so ESPHome just assumes the last set state is current. But this can get messy if other things touch the backlight on the display directly. Also, as a side effect, if the device restarts, the state will default to off, but the backlight is actually on. There are ways to fix this (with global variables and such), but it feels pretty hacky to me.
It looks like the backlight state is [already stored internally](https://github.com/esphome/esphome/blob/5cb56bc6774a52664703941796fa80f5de000877/esphome/components/lcd_pcf8574/pcf8574_display.cpp#L48-L55), so this should be pretty simple to implement.
I have the backlight set up to turn off along with all my other lights when I go to sleep, and back on when I wake up.
**Additional context**
I'm happy to submit a PR for this! Just wanted to make sure this is suitable for the project before doing so.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with esphome/components/lcd_pcf8574/pcf8574_display.cpp, especially the existing internal backlight state referenced in the issue. Trace the public display API and lambda usage, then expose that state for callers so a lambda can query whether the backlight is on; done means the example can return the actual state.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- embedded-iot
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100