I’ve read a lot about parsing JSON here in the forums, but I am not clever enough to use it when it comes to a JSON that is returned from my solar inverter (it’s a SMA one and I know that there is a integration for it, but it does not help in my case because of (a) having two of them (which the integration cannot handle) and (b) not all values can be accessed using the integration, so I am trying the JSON thingy).
So this is the JSON object that is returned:
{"result":{"012A-B1234C12":{"6800_08822000":{"1":[{"validVals":[9366,9344,9345,9346],"val":[{"tag":9346}]}]},"6800_10821E00":{"1":[{"val":"STP6.0-3AV-40 364"}]},"6800_08811F00":{"1":[{"validVals":[1129,1130],"val":[{"tag":1129}]}]},"6180_08214800":{"1":[{"val":[{"tag":307}]}]},"6180_08414900":{"1":[{"val":[{"tag":886}]}]},"6180_08522F00":{"1":[{"val":[{"tag":308}]}]},"6800_088A2900":{"1":[{"validVals":[9327,9375,9376,9437],"val":[{"tag":9327}]}]},"6100_40463600":{"1":[{"val":3240}]},"6100_40463700":{"1":[{"val":0}]},"6100_40263F00":{"1":[{"val":3566}]},"6400_00260100":{"1":[{"val":8305376}]},"6800_00832A00":{"1":[{"low":6000,"high":6000,"val":6000}]},"6800_008AA200":{"1":[{"low":0,"high":null,"val":3004908683}]},"6400_00462500":{"1":[{"val":1277112}]},"6100_00418000":{"1":[{"val":null}]}}}}
Great. It’s even valid according to https://jsonlint.com/.
Now up to the next tool: https://jsonpath.curiousconcept.com/
I need to get the following values out of the JSON:
- $.result[‘012A-B1234C12’][‘6100_40263F00’][‘1’][‘0’][‘val’]
- $.result[‘012A-B1234C12’][‘6100_40463700’][‘1’][‘0’][‘val’]
- $.result[‘012A-B1234C12’][‘6100_40463600’][‘1’][‘0’][‘val’]
This works perfectly fine, but I have no idea how to use all that magic in https://www.home-assistant.io/integrations/rest/ (value_template, json_attributes, json_attributes_path etc).
Using no templating at all results in:
homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity id: sensor.sma_sunnyboy_storage. State max length is 255 characters.
Thanks in advance,
Torsten