Hi, I’m trying to capture data from a Restful API which has the format of
[
{ "key1": "value1", "key2": "value2" },
{ "key1": "value3", "key2": "value4" },
...
]
What I would ideally like is to capture the data into the attributes of a sensor, such that the attributes come out like this:
Data:
- key1: value1
key2: value2
- key1: value3
key2: value4
...
Unfortunately the Restful sensor just doesn’t seem to be set up to deal with a list, rather than a dictionary. I can use json_attributes to extract out the first entry of key1, key2 but it doesn’t progress through the json data and extract them all, nor put them into the desired structure.
I’ve tried to accomplish this via a python script, but can’t find how to make a restful api call from within the script (the environment doesn’t support import of requests, nor is it allowed to call_service). I can’t capture the full json object from the restful sensor - and then pass this into the python script to manipulate because the value_template of the sensor is limited to 255 characters.
In searching I’ve not found a simple answer, there appears to be ways to do this via ‘appdaemon’ and I know that various integrations and HACS custom_components accomplish this via more extensive python implementations (so there is definitely a way). However, it feels like there should be something pretty simple to do this - as if the raw json data was ever so slightly different to be a dictionary rather than a raw list it would be easy.
Any help or advice is much appreciated.
Thanks