Extract json from mqtt in Esphome

Hi. I have an mqtt sensor that has attribute values in json. I want to extract some of those values using a simple value_template along the lines of:

  - platform: mqtt_subscribe
    name: "x1_mqtt"
    id: x1_mqtt
    topic: x1/room/office
    value_template: '{{ value_json.distance }}'

It works fine in HA but apparently ESPHome doesn’t allow value templates. I get the error:

[value_template] is an invalid option for [text_sensor.mqtt_subscribe]. Please check the indentation.

Am I somehow supposed to use lambda for this?

It took me a while to fully wrap my head around it, but in the end the arduinojson library does the trick for me:

Thanks for the reply but I’m not really sure I can follow. Could you provide some example code so I can have a look?

meteo-thermostat/termostato-meteo.yaml at b43eba3bd5a0c8476e790acc44234194937e57c9 · niahane/meteo-thermostat · GitHub is the project from the linked thread, that was the one I used as an example for my stuff

Thanks. I’ve looked at the code but I can’t say I understand it. And with the very limited contextual knowledge I have of the whole weather thing I think I’ll have to find some other way around it. But thanks anyways.