Openweathermap forecast not working

Hi, I’m having a very bad time trying to get the Openweathermap integration to do what I need.
I have tried every example I could find to get the condition forecast info so that I can pass it on to esphome, but nothing works. (even the code posted as an example)
The integration is working 100%, but I cannot seem to extract the forecast information.
Any help would be appreciated.

This is the code that I tried, and many other:

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

Your response variable is called hourly, but when reading you try to use daily. Rename the response variable to daily.

But then again, the name suggests you want hourly? You would need to change more daily in to hourly then, also for the service type.

I believe the Integration has changed recently and no longer provides forecast data. Either June or July update is when the change happened, but don’t quote me on that one, I was using the forecast data to make weather announcements and noticed one day they stopped working as expected.

Time to try another weather service.

I missed that. I have changed the code now to use an automation to get the info and store in in a text “variable”, but still I get no data. Here is the new code:

alias: Update 12 Hour Forecast
trigger:
  - platform: time_pattern
    hours: "12"
action:
  - service: weather.get_forecasts
    target:
      entity_id: weather.openweathermap
    data:
      type: daily
  - delay: "00:00:10"
  - service: input_text.set_value
    target:
      entity_id: input_text.12_hr_forecast
    data:
      value: >
        {% set forecast = state_attr('weather.openweathermap', 'forecast') %} {%
        if forecast and forecast | length > 0 %}
          {{ forecast[0].condition }}
        {% else %}
          'No data'
        {% endif %}
mode: single

The result is: State “unknown”
I feel like I’m missing something simple.

The integration is definitely working as I can see the forecast if I open the weather.openweathermap sensor info.

HA decided to remove the forecast sensor recently, which was through the 6 months grace period for its deprecation.
It might be that event you are think of.
Today you need to make a service call to get the forecast, which OP looks like he is doing.

That is correct. I am using a service call, but it seems to return an empty string.
image

Ahh, I found what Maximo might be referring to.
OpenWeatherMap has changed API to V3.0 and the old V2.5 was closed in June.
If your API is not set up recently, then you might still be connecting to the old V2.5 API which does not work anymore.

Hi, I have changed it to V3.0. I even uninstalled the integration, upgraded my Openweathermap account, got a new API key, re-installed the integration, and tested it to ensure it works.
All the other sensors created by the integration works correctly and I can view the forecast when I view the “info” for the weather.openweathermap sensor, but I cannot retrieve the info to use it.

You might be missing the response_variable

Is input_text.12_hr_forecast not my response variable?

Nope, that is another step in your automation.
See the link I posted for the Weather integration and look for Response

Ok, so I have modified my automation, restarted Homeassistant, and triggered the automation twice just to be sure, but still no result in input_text.12_hr_forecast.

alias: Update 12 Hour Forecast
trigger:
  - platform: time_pattern
    hours: "12"
action:
  - service: weather.get_forecasts
    target:
      entity_id: weather.openweathermap
    data:
      type: daily
    response_variable: daily
  - delay: "00:00:10"
  - service: input_text.set_value
    target:
      entity_id: input_text.12_hr_forecast
    data:
      value: >
        {% set forecast = state_attr('weather.openweathermap', 'forecast') %} {%
        if forecast and forecast | length > 0 %}
          {{ forecast[0].condition }}
        {% else %}
          'No data'
        {% endif %}
mode: single

I did a “trace” on the automation and it is getting a result from the service call. It is just not stored in the input_text.12_hr_forecast entity.
I’m not sure why not.
image

its because your forecast is stored in a response variable called daily, but you are using that variable anywhere in your service call to set the input text helper.
Check the link for weather again and look at the two examples in the bottom.

I have reworked the code to match the documentation, but still no result:

alias: Update 12 Hour Forecast
trigger:
  - platform: time_pattern
    hours: "12"
action:
  - service: weather.get_forecasts
    data:
      type: daily
      entity_id: weather.openweathermap
    response_variable: daily
  - delay: "00:00:10"
  - service: input_text.set_value
    target:
      entity_id: input_text.12_hr_forecast
    data:
      value: |
        "{{daily['weather.openweathermap'].forecast[0].condition}}"
mode: single

The trace shows that the “daily” variable does contain the data:

The final step also seems correct, but it is not setting the value of “input_text.12_hr_forecast”. I don’t know why.

image

Result:

Ok, I eventually got it to work.
While troubleshooting my code I somehow changed the helper name from input_text.12_hr_forecast to input_text.12_hour_forecast, so even though the code was eventually correct the helper was not updated because it did not exist.
Here is the working automation, maybe it can help somebody else:

alias: Update 12 Hour Forecast
trigger:
  - platform: time_pattern
    hours: "12"
action:
  - service: weather.get_forecasts
    data:
      type: daily
      entity_id: weather.openweathermap
    response_variable: daily
  - service: input_text.set_value
    target:
      entity_id: input_text.12_hour_forecast
    data:
      value: "{{daily['weather.openweathermap'].forecast[0].condition }}"
mode: single

In your first post you put hourly where it should have read daily. I gave you the answer in the post #2 immediately below. Then you changed a lot of other things, and eventually got a more complex solution. If you want to do without the input helper, you can simply fix the response variable.

The problem is that even changing hourly to daily did not work.
I’m not sure if it was because I was using it in an automation or maybe a typo, but it did not work.
The YAML editor won’t even let me save the code as per the first post:
image

It was because you changed multiple things at once. Fix the response variable, add a flawed input helper. But we could not know the input helper was entered the wrong way. I don’t really mind, except for the fact that the solution tag is now on a solution that requires an extra input helper that shouldn’t be needed. So for those coming here for the solution, it should be clear the first attempt was almost right.

The logs would probably have shown the mistake by the way.