ds1707
December 27, 2020, 11:10am
1
Hello guys,
This is the first time i am trying to implement sensors from a Restful APi.
Everything works, but now i have a question about the json_attributes.
Is it possible to add more json_attributes with different folders into one sensor?
This is a part of my json output:
{
"battery": {
"current": 0.0,
"voltage": 98.0
},
"doors_state": null,
"embedded": null,
"energy": [{
"autonomy": 96,
"charging": {
"chargingMode": "No",
"chargingRate": 0,
"nextDelayedTime": "PT10H",
"plugged": true,
"remainingTime": "PT0S",
"status": "Disconnected"
},
"level": 57,
"type": "Electric",
"updatedAt": "2020-12-24T13:34:30Z"
}
I would like to have all information in one sensor under attributes?
With different sensors per each json folder it works.
But i would like to have one sensor for all information:
- platform: rest
name: car_corsa_battery
json_attributes_path: "$."
json_attributes:
- battery.current
- battery.voltage
- energy.charging..chargingMode
resource: http://xxxxx
value_template: '{{ value_json.level }}'
BUt this does not work, i searched but i could not find a solution,
Thank you in advance!
ds1707
January 4, 2021, 1:37pm
2
Nobody here to help me?
The server allows only one request euch minute, thats why it would be cool to combine the json subfolders into one request.
vlycop
January 5, 2021, 10:27am
3
it seam to have a couple issue in this
- platform: rest
name: car_corsa_battery
#json_attributes_path: "$."
json_attributes:
- battery.current
- battery.voltage
- energy.charging.chargingMode
resource: http://xxxxx
value_template: '{{ value_json.energy.level }}'
To start, but not having ever try this, it may just not accept attribute in an object.
You could try with json_attributes_path: "$.battery"
and
json_attributes:
- current
- voltage
to see if it work.
ds1707
January 5, 2021, 11:30am
4
Thanks for your reply, that is the solution i have it already working.
But i wanted to have more attributes out of several sub folders, and i could not find a solution for that.
For example:
for the json of the first post i wanted to extract:
folder1: battery, attribute:current
folder1: battery, attribute:voltage
folder 4:energy, attribute:autonomy
folder 4:energy, attribute:level.
So information from to subfolders with one Restful request.
vlycop
January 5, 2021, 12:52pm
5
and it does not work on the one without typo I’ve send ?
Just wondering since i don’t have much to try it on
ds1707
January 5, 2021, 1:25pm
6
The second hint is the one i have running,
The first one is not working:
- platform: rest
name: car_corsa_battery
#json_attributes_path: "$."
json_attributes:
- battery.current
- battery.voltage
- energy.charging.chargingMode
resource: http://xxxxx
value_template: '{{ value_json.energy.level }}'
Wondering nobody faced the same problem before.
I spent a lot time searching for the solution but without success.
1 Like
Struggling with the same - it looks to be a limitation in the rest sensor.
Very annoying as workarounds are unnecessarily cumbersome.