FL550 / dwd_weather

Deutscher Wetterdienst integration for Home-Assistant
MIT License
154 stars 12 forks source link

Max Daily Temperature broken #127

Open Qhilm opened 1 month ago

Qhilm commented 1 month ago

Version of home_assistant

2024.5.3

Version of the custom_component

2.1.2

Describe the bug

The following code was working last year (you suggested this, many thanks again), it does not work anymore though:

  - trigger:
    - platform: time
      at: "00:02:00"
    - platform: homeassistant
      event: start
    - platform: event
      event_type: event_template_reloaded
    action:
      - service: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: weather.dwd_station_redacted
        response_variable: weather_data
    sensor:
      - name: "Max temp today"
        unique_id: max_temp_today
        state: >-
          {{ weather_data['weather.dwd_station_redacted'].forecast[0].temperature }}
        unit_of_measurement: "°C"
      - name: "Min temp today"
        unique_id: min_temp_today
        state: >-
          {{ weather_data['weather.dwd_station_redacted'].forecast[0].templow }}
        unit_of_measurement: "°C"

The entity sensor.max_temp_today seems to show the minimum daily temperature now, instead of the maximum. It feels like the data structure has changed. If there is a place where I can look this up, please point me in the right direction. I went to the DWD OpenData page but it does not seem there is a description of the data format.

"Force hourly data update" is enabled for me, but I notice that data type is set to "daily" in this yaml, I wonder if there is a conflict.

Debug log

There are no errors in the logs, as far as I can tell.

Qhilm commented 1 month ago

I feel I need to create a second sensor, same DWD station, but left in "daily data update" mode. I will try this.

FL550 commented 1 month ago

Hi, sorry for my late reply. There hasn't been changed regarding this data structure. The temperature attribute is still the same, so the max temp should still be the maximum temperature of the day. Can you please provide some details about your suspected error in the data?

Qhilm commented 1 month ago

Hi, no problem.

For example, currently sensor.max_temp_today is 16°C. 16°C is the minimum today though...

Will the below really get the daily minimum? Or is 0 the first hour of the day? (my service is set to collect hourly data)

weather_data['weather.dwd_station_redacted'].forecast[0].temperature

Qhilm commented 1 month ago

It's weird, it seems to work at first when I reload Home Assistant, then it goes wrong and sensor.max_temp_today is even lower than the daily max I see in the forecast card for weather.dwd_station_redacted...

image

Then I reload HA and it's correct again:

image

FL550 commented 1 month ago

@Qhilm Do you have the daily update enabled?

Qhilm commented 1 month ago

So the yaml above says "daily" but the device is set to "hourly". I'm not entirely clear on how the two interacts.

Qhilm commented 1 month ago

I tried creating an new integration entry set to "daily", that didn't help.

There are two symptoms:

  1. Restart Home Assistant always temporarily fixes the issue. The next day it's wrong again.
  2. When sensor.max_temp_today is wrong the value is way too low, it's sometime lower than the daily minimum, I have really no idea what this temperature is supposed to represent.

It's like weather.get_forecasts is broken and pulling some garbled data and when HA restarts it does something else, not weather.get_forecasts...

Qhilm commented 1 month ago

Update: the history of sensor.max_temp_today shows that it is indeed fetching something at 2am, the trigger seems to be working. In the image below, one can see that sensor.max_temp_today was 15°C until 2am (which was wrong), then at 2am it went down to 13°C (also completely wrong) and when I reloaded HA it jumped to 25°C (correct).

image

It seems that the trigger triggers does something that is different than what happens when restarting HA.

[edit] And reloading templates also fixes the issue. I don't get why it pulls the wrong temperature at 2am, it's the same code.

FL550 commented 3 weeks ago

I am quite busy right now, so I currently have no time for assisting you. I am sorry, but I promise I will look into this after I find some time!