Display MQTT JSON value on matrix LED max7219

Hi,

I try with no success to display on a matrix LED max7219 a JSON value from a MQTT topic.
My message is displayed in the logs. But I can’t display a part of this JSON message on my LED matrix.

The full JSON is displayed but I just want the value of PAPP : 400
My json looks like : ‘{“PAPP”:400,“IMAX1”:90}’

I try with lambda or text _sensor …

text_sensor:
  - platform: mqtt_subscribe
    name: "Data from topic"
    id: elec_value
    topic: my/topic
 
spi:
  clk_pin: 27
  mosi_pin: 26

display:
  - platform: max7219digit
    cs_pin: 14
    num_chips: 4
    intensity: 15
    lambda: |-
      if (id(mqtt_client).is_connected()) {
        it.printf(0, 4, id(digit_font), TextAlign::CENTER_LEFT, id(elec_value).state.c_str());
      }

Have you an idea ? thanks

Start simple, can you display anything on the display?

Like I said : The full JSON is displayed: ‘{“PAPP”:400,“IMAX1”:90}’
but I just want display the value of PAPP : 400
I try with on_json_message and subscribe_json but I think I don’t have the good synthaxe

Sorry I probably read too quickly. My JSON is crap, but this site may help Best JSON Parser Online [2022]

No problem for the Quick read.
But I don’t understand your answer.
I don’t need a online parser.
I need to parse the JSON message and the value of the PAPP key in the display block

Thanks

The online site can help you visualise your JSON data. That’s all. Mind you, yours is simple enough.

Looking at it I probably meant to point you here, sorry for the confusion. https://jsonpathfinder.com/

The path you are looking for is x.PAPP so (I think) something like the example for on_json_message. MQTT Client Component — ESPHome

How about if you create a sensor in HA, which contains the PAPP and then just display the sensors value in ESPHome?

sensor.yaml:

- platform: mqtt
  state_topic: 'my/topic'
  name: 'Data from topic'
  value_template: "{{ value_json.PAPP }}"

ESPHome:

text_sensor:
  - platform: homeassistant
    id: papp
    entity_id: sensor.data_from_topic
display:
  - platform: max7219digit
    cs_pin: 14
    num_chips: 4
    intensity: 15
    lambda:|-
      it.printf(0, 4, id(digit_font), TextAlign::CENTER_LEFT, id(papp).state.c_str());
2 Likes

Thanks !
I will try this.