ESPHome MAX7219 Matrix Display Code is not working

Hi

i want to display the time on my Display when both sensors are below a certain value. if one of the sensors reaches this value or goes higher i would like to display both sensors every 2 seconds the shown sensor should change. but only the time is shown :frowning:

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

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: traktor10


captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

web_server:
  port: 80

sensor:
  - platform: homeassistant
    id: ofen_temp1
    entity_id: sensor.bme280_temperature
    internal: true
  - platform: homeassistant
    id: ofen_temp2
    entity_id: sensor.gd_gewachshaus_temperature
    internal: true

text_sensor:
  - platform: homeassistant
    name: "Weather Forecast From Home Assistant"
    entity_id: input_text.max7219
    id: max7219
  - platform: wifi_info
    ip_address:
      name: ESP IP Address
      id: ip_address
    ssid:
      name: ESP Connected SSID
      id: ssid

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) or id(ofen_temp2)) < 10) {
        it.strftime(0, 4, id(digit_font), TextAlign::CENTER_LEFT, "%H:%M:%S", id(hass_time).now());
      }
      else if ((id(my_global_bool)) and (id(ofen_temp1) or id(ofen_temp2)) > 10) {
        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));
      }

# 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;
          }

#display:
#  - platform: max7219digit
#    cs_pin: D8
#    num_chips: 12
#    intensity: 9
#    lambda: |-
#      it.printf(0, 4, id(digit_font), TextAlign::CENTER_LEFT, "%s", id(max7219).state.c_str() );
#      it.scroll(true,1,100,1000,1000);

The if statement in the lambda is not give you what you want.

if ((id(ofen_temp1) or id(ofen_temp2)) < 10) {

I think what you want is

if ((id(ofen_temp1) <10 ) || (id(ofen_temp2)) < 10)) {

You need to do comparison on each value and then do the “or” (||) after.

And do similar on the if else.

/Mattias

1 Like