I’m new to using ESPHome and am having a lot of issues with what seems to be a simple task. I am trying to read from a text sensor, e.g. homemade_alarm
which is either on
or off
, and display that on an OLED screen. I have been reading through lots of articles and documentation and can’t figure out how to do this. I think the issue is with converting the text sensor to an integer. But even looking into that, I can’t figure out what to do. Any help would be greatly appreciated.
I would just like the text on the OLED to change depending if the sensor is showing ‘on’ or ‘off’:
i2c:
sda: D2
scl: D1
frequency: 800kHz
sensor:
- platform: homeassistant
id: alarm_status
entity_id: input_boolean.homemade_alarm
internal: true
font:
- file: 'slkscr.ttf'
id: font1
size: 20
display:
- platform: ssd1306_i2c
model: "SSD1306 128x64"
address: 0x3C
rotation: 180
lambda: |-
if (id(alarm_status).state) {
it.printf(64, 40, id(font1), TextAlign::CENTER , "Alarm On");
} else {
it.printf(64, 40, id(font1), TextAlign::CENTER , "Alarm Off");
}
For what it’s worth, the above code just shows “Alarm On” and doesn’t change when the boolean changes in Home Assistant. The logs show:
[W][homeassistant.sensor:015]: Can't convert 'off' to number!
EDIT: Maybe the issue is because input_boolean isn’t a real sensor in HA? Maybe it needs to be converted to a sensor first?