Pretty new to RESTful sensors and also JSON for that matter… I am trying to create a sensor to get high/low tide times and heights using the Storm Glass API https://stormglass.io/. The difficulty is that the two high and two low tides each day are described in JSON with keys of the same name. The API call returns:
{
"extremes":[
{
"height":-0.030679245283018908,
"timestamp":"2019-05-14 03:35:52+00:00",
"type":"low"
},
{
"height":1.469320754716981,
"timestamp":"2019-05-14 09:54:05+00:00",
"type":"high"
},
{
"height":0.08932075471698109,
"timestamp":"2019-05-14 15:58:19+00:00",
"type":"low"
},
{
"height":1.639320754716981,
"timestamp":"2019-05-14 22:12:32+00:00",
"type":"high"
}
],
"meta":{
"cost":1,
"dailyQuota":50,
"end":"2019-05-15 00:00",
"lat":27.7621,
"lng":-15.5644,
"requestCount":4,
"start":"2019-05-14 00:00",
"station":{
"distance":41,
"lat":28.1,
"lng":-15.4,
"name":"las palmas",
"source":"UHSLC"
}
}
}
The values I care about are tied to the height
, timestamp
and type
keys under extremes
.
This sensor definition…
# Maspalomas tides
- platform: rest
name: Masplomas Tides
resource: "https://api.stormglass.io/v1/tide/extremes/point?lat=27.8&lng=-15.6&start=2019-05-14&end=2019-05-15"
headers:
Authorization: !secret storm_glass_key
json_attributes:
- extremes
- meta
value_template: '{{ value_json.tides }}'
scan_interval: 14400
…results in,
…where the different key/value pairs under
extremes
are not captured.
Any suggestions as to how to get the two high and two low tide data sets each day?
Thanks!