FL550 / dwd_weather

Deutscher Wetterdienst integration for Home-Assistant
MIT License
157 stars 11 forks source link

Maximum forecasted temperature for today in v2 version? #83

Closed Qhilm closed 9 months ago

Qhilm commented 9 months ago

Version of home_assistant

2023.09.2

Version of the custom_component

2.0.1

Describe the bug

In previous version I used the code documented in closed issue #80

template:
  - sensor:
      - name: "Temperatur DWD Waltrop Heute Min"
        unique_id: temperatur_dwd_waltrop_forecast_0_temp_min
        state: "{{state_attr('weather.waltrop_abdinghof','forecast')[0]['templow'] | float(0) }}"
        unit_of_measurement: "°C"
        device_class: temperature

Question: how to rewrite this code for v2 of the integration? I'm struggling a bit.

FL550 commented 9 months ago

I will integrate this for you in the next few days as a new sensor 😉

Qhilm commented 9 months ago

Just to be specific, I use both max and min forecasted temperatures for today, not just minimum as depicted in the sample code. Probably obvious, but just in case.

FL550 commented 9 months ago

Ok, I have spent another thought about this and i think it is no good idea to implement this as a sensor in the integration. This will more or less counteract the newly introduced change in v2.

However, you can achive your request with this:

template:
- trigger:
    - platform: time
      at: "00:00:01"
    - platform: homeassistant
      event: start
    - platform: event
      event_type: event_template_reloaded
  action:
    - service: weather.get_forecast
      data:
        type: daily
      target:
        entity_id: {INSERT WEATHER ENTITY HERE}
      response_variable: weather_data
  sensor:
    - name: "Max temp"
      unique_id: max_daily_temp
      state: >-
        {{ weather_data.forecast[0].temperature }}
      unit_of_measurement: "°C"
    - name: "Min temp"
      unique_id: min_daily_temp
      state: >-
        {{ weather_data.forecast[0].templow }}
      unit_of_measurement: "°C"
Qhilm commented 9 months ago

Thanks a lot @FL550 .

I'm trying to understand the yaml you wrote: I do not see any reference to dwd_weather in there, am I right in thinking that the forecast in this code then comes from the built-in home assistant weather integration? It's not a problem, I just want to make sure I understand it.

[edit] there are two spaces missing at the start of the line - trigger:, correct?

FL550 commented 9 months ago

Hi! No, the data will come from whichever weather sensor you would like to use.

If you add a station to dwd_weather, it creates a weather entity with the name of the station in the format weather.station_name. This entity has to be inserted in the part entity_id: {INSERT WEATHER ENTITY HERE} from the snippet above.

Qhilm commented 9 months ago

That's strange, I cannot find this entity. I have 11 entities created by the "Deutscher Wetterdienst" integration, they all are of the type sensor.*.

Does it matter if I choose "sensor only", "forecast only" etc. when configuring the entity?

Qhilm commented 9 months ago

ignore, I deleted it, re-added it and now I have 20 entities, including the weather. entity. Don't know what happened.

FL550 commented 9 months ago

Happy to hear