Updating brightness on Matrix Display from HA

Hey everyone,

I’m trying to be able to set the brightness of a matrix display I’m using remotely, from Home Assistant.

Here’s the config I have:

number:
  - platform: template
    name: "Matrix Display Brightness"
    id: max7219_bright
    update_interval: never
    initial_value: 1
    min_value: 0
    max_value: 15
    step: 1
    optimistic: true

text_sensor:
  - platform: mqtt_subscribe
    name: "Data from topic"
    id: elec_value
    topic: display/display8266
 
spi:
  clk_pin: D5
  mosi_pin: D7

display:
  - platform: max7219digit
    cs_pin: D4
    num_chips: 8
    #intensity: 1
    lambda: |-
      if (id(mqtt_client)->is_connected()) {
        int to_set = (int) id(max7219_bright).state;
        it.set_intensity(to_set);
        it.printf(0, 4, id(digit_font), TextAlign::CENTER_LEFT, id(elec_value).state.c_str());
      }

While the text is updating when I publish something to the mqtt topic, unfortunately the brightness is not updating. I had a feeling that this is due to the max7219_bright value being a float rather than int as expected, hence me trying to convert it within the lambda.

When I set the value in HA, I see corresponding logging:

[18:33:58][D][text_sensor:067]: ‘Data from topic’: Sending state ‘X1C Humidity: 39.19…’
[18:34:02][D][number:054]: ‘Matrix Display Brightness’ - Setting number value
[18:34:02][D][number:113]: New number value: 1.000000
[18:34:02][D][number:012]: ‘Matrix Display Brightness’: Sending state 1.000000

Anyone got an idea / suggestion how I can make this work? Sorry if I’m being stupid and thanks in advance for your help :slight_smile: :grinning:

I think it should be it.intensity not it.set_intensity