core: OpenWeatherMap hourly missing attribute(s)

The problem

Used open weathermap integration onecall_hourly to calculate the number of sunny hours for the day. For hours with “partlycloudy” I’ve checked the “clouds” attribute of the hour and added a value according to the cloud coverage. But the cloud attribute is missing since I’ve updated from 22.6.x to 22.7.3

Hourly output with 22.7.3:

{'condition': 'cloudy', 'precipitation_probability': 0, 'datetime': '2022-07-11T09:00:00+00:00', 'wind_bearing': 24, 'temperature': 20.9, 'wind_speed': 4.79, 'precipitation': 0.0}

{'condition': 'cloudy', 'precipitation_probability': 0, 'datetime': '2022-07-11T10:00:00+00:00', 'wind_bearing': 25, 'temperature': 20.9, 'wind_speed': 7.13, 'precipitation': 0.0}
  
{'condition': 'cloudy', 'precipitation_probability': 0, 'datetime': '2022-07-11T11:00:00+00:00', 'wind_bearing': 19, 'temperature': 21.3, 'wind_speed': 8.86, 'precipitation': 0.0}

{'condition': 'cloudy', 'precipitation_probability': 0, 'datetime': '2022-07-11T12:00:00+00:00', 'wind_bearing': 16, 'temperature': 21.9, 'wind_speed': 11.84, 'precipitation': 0.0}

{'condition': 'cloudy', 'precipitation_probability': 0, 'datetime': '2022-07-11T13:00:00+00:00', 'wind_bearing': 14, 'temperature': 22.7, 'wind_speed': 12.89, 'precipitation': 0.0}
  
{'condition': 'partlycloudy', 'precipitation_probability': 0, 'datetime': '2022-07-11T14:00:00+00:00', 'wind_bearing': 9, 'temperature': 23.4, 'wind_speed': 12.64, 'precipitation': 0.0}
  
    {'condition': 'partlycloudy', 'precipitation_probability': 0, 'datetime': '2022-07-11T14:00:00+00:00', 'wind_bearing': 9, 'temperature': 23.4, 'wind_speed': 12.64, 'precipitation': 0.0}
  
{'condition': 'partlycloudy', 'precipitation_probability': 0, 'datetime': '2022-07-11T15:00:00+00:00', 'wind_bearing': 5, 'temperature': 24.0, 'wind_speed': 13.75, 'precipitation': 0.0}

My sensor:

template:
  - sensor:
    - name: "Sonnenstunden heute"
      unit_of_measurement: "h"
      state: >
        {% set sunH = namespace(value=0) %}
        {% set nextSunSetting = as_timestamp(state_attr("sun.sun", "next_setting")) %}
        {% for h_forecast in state_attr("weather.openweathermaphourly", "forecast") %}
          {% if h_forecast.condition == "sunny" and as_timestamp(h_forecast.datetime) < nextSunSetting %}
            {% set sunH.value = sunH.value + 1 %}
          {% endif %}
          {% if h_forecast.condition == "partlycloudy" and as_timestamp(h_forecast.datetime) < nextSunSetting %}
            {% set sunH.value = sunH.value + (100-**h_forecast.clouds**)/100 %}
          {% endif %}
        {% endfor %}
        {{ sunH.value }}

According to the openWeather API it should be still there: https://openweathermap.org/api/one-call-3 image

What version of Home Assistant Core has the issue?

core-2022.7.3

What was the last working version of Home Assistant Core?

core-2022.6.x

What type of installation are you running?

Home Assistant Container

Integration causing the issue

OpenWeatherMap

Link to integration documentation on our website

https://www.home-assistant.io/integrations/openweathermap/

Diagnostics information

No response

Example YAML snippet

{% set sunH = namespace(value=0) %}
        {% set nextSunSetting = as_timestamp(state_attr("sun.sun", "next_setting")) %}
        {% for h_forecast in state_attr("weather.openweathermaphourly", "forecast") %}
          {% if h_forecast.condition == "sunny" and as_timestamp(h_forecast.datetime) < nextSunSetting %}
            {% set sunH.value = sunH.value + 1 %}
          {% endif %}
          {% if h_forecast.condition == "partlycloudy" and as_timestamp(h_forecast.datetime) < nextSunSetting %}
            {% set sunH.value = sunH.value + (100-h_forecast.clouds)/100 %}
          {% endif %}
        {% endfor %}
        {{ sunH.value }}

Anything in the logs that might be useful for us?

TemplateError('UndefinedError: 'dict object' has no attribute 'clouds'') while processing template 'Template("{% set sunH = namespace(value=0) %} {% set nextDuskE = as_timestamp(state_attr("sun.sun", "next_dusk")) %} {% set nextSunSetting = as_timestamp(state_attr("sun.sun", "next_setting")) %} {% for h_forecast in state_attr("weather.openweathermaphourly", "forecast") %} {% if h_forecast.condition == "sunny" and as_timestamp(h_forecast.datetime) < nextSunSetting %} {% set sunH.value = sunH.value + 1 %} {% endif %} {% if h_forecast.condition == "partlycloudy" and as_timestamp(h_forecast.datetime) < nextSunSetting %} {% set sunH.value = sunH.value + (100-h_forecast.clouds)/100 %} {% endif %} {% endfor %} {{ sunH.value }}")' for attribute '_attr_native_value' in entity 'sensor.sonnenstunden_heute'

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 19

Most upvoted comments

Got the same issue.

Also noticed strange difference in units of measure:

  • sensor.openweathermap_forecast_wind_speed is reported in m/s but:
  • weather.openweathermap hourly forecast is reported in km/h

This was changed at the same time as the “clouds”.