I apologize if this is a FAQ or something - I’ve been poking around a bit, and haven’t nailed down an answer, though my poking has gotten me to a point where I can ask a coherent question. I’m running HA 0.72.1, which I just updated to yesterday.
I’m adding a REST sensor, and the API I’m calling returns JSON - but it returns an array as a top-level object, and so I’m having trouble using json_attributes
, which I think I need to do to achieve what I want, which is to make one call to the API and then retrieve all the different info from the returned value.
Here’s an example return from the API:
[
{
"macAddress": "2C:3A:E8:FF:FF:FF",
"lastData": {
"dateutc": 1530724440000,
"winddir": 194,
"windspeedmph": 2.5,
"windgustmph": 4.5,
"maxdailygust": 5.8,
"tempf": 63.1,
"hourlyrainin": 0,
"dailyrainin": 0,
"weeklyrainin": 0,
"monthlyrainin": 0,
"totalrainin": 14.68,
"baromrelin": 29.7,
"baromabsin": 29.86,
"humidity": 67,
"tempinf": 68.5,
"humidityin": 54,
"uv": 2,
"solarradiation": 200.75,
"feelsLike": 63.1,
"dewPoint": 51.96056810981581,
"lastRain": "2018-05-23T05:59:00.000Z",
"date": "2018-07-04T17:14:00.000Z"
},
"info": {
"name": "MyStation",
"location": "Backyard"
}
}
]
I think it returns an array because I could have multiple weather stations, and [0] would be the first, [1] the second, etc. What I’d like is to be able to get lastData into a json_attribute so I can parse that in other sensors. I’ve tried this:
- platform: rest
resource: https://api.ambientweather.net/v1/devices?applicationKey=KEY_HERE&apiKey=OTHER_KEY_HERE
name: weather_station_report
json_attributes:
- [0]
scan_interval: 300
value_template: '{{ value_json[0].info.location }}'
… this doesn’t work; I get “JSON result was not a dictionary”. I’ve tried just
- platform: rest
resource: https://api.ambientweather.net/v1/devices?applicationKey=KEY_HERE&apiKey=OTHER_KEY_HERE
name: weather_station_report
json_attributes:
scan_interval: 300
value_template: '{{ value_json[0].info.location }}'
as well, but in this case, no attributes show up.
Hm. I’ve been banging my head against this for a few days now and I’d like some pointers - once I get the JSON into an attribute (in whatever form), I feel like the rest of what I want to do (not detailed here) is straightforward. (Also, in case it’s not obvious, it doesn’t work to have the JSON in the state, because it’s more than 255 chars).
Thanks in advance for any help.