How to automate based on weather temperature forcast for current day?

I want to create an automation that should trigger always at the same time of the day (let’s say 9am).
My condition should be: “does the weather forecast show a forecast temperature of >20°C at 12am”.
Then as my action, I want to close my shutter blinds to 50%.

Problem: how can I evaluate that weather forecast condition? I mean, how can I get the forecast temperature of the current day?

  trigger:
  - at: 09:00:00
    platform: time
  condition:
  - condition: state
    //TODO weather.forecast.today.temperature??
  action:
  - service: script.shutter_move_down
1 Like

Show us What you have done so far and we point down the right track

read this

and

My problem is that I don’t know how I can extract the todays’ weather forecast temperature.

What are you using for your weather integration?

You can use yr.no integration.

Configuration.yaml

sensor:
  - platform: yr
    name: Weather
    forecast: 3 # 3 hour forcast
    monitored_conditions:
      - temperature

This will create a new sensor with the temperature forecast

This would be the condition you would use

  - condition: template
    value_template: "{{ (states('sensor.weather_temp_at_12am') | float) > 20 }}"

I’m not using anything special yet. Just the default HA sun + weather integration.
The sensor is called weather.home, but how can I get to know the properties that I could use?

So I now found out that I have the met.no integration running, the following is shown in my frontend.
Question: how can I access the values “temperature” and “forecast today 12pm” and the cloud state?

1 Like

So I could use the following:

weather.home //sunny
value_template: "{{ state_attr('weather.home', 'temperature') } //temperature
value_template: "{{ state_attr('weather.home', 'forecast[0].temperature') } //forecast TOMORROW

Unfortunately the 1st entry in forecast is never for today, but only starting from next day. Any chance I could also add the current day here?

It looks like they only have daily forecast. I use openweathermap which should give you want you want.

EDIT

Actually, doesn’t look like they do 12pm, every 3 hours so they jump from 11am to 2pm.

You can check out others here:

Unfortunately openweathermap does not offer the daily forecast in the free plan. I would mostly be interested in daily.temperature.max or something like that. Is there any HA weather integration that offers this?

I also found the default 5-day-3-hour forecast is very very bad for my location. Eg for this midnight, it shows 16°C, whereas current nights are never > 10° and any local forecasts confirm that’s below. So anyways I cannot use openweathermap for my case…

For now I solved it as follows: using yr.no with a 4h weather forecast, and evaluation my conditions at 10am in the automation. Then I will receive the temperature approx at the hottest time of the day (2pm). And if threshold is exceeded, I close my blinders.

  - name: weather_forecast
    platform: yr
    forecast: 4
    scan_interval: 600
    monitored_conditions:
      - temperature
      - cloudiness

No they don’t, but I use sensors to pull that information from here:

I created a day min and max sensor with OWM like this (details in the thread mentioned above):

# Day min and max temp
- platform: template
  sensors:
    day_max_temp:
      friendly_name: "24 Std. Höchsttemperatur"
      unit_of_measurement: "°C"
      entity_id: weather.openweathermap
      value_template: >
        {#% set start = (now().replace(hour=0,minute=0,second=0).timestamp() * 1000) | int %#}
        {% set start = (now().timestamp() * 1000) | int %}
        {% set end = start + 86400000 %}
        {{ state_attr('weather.openweathermap', 'forecast') | selectattr('datetime', '>=', start) | selectattr('datetime','<=', end) | map(attribute='temperature') | list | max }}

    day_min_temp:
      friendly_name: "24 Std. Tiefsttemperatur"
      unit_of_measurement: "°C"
      entity_id: weather.openweathermap
      value_template: >
        {#% set start = (now().replace(hour=0,minute=0,second=0).timestamp() * 1000) | int %#}
        {% set start = (now().timestamp() * 1000) | int %}
        {% set end = start + 86400000 %}
        {{ state_attr('weather.openweathermap', 'forecast') | selectattr('datetime', '>=', start) | selectattr('datetime','<=', end) | map(attribute='temperature') | list | min }}

Then you can use an automation like this:

- alias: 'Sun protection on sunny days'
  trigger:
    - platform: time
      at: '09:00:00'
  condition:
    condition: and
    conditions:
      - condition: numeric_state
        entity_id: sensor.day_max_temp
        above: 20.0
      - condition: numeric_state
        entity_id: sensor.owm_cloud_coverage
        below: 50
  action:
    - service: notify.telegram
      data:
        message: "Sonnenschutz \U0001F525"
    - service: script.alle_halb_geschlossen

Enjoy!

7 Likes

Which mode did you chose? Did you stick to the default hourly?

Just for reference: I’m not satisfied with the default OWM implementation in HA. Especially as owm provides a daily report that directly gives out the min/max temperatures for a day. So no need for calculations.

I set up my own sensors using a rest_template as follows:

  - name: owm_report
    platform: rest
    resource: 'https://api.openweathermap.org/data/2.5/onecall?units=metric&exclude=minutely,hourly&lat=<lat>&lon=<lon>&appid=<apikey>'
    scan_interval: 600
    value_template: '{{ value_json.current.temp }}'
    unit_of_measurement: '°C'
    json_attributes_path: "$.daily[0]"
    json_attributes:
      - temp
      - clouds
  - platform: template
    sensors: 
      weather_today_max_temp:
        friendly_name: 'Today Max Temp'
        device_class: temperature
        unit_of_measurement: '°C'
        value_template: '{{ state_attr("sensor.owm_report", "temp")["max"] }}'
      weather_today_min_temp:
        friendly_name: 'Today Min Temp'
        device_class: temperature
        unit_of_measurement: '°C'
        value_template: '{{ state_attr("sensor.owm_report", "temp")["min"] }}'
      weather_today_clouds:
        friendly_name: 'Today Cloudiness'
        unit_of_measurement: '%'
        value_template: '{{ state_attr("sensor.owm_report", "clouds") }}'
7 Likes

Much better! Thx a lot!

Maybe it would make sense to ask the maintainer of the OWM platform to include this within the official platform? :thinking:

PS: The OWM One Call API is being implemented (Convert OpenweatherMap Integration to use "one-call-api"). So just be patient… :slightly_smiling_face:

1 Like

I like your solution, but I am a bit confused since temp and temp_min/temp_max are always the same in my installation. Now I found this in the OWM API docs:

Please, do not confuse min/max parameters in our weather APIs.
In Current weather API , Hourly forecast API and 5 day / 3 hour forecast API - temp_min and temp_max are optional parameters mean min / max temperature in the city at the current moment just for your reference. For large cities and megalopolises geographically expanded it might be applicable. In most cases both temp_min and temp_max parameters have the same volume as ‘temp’. Please, use temp_min and temp_max parameters in current weather API optionally.

At least for the free subscription plan this might not be what you want?!

PS: Sorry, my mistake. You are using the new One Call API which indeed does provide day min/max temp (daily.temp.min).

Thanks for your feedback.
So we can hope to switch back to the owm plugin in some weeks?