xti9
(Xti9)
September 9, 2023, 1:49pm
1
Hi all,
Need some help in parsing MQTT payload as shown below:
[{“i”:0.815095,“p”:52.37265,“f”:0.53942},{“i”:0.882872,“p”:-0.395224,“f”:-0.629938},{“i”:1.601247,“p”:0.843253,“f”:0.674454},{“i”:0.119281,“p”:-1.426369,“f”:-0.10039},{“i”:0.118915,“p”:-0.022139,“f”:-0.261984},{“i”:0.128542,“p”:0.034876,“f”:0.347481}]
I simply cannot get my head about how to parse, especially since the variable names are the same in the payload. Some assistance please on to crease a value_template to parse this!
thanks
tom_l
September 9, 2023, 4:10pm
2
For which value(s)?
Also please format your data correctly for the forum so it does not replace the quotes with invalid “fancy” ones.
There’s a handy tool here for finding paths to json data: https://jsonpathfinder.com/
xti9
(Xti9)
September 9, 2023, 6:11pm
3
I need to parse all the data.
tom_l
September 10, 2023, 4:01am
4
You did not format your data, so I had to do it for you. You’re not making this easy.
Using this data (see how the quotes are different?):
[{"i":0.815095,"p":52.37265,"f":0.53942},{"i":0.882872,"p":-0.395224,"f":-0.629938},{"i":1.601247,"p":0.843253,"f":0.674454},{"i":0.119281,"p":-1.426369,"f":-0.10039},{"i":0.118915,"p":-0.022139,"f":-0.261984},{"i":0.128542,"p":0.034876,"f":0.347481}]
And the website linked above gives you all the information you need. For example to create a sensor for the fourth p value:
You would use this value template in your sensor:
value_template: "{{ value_json[3].p }}"
You can make 18 separate sensors or you can put some of the values in attributes.
xti9
(Xti9)
September 10, 2023, 5:06am
5
Thank you! Yes that works. And apologies for the formatting. I need to learn how that’s done for the next time.