ESPHome and MAX7219

I am trying to get the MAX7219 to do what I want, but without succes.

I want to display a text when the doorbell is ringing and I am home. The part that is not working:

binary_sensor:    
  - platform: homeassistant
    name: "i-am-coming"
    id: coming
    entity_id: input_boolean.coming
    internal: true

display:
  - platform: max7219digit
    cs_pin: GPIO15
    num_chips: 8
    intensity: 5
    lambda: |-
      if (id(coming).state) {
        it.turn_on_off(true); 
        it.print(2,0, id(pixelmix8), "I am Coming!");
      } else{
        it.turn_on_off(false);
      }

When I only use the it.print and not the if-else then the text is displayed. But with the if-else statements it is not responding to any changes in the input_boolean.coming from home assistant. The display stays blank. What am I doing wrong?

Maybe I should be lambda like this:
lambda: ! lambda | -

Did you add the device as an integration in HA? And can you post your complete yaml and the log from the device?

You can also add the following line to the lambda above the if statement, to see the value of the binary sensor you are testing in the if.

    lambda: |-
      ESP_LOGD("display", "Value coming: %d", id(coming).state);
      if (id(coming).state) {

How stupid of me! I didn’t add the device as an Integration. Now it is working!
And also thanks for the tip to add a line so you can see in the logs what happens.

Many thanks Jos!

Hello Gert,
Your funtion for your doorbel should help me to use a max7219 dotmatrix.
So I copied your xxx.yaml file into my esphome xx.yaml file and uploaded it.
error could not find pixelmix8???
It is a great help if you can explain howe you arranged your pixelmix8 file font?
Like to hear.

Theo

ps. the example max7219 7 segment seems like to work. Some leds are light up at least the combination esp wemos d1 print and matrix are working and integrated in HA

Hallo Gert,

INFO Reading configuration /config/esphome/max.yaml…
Failed config

font: [source /config/esphome/max.yaml:39]

  • [source /config/esphome/max.yaml:40]

    Could not find file ‘/local/pixelmix8.ttf’. Please make sure it exists (full path: /local/pixelmix8.ttf).
    file: /local/pixelmix8.ttf [source /config/esphome/max.yaml:40]
    id: pixelmix8

This is the log.

Hallo Gert,

‘utf-8’ codec can’t decode byte 0x80 in position 7: invalid start byte

This error if I,am arranging the pixelmix.ttf file in the folder.
btw this happends always no matther what I try?
Where am I going wrong?

Here is the complete file:

# LED MAX7219 display via ESP32 "Kom er aan!"

# This configuration is for the ESP-WROOM-32D board.

# with ESP32_DEVKITC_V4 on the back

#

esphome:

  name: matrix-led

esp32:

  board: nodemcu-32s #esp32doit-devkit-v1

wifi:

  ssid: "<name>"

  password: "<password>"

  # Enable fallback hotspot (captive portal) in case wifi connection fails

  ap:

    ssid: "Matrix-Led Fallback Hotspot"

    password: "<password>"

captive_portal:

logger:

ota:

  password: "<password>"

# Enable Home Assistant API

api:

  encryption:

    key: "<key>"

spi:

  clk_pin: GPIO18

  mosi_pin: GPIO23

font:

  - file: "pixelmix.ttf"

    id: pixelmix8

    size: 8

  - file: "Helvetica.ttf"

    id: helvetica_60

    size: 60

  - file: "Helvetica.ttf"

    id: helvetica_48

    size: 48

  - file: "Helvetica.ttf"

    id: helvetica_24

    size: 24

  - file: "Helvetica.ttf"

    id: helvetica_12

    size: 12

 

binary_sensor:    

  - platform: homeassistant

    name: "i-am-coming"

    id: iamcoming

    entity_id: input_boolean.coming

    internal: true

   

display:

  - platform: max7219digit

    cs_pin: GPIO0

    num_chips: 8

    intensity: 5

    lambda: |-

      it.turn_on_off(true);

      if (id(iamcoming).state) {

        it.print(2, 0, id(pixelmix8), "Kom er aan!");

      } else{

        it.turn_on_off(false);

      }

The pixelmix.ttf and other ttf files are in the directory /config/esphome/.