I have recently moved to the new official Met Office integration (previously using the method which was helpfully documented in this thread: Template weather provider from UK Met Office DataHub API)
I am using a trigger template to periodically retrieve forecast data as two sensors:
template:
# template for UK met hourly weather forecast
- trigger:
- platform: time_pattern
minutes: /1
action:
- service: weather.get_forecasts
data:
type: hourly
target:
entity_id: weather.met_office_my_location
response_variable: met_hourly_forecast
- service: weather.get_forecasts
data:
type: daily
target:
entity_id: weather.met_office_my_location
response_variable: met_daily_forecast
sensor:
- name: met_hourly_forecast
unique_id: met_hourly_forecast
icon: mdi:weather-partly-cloudy
state: "{{ now() }}"
attributes:
forecast: "{{ met_hourly_forecast['weather.met_office_my_location'].forecast|to_json}}"
- name: met_daily_forecast
unique_id: met_daily_forecast
icon: mdi:weather-partly-cloudy
state: "{{ now() }}"
attributes:
forecast: "{{ met_daily_forecast['weather.met_office_my_location'].forecast|to_json}}"
I found that I had to use the “to_json” filter to get valid double quoted json which I can parse in the applications consuming the data via the HA API.
I was able to retrieve and parse the forecast data successfully for both sensors, but have encountered a problem where the hourly forecast returned by the template is periodically throwing errors when it is consumed because the format has changed. For example, I am using the sensors in a python application, and the forecast attribute for both sensors is usually returned as a string, which I can parse and load as an object using json.loads. The daily forecast works consistently, but the hourly forecast periodically starts returning a list instead of a string, causing the parsing to fail.
I can see the effect when I examine the sensor attributes in HA - the daily forecast is displayed as a valid json string, the hourly forecast in list form:
Daily:
[{"datetime":"2026-01-19T00:00:00+00:00","condition":"sunny","precipitation":null,"precipitation_probability":4,"uv_index":1,"wind_bearing":150,"temperature":6.7,"apparent_temperature":5.5,"templow":2.6,"pressure":1012.2,"wind_gust_speed":11.16,"wind_speed":5.4},{"datetime":"2026-01-20T00:00:00+00:00","condition":"partlycloudy","precipitation":null,"precipitation_probability":4,"uv_index":1,"wind_bearing":113,"temperature":8.5,"apparent_temperature":5.4,"templow":4.4,"pressure":1007.81,"wind_gust_speed":23.8,"wind_speed":12.31},{"datetime":"2026-01-21T00:00:00+00:00","condition":"rainy","precipitation":null,"precipitation_probability":79,...etc
Hourly:
- datetime: '2026-01-19T12:00:00+00:00' condition: sunny precipitation: 0 precipitation_probability: 0 uv_index: 1 wind_bearing: 31 temperature: 5.3 apparent_temperature: 4.3 pressure: 1012.62 wind_gust_speed: 7.78 wind_speed: 6.48 - datetime: '2026-01-19T13:00:00+00:00' condition: sunny precipitation: 0… etc
This problem is occurring intermittently. Both forecasts were returning JSON successfully but the hourly forecast changed to list format last night. This morning, both forecasts were back to JSON, but the hourly forecast has just switched to a list again.
I assume there is something being included in the format or values of the hourly data that is intermittently causing an issue when the template runs to update the sensors. I’ve gone back to the Met Office dev API tool to test the calls, and the hourly data looks valid.
The only thing that looks a bit suspect is
"precipitation": null
in the daily feed, but that doesn’t seem to be causing any problems with this forecast.
Has anyone else experienced something similar, or can suggest why I am getting this problem, please?