FL550 / dwd_weather

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

Use max temperature today in automation #50

Closed Qhilm closed 2 years ago

Qhilm commented 2 years ago

Describe the solution you'd like

I an trying to create an automation based on the daily max temperature. Say for example, if temperature will rise above 28°C, close blinds. (it's more complex than this, I am only closing if the sun is hitting the particular window, but the daily max temperature should be a condition for the automation to run, hence I think I need it to be a sensor).

Describe alternatives you've considered

I have enabled sensor.temperature_<entity_name>, but that only gives the current temperature.

diplix commented 2 years ago

it’s not exactly a daily low, but this template sensor gives me the lowest temperature in the next 24 hours. this can be done with {{ today | max }} for the highest temperature, too.

template:
  - sensor:
      - name: Tiefsttemperatur in 24 h
        unique_id: E74013A7-348C-44F8-B4B1-93E5992C1840
        unit_of_measurement: °C
        state: >-
            {% set tomorrow = (as_timestamp(now() + timedelta(hours=24)) | timestamp_local) %}
            {% set today = state_attr('sensor.temperature_berlin_tegel', 'data')| selectattr('datetime', 'lt', tomorrow) | map(attribute='value') | list %}
            {{ today | min }}
Qhilm commented 2 years ago

Thanks a lot, the windows are facing east (ish), so this is good enough for me.

The frustrating thing is, the daily max is visible in the "weather forecast" card in HA, so I thought this could be pulled into a sensor.

nikipore commented 2 years ago

This is what I did for the very same purpose, but I found that what one actually needs for climate control isn't „today“ in terms of midnight or next 24 hours but in terms of day and night:

template:
  - sensor:
      - name: weather_hourly_forecast_index_next_rising
        state: >
          {{ max(0, (as_timestamp(state_attr('sun.sun', 'next_rising')) - as_timestamp(state_attr('weather.dwd_weather_1h', 'forecast')[0]['datetime'])) // 3600) }}
      - name: weather_hourly_forecast_index_next_setting
        state: >
          {{ max(0, (as_timestamp(state_attr('sun.sun', 'next_setting')) - as_timestamp(state_attr('weather.dwd_weather_1h', 'forecast')[0]['datetime'])) // 3600) }}
      - name: weather_forecast_temperature_high
        state_class: measurement
        unit_of_measurement: "°C"
        state: >
          {{ state_attr('sensor.temperature_1h', 'data')[:(states('sensor.weather_hourly_forecast_index_next_setting') | int(0)) + 1] | map(attribute='value') | max | float(0) }}
        device_class: temperature
      - name: weather_forecast_temperature_low
        state_class: measurement
        unit_of_measurement: "°C"
        state: >
          {{ state_attr('sensor.temperature_1h', 'data')[:(states('sensor.weather_hourly_forecast_index_next_rising') | int(0)) + 1] | map(attribute='value') | min | float(0) }}
        device_class: temperature

Since I am on vacation I am posting this on my smartphone, so no guarantee for correct syntax/indentation, but the idea should be clear.

I decide when to open/close window and roof covers with a combination of actual (inside/outside) and high/low forecast temperatures, window position w.r.t. sun (Node-RED library sun-position) plus forecast of sun intensity (forecast.solar integration).

FL550 commented 2 years ago

Hi, you could also use the max and min values for the configured time interval from the weather entity directly like this:

template:
  - sensor:
      - name: Höchsttemperatur
        unit_of_measurement: °C
        state: > 
          {{ state_attr("weather.dwd_weather_bad_homburg", "forecast")[0]["temperature"] }}
      - name: Tiefsttemperatur
        unit_of_measurement: °C
        state: > 
          {{ state_attr("weather.dwd_weather_bad_homburg", "forecast")[0]["templow"] }}

If you want the next day, replace the 0 with a 1 and so on.

diplix commented 2 years ago

Hi, you could also use the max and min values for the configured time interval from the weather entity directly like this:

i think thats what i used first, but i wanted to know if there’s night frost during the night. and since the weather entity’s min/max only extends to midnight it was hard to predict whether there was going to be frost during the upcoming night. 24 h min/max works better for that prediction. but of course it’s more elegant to get the „daily max temperature“.

Qhilm commented 2 years ago
template:
  - sensor:
      - name: Höchsttemperatur
        unit_of_measurement: °C
        state: > 
          {{ state_attr("weather.dwd_weather_bad_homburg", "forecast")[0]["temperature"] }}

Exactly what I was looking for! Thanks @FL550 .