I am attempting to create sensors from an API returning JSON. I’ve attempted to use all of the variations in the RESTful Sensor doc but I cant get any variation to work.
Goal: Create a sensor returning the stats of each item in [0], [1] and [2]
Payload:
[
{
"eid": 123,
"state": "enabled",
"measurementType": "production",
"phaseMode": "split",
"phaseCount": 2,
"meteringStatus": "normal",
"statusFlags": []
},
{
"eid": 456,
"state": "enabled",
"measurementType": "net-consumption",
"phaseMode": "split",
"phaseCount": 2,
"meteringStatus": "normal",
"statusFlags": []
},
{
"eid": 789,
"state": "enabled",
"measurementType": "storage",
"phaseMode": "split",
"phaseCount": 2,
"meteringStatus": "normal",
"statusFlags": []
}
]
Here is one example of what I tried.
sensor:
platform: rest
resource: https://127.0.0.1/ivp/meters
verify_ssl: false
headers:
Authorization: !secret api
Content-Type: application/json
json_attributes_path: "$."
json_attributes:
- eid
- state
- measurementType
- phaseMode
- phaseCount
- meteringStatus
name: "Meters"
value_template: "{{ value_json[0].state }}"
Even calling a specific item, nothing returns.
All I see in the log is REST result could not be parsed as JSON
Using JSONPath Online Evaluator, $.[0].state
returns as expected.
The payload above is exactly what is returned when using curl.
Any ideas on how to approach this?
Is there a way to see exactly what is being returned to home assistant?
Edit: Since there is no response so far, I’ll post things I learn along the way trying to figure it out.