Problem to write to display in on_value automation

Hallo,
I have an ESP32 board with a display SSD1306 128x64, a relay and a smart meter connected to it. The idea is to write the active power values transmitted by the smart meter’s optical interface to the display. But the display gets not updated at all. It still show’s the zero values from original display initialization.

Here is the crucial stuff:

`sensor:
  - platform: sml
    name: "Wirkleistung"
    id: actual_power
    sml_id: mysml
    obis_code: "1-0:16.7.0"
    unit_of_measurement: W
    accuracy_decimals: 1
    device_class: power
    state_class: measurement
    on_value:
      - lambda: |-
          id(my_display).printf(0, 32, id(roboto), "P: %10.1f kWh", x);`

All other stuff is working well:

  • connection to the smart meter
  • display the values in HomeAssistant
  • switching relay on/off as define by “on_value_range:”

Any ideas why the display does show the values?

Thanks
Viktor

Esphome configuration:

esphome:
  name: "smart-meter-relay"
  friendly_name: SmartMeterRelay

esp32:
  board: esp32dev
  framework:
    type: arduino

<<: !include ../base.yaml

i2c:
  sda: GPIO21
  scl: GPIO22
  frequency: 800kHz

font:
  - file: "gfonts://Roboto"
    id: roboto
    size: 14
  - file: 'slkscr.ttf'
    id: font1
    size: 8
  - file: 'BebasNeue-Regular.ttf'
    id: font2
    size: 48
  - file: 'arial.ttf'
    id: font3
    size: 14  

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3C
    rotation: 180
    id: my_display
    lambda: |-
      it.printf(0, 0, id(roboto), "V: %10.1f kWh", 0.0f);
      it.printf(0, 16, id(roboto), "E: %10.1f kWh", 0.0f );
      it.printf(0, 32, id(roboto), "P: %10.1f W", 0.0f);
      it.printf(0, 48, id(roboto), "Heizung: ein" );

uart:
  id: uart_bus
  rx_pin: GPIO16
  tx_pin: GPIO17
  rx_buffer_size: 512
  baud_rate: 9600
  data_bits: 8
  parity: NONE
  stop_bits: 1

sml:
  id: mysml
  uart_id: uart_bus

sensor:
  - platform: sml
    name: "Verbraucht"
    id: counter_out
    sml_id: mysml
    obis_code: "1-0:1.8.0"
    unit_of_measurement: kWh
    accuracy_decimals: 1
    device_class: energy
    state_class: total_increasing
    filters:
      - multiply: 0.0001
  - platform: sml
    name: "Eingespeist"
    id: counter_in
    sml_id: mysml
    obis_code: "1-0:2.8.0"
    unit_of_measurement: kWh
    accuracy_decimals: 1
    device_class: energy
    state_class: total_increasing
    filters:
      - multiply: 0.0001      
  - platform: sml
    name: "Wirkleistung"
    id: actual_power
    sml_id: mysml
    obis_code: "1-0:16.7.0"
    unit_of_measurement: W
    accuracy_decimals: 1
    device_class: power
    state_class: measurement  
    on_value:
      - lambda: |-
          id(my_display).printf(0, 32, id(roboto), "P: %10.1f kWh", x);
    on_value_range:          
      - below: 800    
        then:
          - switch.turn_on: heizung
      - above: 1000
        then:
          - switch.turn_off: heizung      
           
text_sensor:
  - platform: sml
    name: "Hersteller"
    sml_id: mysml
    obis_code: "1-0:96.50.1"
    format: text

switch:
  - platform: gpio
    pin: 4
    inverted: True
    id: heizung
    name: "Heizung"      

Log-Output:

INFO ESPHome 2023.11.6
INFO Reading configuration /config/esphome/smart-meter-relay.yaml...
INFO Starting log output from smart-meter-relay.local using esphome API
INFO Successfully connected to smart-meter-relay in 0.491s
INFO Successful handshake with smart-meter-relay in 0.105s
[18:16:37][I][app:102]: ESPHome version 2023.11.6 compiled on Dec 12 2023, 19:11:42
[18:16:37][C][wifi:559]: WiFi:
[18:16:37][C][wifi:391]:   Local MAC: C8:F0:9E:4E:E7:34
[18:16:37][C][wifi:396]:   SSID: 'Buehl-privat'[redacted]
[18:16:37][C][wifi:397]:   IP Address: 192.168.178.179
[18:16:37][C][wifi:399]:   BSSID: 98:9B:CB:34:2F:F3[redacted]
[18:16:37][C][wifi:400]:   Hostname: 'smart-meter-relay'
[18:16:37][C][wifi:402]:   Signal strength: -74 dB ▂▄▆█
[18:16:37][C][wifi:406]:   Channel: 6
[18:16:37][C][wifi:407]:   Subnet: 255.255.255.0
[18:16:37][C][wifi:408]:   Gateway: 192.168.178.1
[18:16:37][C][wifi:409]:   DNS1: 192.168.178.1
[18:16:37][C][wifi:410]:   DNS2: 0.0.0.0
[18:16:37][C][logger:416]: Logger:
[18:16:37][C][logger:417]:   Level: DEBUG
[18:16:37][C][logger:418]:   Log Baud Rate: 115200
[18:16:37][C][logger:420]:   Hardware UART: UART0
[18:16:37][C][i2c.arduino:053]: I2C Bus:
[18:16:37][C][i2c.arduino:054]:   SDA Pin: GPIO21
[18:16:37][C][i2c.arduino:055]:   SCL Pin: GPIO22
[18:16:37][C][i2c.arduino:056]:   Frequency: 800000 Hz
[18:16:37][C][i2c.arduino:059]:   Recovery: bus successfully recovered
[18:16:37][I][i2c.arduino:069]: Results from i2c bus scan:
[18:16:37][I][i2c.arduino:075]: Found i2c device at address 0x3C
[18:16:37][C][uart.arduino_esp32:124]: UART Bus 1:
[18:16:37][C][uart.arduino_esp32:125]:   TX Pin: GPIO17
[18:16:37][C][uart.arduino_esp32:126]:   RX Pin: GPIO16
[18:16:37][C][uart.arduino_esp32:128]:   RX Buffer Size: 512
[18:16:37][C][uart.arduino_esp32:130]:   Baud Rate: 9600 baud
[18:16:37][C][uart.arduino_esp32:131]:   Data Bits: 8
[18:16:37][C][uart.arduino_esp32:132]:   Parity: NONE
[18:16:37][C][uart.arduino_esp32:133]:   Stop bits: 1
[18:16:37][C][switch.gpio:068]: GPIO Switch 'Heizung'
[18:16:37][C][switch.gpio:076]:   Inverted: YES
[18:16:37][C][switch.gpio:091]:   Restore Mode: always OFF
[18:16:37][C][switch.gpio:031]:   Pin: GPIO4
[18:16:37][D][text_sensor:064]: 'Hersteller': Sending state 'LGZ'
[18:16:37][D][sensor:094]: 'Verbraucht': Sending state 6622.93750 kWh with 1 decimals of accuracy
[18:16:37][D][sensor:094]: 'Eingespeist': Sending state 0.00000 kWh with 1 decimals of accuracy
[18:16:37][D][sensor:094]: 'Wirkleistung': Sending state 444.00000 W with 1 decimals of accuracy
[18:16:37][D][sml:078]: OBIS info:
[18:16:37][D][sml:084]:   (0a014c475a0000000000) 1-0:96.50.1 [0x4c475a]
[18:16:37][D][sml:084]:   (0a014c475a0000000000) 1-0:96.1.0 [0x0a014c475a0000000000]
[18:16:37][D][sml:084]:   (0a014c475a0000000000) 1-0:1.8.0 [0x0000000003f29482]
[18:16:37][D][sml:084]:   (0a014c475a0000000000) 1-0:2.8.0 [0x0000000000000000]
[18:16:37][D][sml:084]:   (0a014c475a0000000000) 1-0:16.7.0 [0x00000000000001bc]
[18:16:37][W][component:214]: Component sml took a long time for an operation (0.09 s).
[18:16:37][W][component:215]: Components should block for at most 20-30ms.
[18:16:37][C][sml:104]: SML:
[18:16:37][C][sml_sensor:033]: SML 'Verbraucht'
[18:16:37][C][sml_sensor:033]:   Device Class: 'energy'
[18:16:37][C][sml_sensor:033]:   State Class: 'total_increasing'
[18:16:37][C][sml_sensor:033]:   Unit of Measurement: 'kWh'
[18:16:37][C][sml_sensor:033]:   Accuracy Decimals: 1
[18:16:37][C][sml_sensor:037]:   OBIS Code: 1-0:1.8.0
[18:16:37][C][sml_sensor:033]: SML 'Eingespeist'
[18:16:37][C][sml_sensor:033]:   Device Class: 'energy'
[18:16:37][C][sml_sensor:033]:   State Class: 'total_increasing'
[18:16:37][C][sml_sensor:033]:   Unit of Measurement: 'kWh'
[18:16:37][C][sml_sensor:033]:   Accuracy Decimals: 1
[18:16:37][C][sml_sensor:037]:   OBIS Code: 1-0:2.8.0
[18:16:37][C][sml_sensor:033]: SML 'Wirkleistung'
[18:16:37][C][sml_sensor:033]:   Device Class: 'power'
[18:16:37][C][sml_sensor:033]:   State Class: 'measurement'
[18:16:37][C][sml_sensor:033]:   Unit of Measurement: 'W'
[18:16:37][C][sml_sensor:033]:   Accuracy Decimals: 1
[18:16:37][C][sml_sensor:037]:   OBIS Code: 1-0:16.7.0
[18:16:37][C][sml_text_sensor:046]: SML 'Hersteller'
[18:16:37][C][sml_text_sensor:050]:   OBIS Code: 1-0:96.50.1
[18:16:37][C][ssd1306_i2c:023]: I2C SSD1306
[18:16:37][C][ssd1306_i2c:023]:   Rotations: 180 °
[18:16:37][C][ssd1306_i2c:023]:   Dimensions: 128px x 64px
[18:16:37][C][ssd1306_i2c:024]:   Address: 0x3C
[18:16:37][C][ssd1306_i2c:025]:   Model: SSD1306 128x64
[18:16:37][C][ssd1306_i2c:027]:   External VCC: NO
[18:16:37][C][ssd1306_i2c:028]:   Flip X: YES
[18:16:37][C][ssd1306_i2c:029]:   Flip Y: YES
[18:16:37][C][ssd1306_i2c:030]:   Offset X: 0
[18:16:37][C][ssd1306_i2c:031]:   Offset Y: 0
[18:16:37][C][ssd1306_i2c:032]:   Inverted Color: NO
[18:16:37][C][ssd1306_i2c:033]:   Update Interval: 1.0s
[18:16:37][C][captive_portal:088]: Captive Portal:
[18:16:37][C][mdns:115]: mDNS:
[18:16:37][C][mdns:116]:   Hostname: smart-meter-relay
[18:16:37][C][ota:097]: Over-The-Air Updates:
[18:16:37][C][ota:098]:   Address: smart-meter-relay.local:3232
[18:16:37][C][ota:101]:   Using Password.
[18:16:37][C][api:139]: API Server:
[18:16:37][C][api:140]:   Address: smart-meter-relay.local:6053
[18:16:37][C][api:142]:   Using noise encryption: YES
[18:16:38][D][text_sensor:064]: 'Hersteller': Sending state 'LGZ'
[18:16:38][D][sensor:094]: 'Verbraucht': Sending state 6622.93799 kWh with 1 decimals of accuracy
[18:16:38][D][sensor:094]: 'Eingespeist': Sending state 0.00000 kWh with 1 decimals of accuracy
[18:16:38][D][sensor:094]: 'Wirkleistung': Sending state 442.00000 W with 1 decimals of accuracy
[18:16:38][D][sml:078]: OBIS info:
[18:16:38][D][sml:084]:   (0a014c475a0000000000) 1-0:96.50.1 [0x4c475a]
[18:16:38][D][sml:084]:   (0a014c475a0000000000) 1-0:96.1.0 [0x0a014c475a0000000000]
[18:16:38][D][sml:084]:   (0a014c475a0000000000) 1-0:1.8.0 [0x0000000003f29483]
[18:16:38][D][sml:084]:   (0a014c475a0000000000) 1-0:2.8.0 [0x0000000000000000]
[18:16:38][D][sml:084]:   (0a014c475a0000000000) 1-0:16.7.0 [0x00000000000001ba]
[18:16:38][W][component:214]: Component sml took a long time for an operation (0.08 s).
[18:16:38][W][component:215]: Components should block for at most 20-30ms.
[18:16:39][D][text_sensor:064]: 'Hersteller': Sending state 'LGZ'
[18:16:39][D][sensor:094]: 'Verbraucht': Sending state 6622.93799 kWh with 1 decimals of accuracy
[18:16:39][D][sensor:094]: 'Eingespeist': Sending state 0.00000 kWh with 1 decimals of accuracy
[18:16:39][D][sensor:094]: 'Wirkleistung': Sending state 443.00000 W with 1 decimals of accuracy
[18:16:39][D][sml:078]: OBIS info:
[18:16:39][D][sml:084]:   (0a014c475a0000000000) 1-0:96.50.1 [0x4c475a]
[18:16:39][D][sml:084]:   (0a014c475a0000000000) 1-0:96.1.0 [0x0a014c475a0000000000]
[18:16:39][D][sml:084]:   (0a014c475a0000000000) 1-0:1.8.0 [0x0000000003f29484]
[18:16:39][D][sml:084]:   (0a014c475a0000000000) 1-0:2.8.0 [0x0000000000000000]
[18:16:39][D][sml:084]:   (0a014c475a0000000000) 1-0:16.7.0 [0x00000000000001bb]

Hi, i have s similar problem. But also no solution. My guess was it has something todo with the mysml blocking more then 30ms (see log message).
Best