Getting tomorrow's forecast at a specified time of day

Using the default HA weather sensor (Meteorologisk institutt (Met.no)) I got the following so far:

alias: Tomorrow's Forecast - Rain
description: 'Check to see if there is rain forecast tomorrow, otherwise stope the automation until next trigger time.'
trigger:
  - platform: time
    at: '21:00:00'
condition: []
action:
  - if:
      - condition: state
        entity_id: zone.home
        attribute: forecast
        state: rainy
    then:
      - service: notify.notify
        data:
          title: Tomorrow's forecast
          message: >-
            Tomorrow's forecast is {{ state_attr("weather.my_home",
            "forecast")[1].condition }}
    else:
      - stop: No rainy forecast for tomorrow
mode: single

What I am trying to do here is to have every day at 9:00 pm, evaluate if tomorrow will be rainy forecast. If it is, then notify me on my phone. Otherwise, the automation stops/finishes.

The issue where I’m getting it is at the “if” part of the automation.

Here is the state:

Any help is appreciated!

You’re complicating things here just a little. :slight_smile: Try to go one or two steps back and use “normal” automation functions.

alias: Tomorrow's Forecast - Rain
id: Tomorrow's Forecast - Rain
description: 'Check to see if there is rain forecast tomorrow, otherwise stope the automation until next trigger time.'
trigger:
  - platform: time
    at: '21:00:00'
condition:
  - condition: template
    value_template: "{{ states.weather.my_home.attributes.forecast[1].condition == 'rainy' }}"
action:
  - service: notify.notify
    data:
      title: Tomorrow's forecast
      message: "Tomorrow's forecast is {{ states.weather.my_home.attributes.forecast[1].condition }}"
mode: single

This does:

  • trigger at 21:00h
  • check, if tomorrows forecast is rainy (Note: check the exact states, I’m quite sure there are other states than “rainy” that are used for a rainy condition!)
  • send a notification

If the condition isn’t met, the following action part will not be used, so no need to do anything more. Following on this, it is not necessary to “stop” an automation. It ends after the action part is done, or it ends after the condition, if it isn’t met. :slight_smile: All done! :smiley:

If you want to enhance on this, let’s say start another service to close a window or a door (just an example), add it after (or before) the notification.

EDIT: changed the weather entity from weather.my_weather to weather.my_home

2 Likes
alias: Tomorrow's Forecast - Rain
description: 'Check to see if there is rain forecast tomorrow, otherwise stope the automation until next trigger time.'
trigger:
  - platform: time
    at: '21:00:00'
variables:
  forcast: >
    {% set dt = (today_at().astimezone(utcnow().tzinfo) + timedelta(days=1)).isoformat() %}
    {% set forcast = state_attr('weather.my_home', 'forecast') | selectattr('datetime','eq', dt) | first | default({}) %}
condition:
  condition: template
  value_template: "{{ forcast.get('condition', none) == 'rainy' }}"
action:
- service: notify.notify
  data:
    title: Tomorrow's forecast
    message: >-
      Tomorrow's forecast is {{ forcast.condition }}
mode: single

When I test the condition, I get the following error:

Did you change the my_weather to your actual entity?

1 Like

That’s broken in the UI. The test doesn’t work with templates.

1 Like

And I used the wrong entity, sorry. :slight_smile:

In my posted code it is weather.my_weather where it should be weather.my_home. :slight_smile:

I’ll edit my post above. :slight_smile:

1 Like

Yeah, I actually used my_home for my entity and still getting the same error:

Again, you can’t use the test button on template conditions. It will always error. It’s broken and does not work.

1 Like

But you can try and test it under Developer Tools > Template. :slight_smile:

1 Like