Hello, I’ve just followed this tutorial for displaying time and temperature on an OLED display.
However the sensor values from HA don’t show up at all. If I move the printf
outside of the if
statement so it always gets displayed, I get a NaN
.
I thought that this might be an authentication issue, however the time
section is also fetched from the HA instance and that works fine.
I’m on the latest HA/ESPHome, I haven’t done anything specific than to add the 2 sensors from HA.
In order to debug, I’ve changed one of them to the random_reading
analog read sensor (pin not connected to anything, just noise). This shows up on the screen just fine.
However I’m unable to fetch any sensor information from HA to the ESP32.
I’ve tried this with multiple working sensors and two different HA instances - still nothing.
Full config:
esphome:
name: lcd-screen-test
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "rSYZvkwWTlLfwqhh/6cYPcNrukLejisZ1iOewApI+0o="
ota:
password: "61bd963f509796dfc6b2166ad2b3cddf"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Lcd-Screen-Test Fallback Hotspot"
password: "MC2M96jA5mBl"
captive_portal:
time:
- platform: homeassistant
id: esptime
sensor:
- platform: homeassistant
id: livingroom_temp
entity_id: sensor.temperature_livingroom
- platform: adc
pin: GPIO32
id: random_reading
update_interval: 1s
unit_of_measurement: "V"
font:
- file: 'fonts/slkscr.ttf'
id: font1
size: 8
- file: 'fonts/BebasNeue-Regular.ttf'
id: font2
size: 48
- file: 'fonts/arial.ttf'
id: font3
size: 14
i2c:
sda: GPIO21
scl: GPIO22
scan: false
display:
- platform: ssd1306_i2c
model: "SH1106 128x64"
address: 0x3C
lambda: |-
// Print "Mitt Smarta Hus" in top center.
it.printf(64, 0, id(font1), TextAlign::TOP_CENTER, "Please work");
// Print time in HH:MM format
it.strftime(0, 60, id(font2), TextAlign::BASELINE_LEFT, "%H:%M", id(esptime).now());
// Print inside temperature (from homeassistant sensor)
if (id(livingroom_temp).has_state()) {
it.printf(127, 23, id(font3), TextAlign::TOP_RIGHT , "%.1f°", id(livingroom_temp).state);
}
// Print outside temperature (from homeassistant sensor)
if (id(random_reading).has_state()) {
it.printf(127, 60, id(font3), TextAlign::BASELINE_RIGHT , "%.1f°", id(random_reading).state);
}
Here are my startup logs.
The only thing that I can see is that weird api.connection - Socket operation failed: CONNECTION_CLOSED
message.
Actual output:
Bottom right => Analog read value, correct.
Top Right => Nothing (or NaN
)