dwd_weather: Irradiance forecasts no longer available
Hi there,
I have recently upgraded to HA 2023.9.3 and I have upgraded dwd_weather through the GUI to the latest version (should be 2.0.1).
I have been using my own template sensors to calculate total rest of day or rolling 24 hour irradiance forecasts and the like based on dwd_weather to have an idea how much heat to expect from my solar panels in the near future and to make decisions off of that.
Here is one example that used to work for several months prior to the two upgrades (HA and dwd_weather) I made:
- platform: template
sensors:
sun_irradiance_staaken_rest_of_day_forecast:
friendly_name: "Rest of day forecast of irradiance"
unit_of_measurement: 'W/m^2'
value_template: >-
{% set irrTotal = namespace(value=0) %}
{% set current_hour = now().hour %}
{% set hours_left = 24 - current_hour %}
{% for irr in state_attr('sensor.sun_irradiance_staaken', 'data') -%}
{% if loop.index <= hours_left %}
{% set irrTotal.value = irrTotal.value + irr.value %}
{% else %}
{% break %}
{% endif %}
{%- endfor %}
{{ irrTotal.value }}
After the upgrades I found the following error in the logs:
TemplateError(‘TypeError: unsupported operand type(s) for +: ‘int’ and ‘NoneType’’) while processing template ‘Template<template=({% set irrTotal = namespace(value=0) %} {% set current_hour = now().hour %} {% set hours_left = 24 - current_hour %} {% for irr in state_attr(‘sensor.sun_irradiance_staaken’, ‘data’) -%} {% if loop.index <= hours_left %} {% set irrTotal.value = irrTotal.value + irr.value %} {% else %} {% break %} {% endif %} {%- endfor %} {{ irrTotal.value }}) renders=4>’ for attribute ‘_attr_native_value’ in entity ‘sensor.sun_irradiance_staaken_rest_of_day_forecast’
I checked the sensor sensor.sun_irradiance_staaken in the developer tools and it showed the sensor’s state as “unknown” and the attribute values looked like this:
state_class: measurement data:
- datetime: ‘2023-10-04T19:00:00.000Z’ value: null
- datetime: ‘2023-10-04T20:00:00.000Z’ value: null
- datetime: ‘2023-10-04T21:00:00.000Z’ value: null
- datetime: ‘2023-10-04T22:00:00.000Z’ value: null
- datetime: ‘2023-10-04T23:00:00.000Z’ value: null (…)
Before the upgrades I would see numeric values instead of the null values
Since I head read the notes on the new trigger/action in templates and the breaking change in dwd_weather in the latest release I thought it might have to do with that and I updated my sensor definition to:
- template:
- trigger:
- platform: time_pattern
hours: "/1"
- platform: homeassistant
event: start
- platform: event
event_type: event_template_reloaded
action:
- service: weather.get_forecast
data:
type: hourly
target:
entity_id: weather.staaken_staaken
response_variable: irradiance_data
sensor:
- name: "Rest of day forecast of irradiance"
unique_id: sun_irradiance_staaken_rest_of_day_forecast
state: >-
{% set irrTotal = namespace(value=0) %}
{% set current_hour = now().hour %}
{% set hours_left = 24 - current_hour %}
{% for irr in irradiance_data.data -%}
{% if loop.index <= hours_left %}
{% set irrTotal.value = irrTotal.value + irr.value %}
{% else %}
{% break %}
{% endif %}
{%- endfor %}
{{ irrTotal.value }}
unit_of_measurement: "W/m^2"
after that the error changed and it now is:
Template variable warning: ‘dict object’ has no attribute ‘data’ when rendering ‘{% set irrTotal = namespace(value=0) %} {% set current_hour = now().hour %} {% set hours_left = 24 - current_hour %} {% for irr in irradiance_data.data -%} {% if loop.index <= hours_left %} {% set irrTotal.value = irrTotal.value + irr.value %} {% else %} {% break %} {% endif %} {%- endfor %} {{ irrTotal.value }}’
so I manually tested the new get_forecast service like:
service: weather.get_forecast
data:
type: hourly
target:
entity_id: weather.staaken_staaken
and I got this:
forecast:
- datetime: “2023-10-04T19:00:00Z” condition: cloudy wind_bearing: SW wind_gusts: 5.14 precipitation_probability: 11 temperature: 14 templow: 14 wind_speed: 2.57 precipitation: 0 (…)
This tells me two things:
- I will slightly have to adjust my code as the structure has changed a bit
- there is no point in fixing the issue above as the attribute I have always been using (irradiance) is no longer part of the forecast
Obviously I am missing something but I can’t figure out what it is. Any hints how to solve this and get the hourly forecasts for irradiance back would be highly appreciated!
Thanks, Alex
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Reactions: 1
- Comments: 22 (12 by maintainers)
@diplix the station X104 you have mentioned should have the sensor values you are looking for. The error looks like some kind of network error, as this specific case should not happen. Can you file a new issue for this and upload your debug log as well? Thanks.