Hi!
I’m trying to create a template sensor based on a MQTT server topic.
It contains a malformed JSON string, like the one below:
{"SerialReceived":"{"circ":[0,0,0,-9,-9,-9,-9,-9,-9],"circdm":[-9,-9,-9],"ventdm":[-9],"vent":[0],"DHT":[25,86.5,0,0,26.16333]}"}
With this sensor I can extract the valid JSON part:
sensor:
- platform: mqtt
name: "result_serial"
state_topic: "tele/sonoff/RESULT"
value_template: '{{ value|regex_replace(find="{\"SerialReceived\":\"", replace="",ignorecase=False)|regex_replace(find="\"}", replace="",ignorecase=False) }}'
The problem is that sensor.result_serial is string, not a JSON, for HASS. How can I convert this new string to a JSON? I’ve tried {{ value_json|… in place of {{ value|… but it seems that the malformed string should be fixed before converting it.
PD: the whole part is an Arduino Nano that prints on serial the “good” JSON part. A ESP-01 with Sonoff Tasmota firmware acts like a serial MQTT bridge, receiving the JSON on serial and sending the string on a MQTT topic, adding “SerialReceived” on the beginning, but breaking the JSON.
Thanks in advance!