Can t find error in Lambda Logic

Hi
i have a problem with the following code, and i can not find the root cause why the code i not working. maybe someone have an idea

substitutions:
  device_name: max7219_2
  #device_description: Display für Temperatur
  #friendly_name: max7219_2

esphome:
  name: ${device_name}
  #comment: ${device_description}
  platform: ESP8266
  board: d1_mini
  #arduino_version: 2.4.2

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: on #we only have one WiFi AP so just use the first one that matches
  ap: #since we listed an SSID above, this AP mode will only enable if no WiFi connection could be made
    ssid: ${friendly_name}_AP
    password: my_pw


captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

web_server:
  port: 80

sensor:
  - platform: homeassistant
    id: ofen_temp1
    entity_id: sensor.netatmo_wohnhaus_wohnzimmer_temperature
    internal: true
  - platform: homeassistant
    id: ofen_temp2
    entity_id: sensor.netatmo_wohnhaus_wohnzimmer_aussen_temperature
    internal: true


time:
  - platform: homeassistant
    id: hass_time

font:
  - file: "pixelmix.ttf"
    id: digit_font
    size: 8

globals:
  - id: my_global_bool
    type: bool
    restore_value: no
    initial_value: 'true'

spi:
  clk_pin: D5
  mosi_pin: D7


display:
  - platform: max7219digit
    cs_pin: D8
    num_chips: 12
    intensity: 9
    lambda: |-
      if (id(ofen_temp1).state < 40 || id(ofen_temp2).state < 40) {
        it.strftime(0, 4, id(digit_font), TextAlign::CENTER, "%A %d. %B %Y %H:%M:%S", id(hass_time).now());
      }
      else if ((id(my_global_bool)) && (id(ofen_temp1).state > 40 || id(ofen_temp2).state > 40)) {
        it.printf(0, 4, id(digit_font), TextAlign::CENTER, "Temp-O: %.1f°C",  (id(ofen_temp1).state));
      }
      else {
        it.printf(0, 4, id(digit_font), TextAlign::CENTER_LEFT, "Temp-U: %.1f°C",  (id(ofen_temp2).state));
      }
    #lambda: |-
    #    it.printf(0, 4, id(digit_font), TextAlign::CENTER_LEFT, "Holzofen: %.1f°C",  (id(ofen_temp1).state));
    #    it.scroll(true,1,100,1000,1000);
# For example cycle through pages on a timer
interval:
  - interval: 2s
    then:
      - lambda: |-
          if (id(my_global_bool)) {
            id(my_global_bool) = false;
          }
          else {
            id(my_global_bool) = true;
          }



Not sure, if I understand the code correctly, but most likely you should change this line:

to
it.printf(0, 4… ).

No logs, no issue.

I have similar problems quite often, too, since i’ only beginner programmer. The point is that esphome’s compiler is pretty soon ‘quite happy’ with lambda code, but code itself is not correct, so it doesn’t work in real world.
Is there any “thing” where this code coudl be tested (similar like developer tools for yaml)?

1 Like