Met.no hourly forecast entity not available in latest HA

The only entity available from the met.no integration is weather.forecast_home, there is no other entity created, however it seems the hourly forecast data is available, because I can display it with the forecast_type=hourly in lovelace.

My goal is to get the hourly forecast on an e-ink and therefore I need to get access to the data, I could not find an api call or entity that returns the data. Checking github issues or this forum yields some suggestions with a second _hourly entity however that is not present in my HA, restarting HA and reinstalling met.no did not help either.

Home Assistant 2023.9.2
Supervisor 2023.09.2
Operating System 10.5
Frontend 20230911.0 - latest

Create sensors for each hour.
Change the weather entity to your own.

template:
  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecast
        target:
          entity_id: weather.forecast_testy
        data:
          type: hourly
        response_variable: forecast
    sensor:
      - name: Počasí teplota hodinově 1
        unique_id: teplota_pocasi_hodina_1
        state: "{{ forecast.forecast[0].temperature }}"
      - name: Počasí teplota hodinově 2
        unique_id: teplota_pocasi_hodina_2
        state: "{{ forecast.forecast[1].temperature }}"
      - name: Počasí teplota hodinově 3
        unique_id: teplota_pocasi_hodina_3
        state: "{{ forecast.forecast[2].temperature }}"
        ................................
        .................
1 Like

thanks, for reference, this is because of the following change: 2023.9: New climate entity dialogs, lots of tile features, and template sensors from the UI! - Home Assistant

the proper way is indeed to call the get_forecast service as also described in Template - Home Assistant

Hello Pepe59,

I can’t get this to work. Do I have to copy the code from you into a template helper or into the configuration YAML. I always get the message that forecast is not defined.

Tanks

The attribute is no longer the right way to do it, as explained in the post above yours. You should now call a service to get the hourly forecast.

1 Like

Danke, aber wie kann ich dann auf die stündlichen Werte zugreifen.

Thanks, but how can I then access the hourly values.

same question here…
I can run the service, but how can I get the data into a weather entity with the hourly values?

now I got a solution.
this is the point:

here an example code from the link:

template:
  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecast
        data:
          type: hourly
        target:
          entity_id: weather.home
        response_variable: hourly
    sensor:
      - name: Weather Forecast Hourly
        unique_id: weather_forecast_hourly
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: "{{ hourly.forecast }}"

Does this work in the latest HA? I tried the same template (with my met.no sensor name) but it does not work.
Running it in dev tools returns “‘hourly’ is undefined”.

I’m just looking for the hourly forecast in a similar way it was previously available in a separate sensor.

That was last month.
weather.get_forecast has changed to weather.get_forecasts

At the time of writing, the following config is now working for me

template:
###### to call weather forecast service to get hourly into a new entity Dec 2023 #####
  - trigger:
      - platform: time_pattern
        hours: "/1"
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.forecast_home
        response_variable: hourlyforecast
    sensor:
      - name: "Forecast Home Hourly"
        unique_id: bis202312041810
        icon: mdi:weather-cloudy-clock
        state: "{{ now().isoformat() }}"
        attributes:
          forecast: "{{ hourlyforecast['weather.forecast_home']['forecast'] }}"

The new call now returns a list of forecasts, and the id contains a ‘.’, hence the need for the more complex [ - ] referencing to get at the values.

Hope this helps

5 Likes

Thank you, I’ve got it working now. I’m sure there’s a good reason for the change, but for this specific case it made things unnecessarily complicated just to get the forecast.

1 Like

I still get “hourlyforecast” undefined when I try the template in developer tools. I guess I am missing something basic.

This is my exact code that works on the latest HASS.io install, hope it helps.

template:
  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      service: weather.get_forecasts
      data:
        type: hourly
      target:
        entity_id: weather.forecast_home
      response_variable: forecast_data
    sensor:
      name: Weather Forecast Hourly
      state: "{{ forecast_data['weather.forecast_home'].forecast[0].temperature }}"
      attributes:
        forecast: "{{ forecast_data['weather.forecast_home'].forecast }}"
        updatedAt: "{{ now().isoformat() }}"

Thank you. When I copy the code to the template checker in developer tools I get “forecast_data” undefined.

When I run the service in developer tool I can see that all information is there.

Edit: After awhile, it seems that it works.

Just a note to all of you (or my future self that rediscovers this thread) -

When you edit your YAML files and add the trigger/sensors, they refresh at the top of the hour. Put differently - if you add the sensor and then restart HA don’t expect it to populate hourly forecast data until the top of the hour if your hours value is set to /1.

After troubleshooting this and finally putting it down in frustration I came back after the top of the our and BOOM there are the values.

You could add a trigger to also call it when HA restarts:-

trigger:
  - platform: homeassistant
    event: start
1 Like

How do i use hourly forecast data in a jninja2 template, without creation of a template entity?

Use case is the forecast data is used in jninja2 in markdown cards on dashboard pages.

this works for me in HA 2024.2.5

|Time|Cond|Temp|Windspd|dir|precip|humidity|cloud%|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
{%set direction = ['N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW','N']%}
{%-for attr in state_attr('weather.home_hourly','forecast')[:24]%}
  {%-set time = as_timestamp(attr.datetime) | timestamp_custom("%H:%M")%}
  {%-set cond =  attr.condition%}
  {%-set temp =  attr.temperature%}
  {%-set press =  attr.pressure%}
  {%-set wind_s=  attr.wind_speed%}
  {%-set wind_b = attr.wind_bearing%}
  {%-set wdir = direction[((wind_b+11.25)/22.5)|int]%}
  {%-set precip =  attr.precipitation%}
  {%-set cloud_cov= attr.cloud_coverage-%}  
  {%set humidity= attr.humidity-%}
  |{{time}}|{{cond}}|{{temp}}|{{wind_s}}|{{wdir}}|{{precip}}|{{humidity}}|{{cloud_cov}}|
{%endfor%}