nukeman
(nukeman)
November 6, 2022, 12:03pm
1
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?
Lakini
November 6, 2022, 12:34pm
2
It took me a while to fully wrap my head around it, but in the end the arduinojson library does the trick for me:
Hi, yes in the end i have done this, i learned some basic of c++ and writed this progam for esphome:
Basically when you import attribute forecast in esphome the sensor contain a nested json that contain 5 days of forecast and condition and need to be deserialized,
ArduinoJson is a JSON library for Arduino, IoT, and any embedded C++ project. It supports JSON serialization, JSON deserialization, MessagePack, streams, and fixed memory allocation. It has a simple API, it’s easy to use, and it’s trusted by...
nukeman
(nukeman)
November 6, 2022, 1:39pm
3
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?
Lakini
November 6, 2022, 7:03pm
4
nukeman
(nukeman)
November 7, 2022, 9:16am
5
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.