I’m preparing a Wattmeter by ESPHome to be shown in my Home Assistant. I’ve used a YAML example of a pulse meter to read the optical blinks from the meter.
The measured data shall be shown on a display, and sent to Home Assistant for the dashboard there. But the OLED display shows nothing.
Solved: The config param VCC: was True, shall be False. Appreciate your quick response Karosm
I keep the description here for lookup to anyone who’ll make a similar Wattmeter.
This worked properly first time when I connected it to an SHH1306 display. The intended data and graph was shown OK. And Home Assistant could pick up the data via WiFI.
Next, I prepared the same setup on a new site. I replaced the display to an SDD1306. (HW circuit is verified OK, see below)
In ESPHome the preparation of the display is the same for both, I just select the other model:
display:
- platform: ssd1306_i2c
model: “SSD1306_128x64”
# or:
model: “SH1106_128x64”
I tried “SDD1306 128x64” (Space vs _ ) and various pixel resolutions.
The HW is an ESP32dev 30p module and an OLED SD1306 display with I2C. The ESP32 is powered by 5v, and the display by 3v3 from the ESP32.
This HW has been used previously as a simple wattmeter, just showing data on the display. It was made by Arduino IDE code and has worked for a year or so. I reloaded this today and verified the display is OK.
Here’s the YAML code:
# ##############################################
# 3/2-2025 Wattmeter oppdatert med funksjoner for display
#
esphome:
name: wattmeter
platformio_options:
upload_speed: 115200
build_path: C:\Users\fredl\Documents\SmartHome\HASS\
esp32:
board: esp32dev
framework:
type: arduino
# Enable Home Assistant API
api:
password: "******"
ota:
- platform: esphome
password: "*****"
wifi:
ssid: "SSID"
password: "***"
manual_ip:
# Set this to the IP of the ESP
static_ip: 192.168.1.20
# Set this to the IP address of the router. Often ends with .1
gateway: 192.168.1.1
# The subnet of the network. 255.255.255.0 works for most home networks.
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
# ap:
captive_portal:
font:
- file: '.\arial\arial.ttf'
id: font1
size: 14
- file: '.\arial\arial.ttf'
id: font2
size: 18
i2c:
sda: 21
scl: 22
scan: true # default true
frequency: 500kHz #Default 50k, max 800k
timeout: 80ms # Default 50ms
sensor:
- platform: wifi_signal
name: "WiFi RSSI"
update_interval: 60s
# #################################
# Example configuration entry
- platform: pulse_meter
name: 'Electricity Usage'
id: sensor_pulse_meter1 # Optional ID, necessary if you want to calculate the total number of pulses.
unit_of_measurement: 'W'
device_class: power
state_class: measurement
internal_filter: 20ms # Assuming maximum load of 16 kW and 10000 impulses per kWh,
# any pulses faster than 22.5 ms would exceed load. -10% ~= 20 ms.
accuracy_decimals: 0
pin:
number: 16
mode:
input: true
pullup: false
filters:
- multiply: 30 # (60s / impulse constant) * (1000W / 1kW)
- throttle_average: 5s
- filter_out: NaN
time:
- platform: sntp
# ...
on_time:
# Every 1 minutes
- seconds: 15
minutes: /1
then:
- switch.toggle: blaa
################################
## OUTPUTS:
# Allow the onboard indicator to be controlled
switch:
- platform: gpio
name: "Blå LED"
#name: "Blue"
id: blaa
inverted: false
pin: 2 # Strapping pin, ok for indication output here. Use to pwr sensors
# Display power measured by large font to the left and a bargraph on right side
# Adjust for 6kW max, line indication per kW
# 64px vertikalt => 10px pr kW
display:
- platform: ssd1306_i2c
model: "SSD1306_128x64"
# model: "SH1106_128x64" !! Functionality of this code verified OK on this device
# reset_pin: D0
address: 0x3C
# id: my_oled
update_interval: 5s
external_vcc: true
# show_test_card: true
lambda: |-
/* Turn the whole display off */
it.fill(COLOR_OFF);
unsigned int Effekt, bar_h = 0;
Effekt = /* (unsigned int) */ id(sensor_pulse_meter1).state ;
it.line(0, 63, 127, 63); // Tegn strek i bunnen = 0Kw
it.line(105, 53, 127, 53); // Tegn strek for hver kW, 1 105 på forrige
it.line(105, 43, 127, 43); // Tegn strek for hver kW, 2
it.line(105, 33, 127, 33); // Tegn strek for hver kW ,3
it.line(105, 23, 127, 23); // Tegn strek for hver kW, 4
it.line( 95, 13, 127, 13); // Tegn strek for hver kW, 5
it.line(105, 3, 127, 3); // Tegn strek for hver kW, 6
it.printf(5, 32, id(font2), "%u", Effekt) ;
it.print(80,32, id(font2), "W") ; // Text ved øverste markering
if(Effekt>6000 ) Effekt = 6000;
// Blokk fra 108 til 125 på den gamle
Effekt = Effekt/100; // Ex: 63 - 1000w/100 = 53
bar_h = 63 - Effekt;
it.filled_rectangle(110, bar_h, 17, Effekt);
Serial.println(" Display info");
# End of block display
# Logger must be at least debug (default)
logger:
level: debug
At startup the debug info shows that the I2C scan succesfully found a device at 0x3C (as expected). The Serial.println(" Display info"); in the Lambda code prints out every 5s so this code is executed. But the display is totally black.
Further, reducing the I2C speed results in a timeout violation of I2C display communication, so apparently it “works”.
I noticed in the Arduino code this startup of the display:
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
Maybe: Is the ESPHome SW for SDD1306 missing the voltage stepup, contrary to the Arduino code which I prooved work for the display?
Anyone have an idea or example of a succesful SDD1306 in ESPHome?
Debug printout:
Hard resetting via RTS pin...
INFO Successfully uploaded program.
INFO Starting log output from COM4 with baud rate 115200
[17:03:35]0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[17:03:35]configsip: 0, SPIWP:0xee
[17:03:35]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[17:03:35]mode:DIO, clock div:2
[17:03:35]load:0x3fff0030,len:1184
[17:03:35]load:0x40078000,len:13132
[17:03:35]load:0x40080400,len:3036
[17:03:35]entry 0x400805e4
[17:03:35][I][logger:171]: Log initialized
[17:03:35][C][safe_mode:079]: There have been 2 suspected unsuccessful boot attempts
[17:03:35][D][esp32.preferences:114]: Saving 1 preferences to flash...
[17:03:35][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[17:03:35][I][app:029]: Running through setup()...
[17:03:35][I][i2c.arduino:218]: Performing I2C bus recovery
[17:03:35][C][switch.gpio:011]: Setting up GPIO Switch 'Blå LED/Fuktmålere påslått'...
[17:03:35][D][switch:016]: 'Blå LED/Fuktmålere påslått' Turning OFF.
[17:03:35][D][switch:055]: 'Blå LED/Fuktmålere påslått': Sending state OFF
[17:03:35][D][switch:016]: 'Blå LED/Fuktmålere påslått' Turning OFF.
[17:03:35][C][ssd1306_i2c:010]: Setting up I2C SSD1306...
[17:03:35][C][wifi:048]: Setting up WiFi...
[17:03:35][C][wifi:061]: Starting WiFi...
[17:03:35][C][wifi:062]: Local MAC: E0:5A:1B:5F:3B:84
[17:03:35][D][wifi:482]: Starting scan...
[17:03:35] Display info
[17:03:35][W][component:157]: Component wifi set Warning flag: scanning for networks
[17:03:39] Display info
[17:03:41][D][wifi:497]: Found networks:
[17:03:41][I][wifi:541]: - 'Fjellro' (00:22:07:55:88:DE) ▂▄▆█
[17:03:41][D][wifi:542]: Channel: 5
[17:03:41][D][wifi:543]: RSSI: -66 dB
[17:03:41][D][wifi:546]: - '' (FA:8F:CA:90:A1:DD) ▂▄▆█
[17:03:41][I][wifi:313]: WiFi Connecting to 'Fjellro'...
[17:03:42][I][wifi:617]: WiFi Connected!
[17:03:42][C][wifi:428]: Local MAC: E0:5A:1B:5F:3B:84
[17:03:42][C][wifi:433]: SSID: 'Fjellro'
[17:03:42][C][wifi:436]: IP Address: 192.168.1.20
[17:03:42][C][wifi:440]: BSSID: 00:22:07:55:88:DE
[17:03:42][C][wifi:441]: Hostname: 'wattmeter'
[17:03:42][C][wifi:443]: Signal strength: -69 dB ▂▄▆█
[17:03:42][C][wifi:447]: Channel: 5
[17:03:42][C][wifi:448]: Subnet: 255.255.255.0
[17:03:42][C][wifi:449]: Gateway: 192.168.1.1
[17:03:42][C][wifi:450]: DNS1: 0.0.0.0
[17:03:42][C][wifi:451]: DNS2: 0.0.0.0
[17:03:42][C][sntp:018]: Setting up SNTP...
[17:03:42][C][api:026]: Setting up Home Assistant API server...
[17:03:42][I][app:062]: setup() finished successfully!
[17:03:42][D][sensor:094]: 'WiFi RSSI': Sending state -69.00000 dBm with 0 decimals of accuracy
[17:03:42][W][component:170]: Component wifi cleared Warning flag
[17:03:42][W][component:157]: Component api set Warning flag: unspecified
[17:03:42][I][app:100]: ESPHome version 2025.2.1 compiled on Mar 4 2025, 17:02:14
[17:03:42][C][wifi:600]: WiFi:
[17:03:42][C][wifi:428]: Local MAC: E0:5A:1B:5F:3B:84
[17:03:42][C][wifi:433]: SSID: 'Fjellro'
[17:03:42][C][wifi:436]: IP Address: 192.168.1.20
[17:03:42][C][wifi:440]: BSSID: 00:22:07:55:88:DE
[17:03:42][C][wifi:441]: Hostname: 'wattmeter'
[17:03:42][C][wifi:443]: Signal strength: -68 dB ▂▄▆█
[17:03:42][C][wifi:447]: Channel: 5
[17:03:42][C][wifi:448]: Subnet: 255.255.255.0
[17:03:42][C][wifi:449]: Gateway: 192.168.1.1
[17:03:42][C][wifi:450]: DNS1: 0.0.0.0
[17:03:42][C][wifi:451]: DNS2: 0.0.0.0
[17:03:42][C][logger:177]: Logger:
[17:03:42][C][logger:178]: Max Level: DEBUG
[17:03:42][C][logger:179]: Initial Level: DEBUG
[17:03:42][C][logger:181]: Log Baud Rate: 115200
[17:03:42][C][logger:182]: Hardware UART: UART0
[17:03:42][C][i2c.arduino:071]: I2C Bus:
[17:03:42][C][i2c.arduino:072]: SDA Pin: GPIO21
[17:03:42][C][i2c.arduino:073]: SCL Pin: GPIO22
[17:03:42][C][i2c.arduino:074]: Frequency: 500000 Hz
[17:03:42][C][i2c.arduino:077]: Timeout: 80 ms
[17:03:42][C][i2c.arduino:086]: Recovery: bus successfully recovered
[17:03:42][I][i2c.arduino:096]: Results from i2c bus scan:
[17:03:42][I][i2c.arduino:102]: Found i2c device at address 0x3C
[17:03:42][C][switch.gpio:068]: GPIO Switch 'Blå LED/Fuktmålere påslått'
[17:03:42][C][switch.gpio:091]: Restore Mode: always OFF
[17:03:42][C][switch.gpio:031]: Pin: GPIO2
[17:03:42][C][pulse_meter:110]: Pulse Meter 'Electricity Usage'
[17:03:42][C][pulse_meter:110]: Device Class: 'power'
[17:03:42][C][pulse_meter:110]: State Class: 'measurement'
[17:03:42][C][pulse_meter:110]: Unit of Measurement: 'W'
[17:03:42][C][pulse_meter:110]: Accuracy Decimals: 0
[17:03:42][C][pulse_meter:110]: Icon: 'mdi:pulse'
[17:03:42][C][pulse_meter:111]: Pin: GPIO16
[17:03:42][C][pulse_meter:113]: Filtering rising edges less than 20000 µs apart
[17:03:42][C][pulse_meter:118]: Assuming 0 pulses/min after not receiving a pulse for 300s
[17:03:42][C][ssd1306_i2c:023]: I2C SSD1306
[17:03:42][C][ssd1306_i2c:023]: Rotations: 0 °
[17:03:42][C][ssd1306_i2c:023]: Dimensions: 128px x 64px
[17:03:42][C][ssd1306_i2c:024]: Address: 0x3C
[17:03:42][C][ssd1306_i2c:025]: Model: SSD1306 128x64
[17:03:42][C][ssd1306_i2c:027]: External VCC: YES
[17:03:42][C][ssd1306_i2c:028]: Flip X: YES
[17:03:42][C][ssd1306_i2c:029]: Flip Y: YES
[17:03:42][C][ssd1306_i2c:030]: Offset X: 0
[17:03:42][C][ssd1306_i2c:031]: Offset Y: 0
[17:03:42][C][ssd1306_i2c:032]: Inverted Color: NO
[17:03:42][C][ssd1306_i2c:033]: Update Interval: 5.0s
[17:03:42][C][captive_portal:089]: Captive Portal:
[17:03:42][C][sntp:042]: SNTP Time:
[17:03:42][C][sntp:045]: Server 0: '0.pool.ntp.org'
[17:03:42][C][sntp:045]: Server 1: '1.pool.ntp.org'
[17:03:42][C][sntp:045]: Server 2: '2.pool.ntp.org'
[17:03:42][C][mdns:116]: mDNS:
[17:03:42][C][mdns:117]: Hostname: wattmeter
[17:03:42][C][esphome.ota:073]: Over-The-Air updates:
[17:03:42][C][esphome.ota:074]: Address: 192.168.1.20:3232
[17:03:42][C][esphome.ota:075]: Version: 2
[17:03:42][C][esphome.ota:078]: Password configured
[17:03:42][C][safe_mode:018]: Safe Mode:
[17:03:42][C][safe_mode:020]: Boot considered successful after 60 seconds
[17:03:42][C][safe_mode:021]: Invoke after 10 boot attempts
[17:03:42][C][safe_mode:023]: Remain in safe mode for 300 seconds
[17:03:42][W][safe_mode:029]: Last reset occurred too quickly; safe mode will be invoked in 8 restarts
[17:03:42][C][api:140]: API Server:
[17:03:42][C][api:141]: Address: 192.168.1.20:6053
[17:03:42][C][api:145]: Using noise encryption: NO
[17:03:42][C][wifi_signal.sensor:010]: WiFi Signal 'WiFi RSSI'
[17:03:42][C][wifi_signal.sensor:010]: Device Class: 'signal_strength'
[17:03:42][C][wifi_signal.sensor:010]: State Class: 'measurement'
[17:03:42][C][wifi_signal.sensor:010]: Unit of Measurement: 'dBm'
[17:03:42][C][wifi_signal.sensor:010]: Accuracy Decimals: 0
[17:03:42][C][homeassistant.sensor:030]: Homeassistant Sensor 'effekten'
[17:03:42][C][homeassistant.sensor:030]: State Class: ''
[17:03:42][C][homeassistant.sensor:030]: Unit of Measurement: ''
[17:03:42][C][homeassistant.sensor:030]: Accuracy Decimals: 1
[17:03:42][C][homeassistant.sensor:031]: Entity ID: 'sensor.eff'
[17:03:44] Display info
[17:03:49] Display info