Openweathermap forecast data shows "none"

Hi @ all,

I had created a custom template for weather conditions some time ago and it was doing the job as intended. but unfortionately round about two weeks ago it stopped without changing something from my side (I was on holidays) and I am not able anymore to extract the weather forecast data from openweathermap.

Normally {{ state_attr('weather.openweathermap', 'forecast') }} returns an array which I read like this:

{% set cond0 = state_attr('weather.openweathermap', 'forecast')[0].condition %}
{% set cond0_time = as_timestamp(state_attr('weather.openweathermap', 'forecast')[0].datetime) %}

But the template editor actually shows me only “None”.

{{ state_attr('weather.openweathermap', 'forecast')[0].condition }}

Output:

(Error !) None has no element 0

… some more tests

{{ state_attr('weather.openweathermap', 'temperature') }}
{{ states('weather.openweathermap') }}
{{ state_attr('weather.openweathermap', 'forecast') }}
{{ state_attr('weather.openweathermap', 'forecast')[0] }}

Output:

(Warning !) None has no element 0

11.5
clear-night
None

The openweathermap integration is working and the forecast data seems to be available. I had already removed the integration and added it back.

Does anyone have any idea?

Regards,
Roman

The forecast is no longer part of the sensor and deprecated this month. Search the forum…many posts

1 Like

See first example:

1 Like

Hi vingerha and troon,

I just googled for a while and didn’t realized that this was changed. The google hits showed only some old posts about how to do that the old way and not the actual ones. Thanks for posting the correct / actual way. I will change it in my config.

Regards,
Roman

Thanks again. If someone other needs an example:

  - trigger:
    - platform: time_pattern
      minutes: "/10"
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.openweathermap
        response_variable: hourly
    sensor:
      - name: sh-flur-bilderrahmen_data
        state: "OK"
        attributes: 
          weather_now_temperature: >
            {{ states('sensor.openweathermap_temperature') | round }}
          weather_now_condition: >
            {% set cond_now = states('weather.openweathermap') %}
            {% if states('sun.sun') == 'below_horizon' %}
                {% if cond_now == 'sunny' %} night {% elif cond_now == 'partlycloudy' %} night-partly-cloudy {% else %} {{ cond_now }} {% endif %}
            {% else %}
                {{ cond_now }}
            {% endif %}
          weather_hourly_condition_0: >
            {% set cond0 = hourly['weather.openweathermap'].forecast[0].condition %}
            {% set next_setting = as_timestamp(state_attr('sun.sun', 'next_setting')) %}
            {% set next_rising = as_timestamp(state_attr('sun.sun', 'next_rising')) %}
            {% set cond0_time = as_timestamp(hourly['weather.openweathermap'].forecast[0].datetime) %}
            {% if cond0_time > next_setting or cond0_time < next_rising < next_setting %}
                {% if cond0 == 'sunny' %} night {% elif cond0 == 'partlycloudy' %} night-partly-cloudy {% else %} {{ cond0 }} {% endif %}
            {% else %}
                {{ cond0 }}
            {% endif %}
          weather_hourly_temperature_0: >
            {{ hourly['weather.openweathermap'].forecast[0].temperature | round }}
          weather_hourly_timestamp_0: >
            {{ as_timestamp(hourly['weather.openweathermap'].forecast[0].datetime) | timestamp_custom('%H:00') }}
          weather_hourly_condition_1: >
            {% set cond1 = hourly['weather.openweathermap'].forecast[1].condition %}
            {% set next_setting = as_timestamp(state_attr('sun.sun', 'next_setting')) %}
            {% set next_rising = as_timestamp(state_attr('sun.sun', 'next_rising')) %}
            {% set cond1_time = as_timestamp(hourly['weather.openweathermap'].forecast[1].datetime) %}
            {% if cond1_time > next_setting or cond1_time < next_rising < next_setting %}
                {% if cond1 == 'sunny' %} night {% elif cond1 == 'partlycloudy' %} night-partly-cloudy {% else %} {{ cond1 }} {% endif %}
            {% else %}
                {{ cond1 }}
            {% endif %}
          weather_hourly_temperature_1: >
            {{ hourly['weather.openweathermap'].forecast[1].temperature | round }}
          weather_hourly_timestamp_1: >
            {{ as_timestamp(hourly['weather.openweathermap'].forecast[1].datetime) | timestamp_custom('%H:00') }}
          weather_hourly_condition_2: >
            {% set cond2 = hourly['weather.openweathermap'].forecast[2].condition %}
            {% set next_setting = as_timestamp(state_attr('sun.sun', 'next_setting')) %}
            {% set next_rising = as_timestamp(state_attr('sun.sun', 'next_rising')) %}
            {% set cond2_time = as_timestamp(hourly['weather.openweathermap'].forecast[2].datetime) %}
            {% if cond2_time > next_setting or cond2_time < next_rising < next_setting %}
                {% if cond2 == 'sunny' %} night {% elif cond2 == 'partlycloudy' %} night-partly-cloudy {% else %} {{ cond2 }} {% endif %}
            {% else %}
                {{ cond2 }}
            {% endif %}
          weather_hourly_temperature_2: >
            {{ hourly['weather.openweathermap'].forecast[2].temperature | round }}
          weather_hourly_timestamp_2: >
            {{ as_timestamp(hourly['weather.openweathermap'].forecast[2].datetime) | timestamp_custom('%H:00') }}
          weather_hourly_condition_3: >
            {% set cond3 = hourly['weather.openweathermap'].forecast[3].condition %}
            {% set next_setting = as_timestamp(state_attr('sun.sun', 'next_setting')) %}
            {% set next_rising = as_timestamp(state_attr('sun.sun', 'next_rising')) %}
            {% set cond3_time = as_timestamp(hourly['weather.openweathermap'].forecast[3].datetime) %}
            {% if cond3_time > next_setting or cond3_time < next_rising < next_setting %}
                {% if cond3 == 'sunny' %} night {% elif cond3 == 'partlycloudy' %} night-partly-cloudy {% else %} {{ cond3 }} {% endif %}
            {% else %}
                {{ cond3 }}
            {% endif %}
          weather_hourly_temperature_3: >
            {{ hourly['weather.openweathermap'].forecast[3].temperature | round }}
          weather_hourly_timestamp_3: >
            {{ as_timestamp(hourly['weather.openweathermap'].forecast[3].datetime) | timestamp_custom('%H:00') }}

Hey group. I’m also in the same boat as others since the change to the new format. My template sensor that gave me the forecast maximum temperature for the day is returning nothing because {{ state_attr('weather.openweathermap', 'forecast') now returns none.

So, Based on the new format, I’m looking for a template sensor that will tell me the forecast maximum temperature for the current day.

Is anyone able to help with that please?

please see post here 2024.4 has broken a esp32home project I use

1 Like