Consuming weather data from a rest API in Home Assistant
With OpenWeatherMap's api 2.5 being deprecated I went to look for alternatives for the outdoor temperature.
Vlinder Project API permalink
Via a colleague I stumbled upon the Vlinder project. This citizen science project collects meteorological data in landscapes where we do not have information today. And lucky me, there is a station very close to my home. This means I don't have to buy, install and maintain another sensor for Home Assistant.
A GET
call to https://mooncake.ugent.be/api/stations
gives a list of all locations with their ID.
To get the weather data from that location you perform a GET
call to https://mooncake.ugent.be/api/measurements/ItzXCMYUzi31xyiEZpLxB7ef
with ItzXCMYUzi31xyiEZpLxB7ef
being the ID of the location.
This will return an array of measurements, the last one being the most recent one. I only listed two here for brevity's sake.
[
{
"humidity": 77,
"id": "ItzXCMYUzi31xyiEZpLxB7ef",
"measurements": "https://mooncake.ugent.be/api/measurements/ItzXCMYUzi31xyiEZpLxB7ef",
"pressure": 1005.38,
"rainIntensity": 0,
"rainVolume": 0,
"station": "https://mooncake.ugent.be/api/stations/ItzXCMYUzi31xyiEZpLxB7ef",
"status": "Ok",
"temp": 17.6,
"time": "Fri, 14 Jun 2024 15:25:00 UTC",
"windDirection": 275,
"windGust": 6.4,
"windSpeed": 2,
"wbgt": null
},
{
"humidity": 77,
"id": "ItzXCMYUzi31xyiEZpLxB7ef",
"measurements": "https://mooncake.ugent.be/api/measurements/ItzXCMYUzi31xyiEZpLxB7ef",
"pressure": 1005.38,
"rainIntensity": 0,
"rainVolume": 0,
"station": "https://mooncake.ugent.be/api/stations/ItzXCMYUzi31xyiEZpLxB7ef",
"status": "Ok",
"temp": 17.6,
"time": "Fri, 14 Jun 2024 15:30:00 UTC",
"windDirection": 275,
"windGust": 6.4,
"windSpeed": 2,
"wbgt": null
}
]
Home Assistant Rest Sensor permalink
In Home Assistant you can add sensors that poll a REST api quite easily. Getting the values from the last key proved to be somewhat tricky and only worked with this syntax: value_json[-1:][0].temp
rest:
resource: 'https://mooncake.ugent.be/api/measurements/ItzXCMYUzi31xyiEZpLxB7ef'
scan_interval: 300
sensor:
- name: 'Outdoor Temperature'
value_template: '{{ value_json[-1:][0].temp }}'
device_class: temperature
unit_of_measurement: '°C'
state_class: measurement
- name: 'Outdoor Humidity'
value_template: '{{ value_json[-1:][0].humidity }}'
device_class: humidity
unit_of_measurement: '%'
state_class: measurement
Then simply add the sensor and you're done!