UK Users - which weather integration do you use?

- resource: https://data.hub.api.metoffice.gov.uk/sitespecific/v0/point/hourly?datasource=BD1&includeLocationName=true&latitude=[LATITUDE]&longitude=[LONGITUDE]&excludeParameterMetadata=true
  headers:
    apikey: "YOUR_LONG_API_KEY"
  scan_interval: 3600
  sensor:
    - name: Datahub Hourly
      value_template: "{{ value_json['features'][0]['properties']['modelRunDate'] }}"
      json_attributes_path: $.features.0.properties
      json_attributes:
        - timeSeries

Then you can pull out the nearest “forecast” as the current weather into attributes of a sensor, and one example of pulling out one of those attributes into a sensor state:

template:
  - sensor:
      - name: Current weather
        state: >
          {% set tsl = state_attr('sensor.datahub_hourly','timeSeries')|map(attribute='time')|map('as_timestamp')|list %}
          {% set ts = tsl|select('>=',(now()-timedelta(minutes=30))|as_timestamp())|first %}
          {{ tsl.index(ts) }}
        attributes:
          status: "{{ state_attr('sensor.datahub_hourly','timeSeries')[this.state|int(0)] }}"

  - sensor:
      - name: Wind speed
        state: "{{ state_attr('sensor.current_weather','status')['windSpeed10m'] }}"
        unit_of_measurement: 'm/s'
        device_class: wind_speed
        attributes:
          timestamp: "{{ state_attr('sensor.current_weather','status')['time'] }}"

The state of sensor.current_weather is the index of the forecast block in the hourly Datahub sensor timeSeries list that is closest to the current time.

Use this macro to return a description for the significantWeatherCode:

[click to expand]
{% macro weather_code(x) -%}
{{ {
   0: "Clear night",
   1: "Sunny day",
   2: "Partly cloudy",
   3: "Partly cloudy",
   4: "Not used",
   5: "Mist",
   6: "Fog",
   7: "Cloudy",
   8: "Overcast",
   9: "Light rain shower",
   10: "Light rain shower",
   11: "Drizzle",
   12: "Light rain",
   13: "Heavy rain shower",
   14: "Heavy rain shower",
   15: "Heavy rain",
   16: "Sleet shower",
   17: "Sleet shower",
   18: "Sleet",
   19: "Hail shower",
   20: "Hail shower",
   21: "Hail",
   22: "Light snow shower",
   23: "Light snow shower",
   24: "Light snow",
   25: "Heavy snow shower",
   26: "Heavy snow shower",
   27: "Heavy snow",
   28: "Thunder shower",
   29: "Thunder shower",
   30: "Thunder"}.get(x, "n/a") -}}
{% endmacro %}

This doesn’t provide a weather object, though. Perhaps I need to learn how to create an integration.

2 Likes

@Troon So much better than what I came up with!

I created a sensor for the 1st in the array for each of hourly, 3-hourly, and daily and @Gen helped me make that more sensible with json_attributes_path: "$['features'][0]['properties']['timeSeries'][1]" but a long list of json_attributes.

I haven’t had time to do anything since, so here is one of the daily ones anyway and special thanks to @GEN who got me there…

daily data for tomorrow
rest:
  - resource: !secret met_office_datahub_daily
    scan_interval: 3600 #max
    headers:
      apikey: !secret met_office_datahub_apikey
    verify_ssl: false
    sensor:
      # timeSeries[x] x={0-7} selects day
      # note starting with [1] as this is consistent ([0] seems to lose entities as the day progresses)
      - name: MetOffice d1
        device_class: timestamp
        value_template: "{{ (value_json.features[0].properties.timeSeries[1].time |as_datetime )| as_local }}"
        json_attributes_path: "$['features'][0]['properties']['timeSeries'][1]"
        json_attributes:
          - time
          - midday10MWindSpeed
          - midnight10MWindSpeed
          - midday10MWindDirection
          - midnight10MWindDirection
          - midday10MWindGust
          - midnight10MWindGust
          - middayVisibility
          - midnightVisibility
          - middayRelativeHumidity
          - midnightRelativeHumidity
          - middayMslp
          - midnightMslp
          - maxUvIndex
          - daySignificantWeatherCode
          - nightSignificantWeatherCode
          - dayMaxScreenTemperature
          - nightMinScreenTemperature
          - dayUpperBoundMaxTemp
          - nightUpperBoundMinTemp
          - dayLowerBoundMaxTemp
          - nightLowerBoundMinTemp
          - dayMaxFeelsLikeTemp
          - nightMinFeelsLikeTemp
          - dayUpperBoundMaxFeelsLikeTemp
          - nightUpperBoundMinFeelsLikeTemp
          - dayLowerBoundMaxFeelsLikeTemp
          - nightLowerBoundMinFeelsLikeTemp
          - dayProbabilityOfPrecipitation
          - nightProbabilityOfPrecipitation
          - dayProbabilityOfSnow
          - nightProbabilityOfSnow
          - dayProbabilityOfHeavySnow
          - nightProbabilityOfHeavySnow
          - dayProbabilityOfRain
          - nightProbabilityOfRain
          - dayProbabilityOfHeavyRain
          - nightProbabilityOfHeavyRain
          - dayProbabilityOfHail
          - nightProbabilityOfHail
          - dayProbabilityOfSferics
          - nightProbabilityOfSferics

2024.2.2 released today brings back the Met office integration (haven’t upgraded to it yet though):

2024.2.2

4 Likes

Met office now working for me. But remind didn’t Met Office have a full 3 hourly weather entity? I now only have daily weather entity.

This is missing for me too

It did. A 3-hourly and a daily.

I now have a fully-working Template Weather entity using DataHub RESTful sensors and my own temperature sensor as the inputs.

I’ll share details next week when I have time…

3 Likes

Thanks fantastic! …looking forward to it!

1 Like

I definitely wait for them, hoping that your example will help me create mine😊

2 Likes

@Troon awesome - thanks!

I use the 3 hourly met office entity but is this still available? I’m using the met office intergration but on the intergration page it shows all the 3 hourly entities have been disabled.

Yes it is… but did you gather the weather service has changed? You need to create a template if you want to access the information below…

The documentation says the hourly and daily entity is now combined but not how to use it.
Anyone know the new syntax or location of info to replace
{{ state_attr(‘weather.met_office_chester_daily’, ‘forecast’)[0].condition }},
{{ state_attr(‘weather.met_office_chester_daily’, ‘forecast’)[1].condition }},
{{ state_attr(‘weather.met_office_chester_daily’, ‘forecast’)[2].condition }},
{{ state_attr(‘weather.met_office_chester_daily’, ‘forecast’)[3].condition }}
where "forecast’).condition where x used to give today tomorrow etc

Covered at length in various topics on here: the forecast attribute has been replaced with the get_forecasts() service. See the first example here:

You’ll need to set up a template sensor like this:

template:
  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.met_office_chester_daily
        response_variable: hourly
    sensor:
      - name: Temperature forecast next hour
        unique_id: temperature_forecast_next_hour
        state: "{{ hourly['weather.met_office_chester_daily'].forecast[0].temperature }}"
        unit_of_measurement: °C
        attributes:
          forecast: "{{ hourly['weather.met_office_chester_daily'].forecast }}"

Thank you so much. I snese your frustration but in my defence none of the links take you to the location you highlighted. Met Office Integation tells you nothing, the github page tells you little and the “Weather” link on the documentation for met office takes you back to met office. Maybe I should have thought of looking at the generic weather page so grateful for you adcive and code snippet. Thanks again

It was a change made in 2024.4: the forecast attribute had been “deprecated” (planned to remove) for a few months, then it happened. It’s buried under "Backward-incompatible changes on the release page:

image

It’s always worth reading through these before updating, although I do recognise that you might not always be able to identify a looming problem from the notes if you’re not that “techie”.

Thanks will keep an eyeout now on the release info.
I have sucessfully set up the template sensors and they report the next 4 days temps.
However I cant quite fogure out the templete to display it now.
Can I seek you indulgance one more time
The code to print the results was as below


  - alias: "Display "
    trigger:
      platform: state
      entity_id: input_boolean.display
      to: 'on'
    action:
      - service: notify.notify_lounge
        data:
          message: "Conditons for next 4 days"
      - service: notify.notify_lounge
        data:
          message: "Conditons for next 4 days
            {{ state_attr('weather.met_office_chester_daily', 'forecast')[0].condition }},
            {{ state_attr('weather.met_office_chester_daily', 'forecast')[1].condition }},
            {{ state_attr('weather.met_office_chester_daily', 'forecast')[2].condition }},
            {{ state_attr('weather.met_office_chester_daily', 'forecast')[3].condition }}"
      - service: input_boolean.turn_off
        entity_id: input_boolean.display_clouds

so for day [0] I tried
{{ state_attr(daily[‘weather.met_office_chester_daily’].forecast[0].temperature) }}
but in the template editor it says daily undefined.

You need to put the template sensor you’ve created in place of weather.met_office_chester_daily in your action template.

Perfect, Thanks
{{ states(‘sensor.temperature_forecast_day_0’) }}
did the trick :slight_smile: