SOLVED MAX7219 Brightness Control

I have setup an 4Ch. Thermometer with DS18B20 and 2 MAX7219 7Segment Boards.
I am trying to control the brightness of the 7Segments by using an value from a LDR-Sensor wich is on another esp. The LDR Sensor values are available in HA.
With an automation i would like to send this value to the max7219.

I have tried to make a sensor but ESPHOME gives me an error while compiling:

sensor:
  - platform: template
    name: "Pool Temp Display Brightness"
    id: "max7219_bright"
    filters:
      - calibrate_linear:
          - 0 -> 0
          - 1000 -> 15

spi:
  clk_pin: 14
  mosi_pin: 13

display:
  - platform: max7219
    cs_pin: 04
    num_chips: 2
    intensity: id(max7219_bright)   <<<-------------- THAT WONT WORK!
    lambda: |-
      it.printf(0, " ");
      it.printf(1, "%.1f", id(DS18B20_1).state);
      it.printf(4, " ");
      it.printf(5, "%.1f", id(DS18B20_2).state);
      it.printf(8, " ");
      it.printf(9, "%.1f", id(DS18B20_3).state);
      it.printf(12, " ");
      it.printf(13, "%.1f", id(DS18B20_4).state);

ESPHome Error:

Failed config

display.max7219: [source D:/Home-Assistant/pool_temp.yml:64]
  platform: max7219
  cs_pin: 4
  num_chips: 2

  Expected integer, but cannot parse id(max7219_bright) as an integer.
  intensity: id(max7219_bright) [source D:/Home-Assistant/pool_temp.yml:67]
  lambda: |-
    it.printf(0, " ");
    it.printf(1, "%.1f", id(DS18B20_1).state);
    it.printf(4, " ");
    it.printf(5, "%.1f", id(DS18B20_2).state);
    it.printf(8, " ");
    it.printf(9, "%.1f", id(DS18B20_3).state);
    it.printf(12, " ");
    it.printf(13, "%.1f", id(DS18B20_4).state);


Anyone an idea?

If you want to use the data from another sensor which is already available in HA you have to use the
- platform: homeassistant
see: Home Assistant Sensor — ESPHome and not - platform: template

and you can then set the intensity in the lambda where you also print the temperature by using:
it.set_intensity(id(max7219_bright).state); as described in MAX7219 7-Segment Display — ESPHome

Probably can’t calibrate it then but since it’s linear I believe you could use round(value/66.66666).
Not sure what the correct syntax in lambda is though.

thank you, now the brightness is always at full bright, because HA doesn’t send the value yet.
Here my code:

sensor:
  - platform: dallas
    address: 0xdc000005948d4d28
    name: "Temperature #1"
    id: "DS18B20_1"
  - platform: dallas
    address: 0xa800000593ec1d28
    name: "Temperature #2"
    id: "DS18B20_2"
  - platform: dallas
    address: 0x6f0000059411c728
    name: "Temperature #3"
    id: "DS18B20_3"
  - platform: dallas
    address: 0xf500000594396728
    name: "Temperature #4"
    id: "DS18B20_4"
  - platform: homeassistant
    name: "Pool Temp Display Brightness"
    id: "max7219_bright"
    entity_id: "sensor.max7219_bright"
    filters:
      - calibrate_linear:
          - 0 -> 0
          - 1000 -> 15

spi:
  clk_pin: 14
  mosi_pin: 13

display:
  - platform: max7219
    cs_pin: 04
    num_chips: 2
    intensity: 0
    lambda: |-
      it.set_intensity(id(max7219_bright).state);
      it.printf(0, " ");
      it.printf(1, "%.1f", id(DS18B20_1).state);
      it.printf(4, " ");
      it.printf(5, "%.1f", id(DS18B20_2).state);
      it.printf(8, " ");
      it.printf(9, "%.1f", id(DS18B20_3).state);
      it.printf(12, " ");
      it.printf(13, "%.1f", id(DS18B20_4).state);
           
           

What do i have to do so HA sends the value of sensor.light_sensor to sensor.pool_temp_display_brightness ?

At the moment the Value of sensor.pool_temp_display_brightness shows as “nAn”

change it to:

  - platform: homeassistant
    name: "Pool Temp Display Brightness"
    id: "max7219_bright"
    entity_id: "sensor.light_sensor"  # here is the change
    filters:
      - calibrate_linear:
          - 0 -> 0
          - 1000 -> 15

THAT way round? OK.
Changed it and WOW! it works!
Because the light is down now i tried it with the value of my swap-file :slight_smile: 189MB and the lights getting brighter! So the calibrate-filter works also! Gives me a value of 2.8.
Even the max7219 does only accept int-values from 0 (dark, not off!) to 15(full bright)
it runs with float-values too. Very good!

Thank you very much for helping!

one hint for using those max7219-7Segment Displays on a ESP:
It runs well with 3.3V but there is a safety-diode onboard, you must remove this and replace it with 0R resistor or a peace of wire! If more than one diplay is daisy-chained there will be too much voltage-loss!

Daysi chaned Displays