I am trying to pull hydrometric data in a near real-time fashion. The data is maintained by Environment Canada and made available via an api key and calls to a web site.
I use the following url to request data:
https://vps267042.vps.ovh.ca/scrapi/station/08LE070/primarylevel/?startDate=2023-05-30&endDate=2023-05-30&resultType=history&key={my secret key}
If you want to try this, you can get a free key at Water Data API | Open Government, Government of Canada
when I submit this request in a browser, I receive data that looks like the following:
{“code”:200,“details”:“Water Level and Flow - Environment Canada 00:00:00”,“value”:“348.448”},{“date”:“2023-05-30 00:05:00”,“value”:“348.448”},{“date”:“2023-05-30 00:10:00”,“value”:“348.450”},{“date”:“2023-05-30 00:15:00”,“value”:“348.450”},{“date”:“2023-05-30 00:20:00”,“value”:“348.450”},{“date”:“2023-05-30 00:25:00”,“value”:“348.449”},{“date”:“2023-05-30 00:30:00”,“value”:“348.449”},{“date”:“2023-05-30 00:35:00”,“value”:“348.448”},
- lots of records omitted -
{“date”:“2023-05-30 20:15:00”,“value”:“348.441”},{“date”:“2023-05-30 20:20:00”,“value”:“348.438”}]}}
Every 5 minutes another record is added.
The value is the number of metres above sea level for the Shuswap lake in Sicamous BC (Canada). It might change by 3-5 metres some years. From very low (so I get a lot of beach) to flood conditions (so I might need to take some corrective actions). This lake (and my cabin) are about a 6 hour drive from home - so I want to monitor it remotely. Fortunately we have a government agency that provides very accurate measurements (every 5 minutes) - and provides it as shown above.
The api limits me to 200 calls per day, and given that lake levels don’t change that fast, I might pull the data once an hour - so 200 is more than enough.
I will want to get the last record provided (the “date” and the “value”) with each call
From the URL, you will see that I need to enter a start and end date (so I’ll need to create the URL programmatically) - and all I know is that I need to extract the last record in the file each time.
This is all different than everything I’ve done in HA so far. My initial questions are:
- How do I pull down the data (REST?) - I’ve never done this and it looks a bit complex to me.
- how do I extract just the last record - I assume into a sensor?
- Should I be using the json parsing capability? (and how)
- How do I best manage some history (I know HA automatically will keep history of entities - should I use that or should I manage some history on my own?)
My objective is to take these lake levels, and coupled with other historical data, calculate the amount of beach in front of my cabin. I will want some history as well - as I would also present information like - change in last 24 hours, change in last week, to indicate if the lake going up or down (and how fast) , has it peaked, etc.
Any thoughts on how best to approach this?
thanks,
Ken