Can anyone see a way I can cut down the number of calls I make to a UKHO tides API? The API can either return a single tidal height for a specified datetime or an array of heights between start and end datetimes. I was expecting to do the former every 2 minutes (to get the current height) plus the latter once a day (so I can find when and for how long the tide goes below a threshold). As the number of API calls I’m allowed is limited, I realised that the single daily API call retruns an array containing all the minute-by-minute data I need to look up the current height during the day. My challenge is how to store it so a template can find the current height within the array.
Having read around the subject elsewhere I understand there is no such thing as an array sensor but I have seen reference to using attibutes to store elements. Can anyone give me guidance on how to do this?
The API that returns an array produces this (just 5 records, a full set would be around 1,000).
[{
"DateTime": "2024-01-19T14:30:00Z",
"Height": 4.402858
}, {
"DateTime": "2024-01-19T14:32:00Z",
"Height": 4.368262
}, {
"DateTime": "2024-01-19T14:34:00Z",
"Height": 4.333631
}, {
"DateTime": "2024-01-19T14:36:00Z",
"Height": 4.298977
}, {
"DateTime": "2024-01-19T14:38:00Z",
"Height": 4.264311
}]
I would expect the sensor to look something like (using the datetime as the attribute name):
sensor.UKtidesdata
attributes:
2024-01-19T14:30:00Z: 4.402858
2024-01-19T14:32:00Z: 4.368262
2024-01-19T14:34:00Z: 4.333631
2024-01-19T14:36:00Z: 4.298977
2024-01-19T14:38:00Z: 4.264311
Is this feasible or am I barking up the wrong tree?