Weather Forecast automation - get notification in case of frost

Hello Community,

im new to HA so please don’t be too harsh with me. :stuck_out_tongue:

Iam trying to set up a new automation which checks the forecast within the next 12 hours and gives me a notification if it gets 2°C or below, so i can bring in all my plants who are not so fine with such cold temperatures.
I’ve tried everything within my power and asked ChatGPT a couple times - also told ChatGPT that there were recent changes (i guess it was 2024.3) but it still doesn’t work. I’m using the Met.no integration.

My automation looks like this atm:


triggers:

  • hours: “*”
    trigger: time_pattern
    conditions:
  • condition: template
    value_template: >
    {% set forecast = state_attr(‘weather.forecast_home’, ‘forecast’) %} {% if
    forecast is not none %}
    {% set frost_warning = false %}
    {% for entry in forecast[:12] %}
    {% if entry.temperature < 2 %}
    {% set frost_warning = true %}
    {% endif %}
    {% endfor %}
    {{ frost_warning }}
    {% else %}
    {{ log(‘Frostwarnung: Keine Vorhersagedaten vorhanden!’) }}
    false
    {% endif %}
    actions:
  • data:
    message: >-
    Achtung! Die Temperatur wird in den nächsten 12 Stunden unter 2°C
    fallen.
    title: Frostwarnung
    action: notify.mobile_app_myphone
    mode: single

Does anyone have a hint for me whats wrong here?

Thank you in advance!

Best regards
Robert

alias: example
triggers:
  - trigger: time_pattern
    hours: '*'
conditions: []
actions:
  - action: weather.get_forecasts 
    data:
       type: hourly
    target:
      entity_id: weather.forecast_home
    response_variable: hourly
  - variables:
      temps: >
        {{ hourly['weather.forecast_home'].forecast[:12]
           | selectattr('temperature', 'lt', 2) 
           | list }}
  - if: "{{ temps | count > 0 }}"
    then:
      - action: notify.mobile_app_myphone
        data:
          message: >-
            Achtung! Die Temperatur wird in den nächsten 
            12 Stunden unter 2°C fallen.
          title: Frostwarnung

If you want, there’s information in the temps variable that allows you to report the exact temperature value and time when the temperature will be less than 2.

1 Like

Thank you for your fast reply!

Awesome, that one works!
Because it works i just notice that i probably had a brainlagg - since it probably checks this every hour now and gives a notification every hour. Potentially 12 times, if the temperature drops below 2 at the 12th hour after the initial check.

Not sure what the most clever way is to solve this…maybe with a check if the notification was sent within the last 6, 8 or 12 hours already? Any good idea regarding this? ^^

Thanks so far <3

Glad to hear it works for you.

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which indicates to others that the topic has been solved. This helps other users find answers to similar questions.

One way would be to replace this automation with a Trigger-based Template Binary Sensor. It will be set to on if the temperature is below 2 within the next 12 hours. It will also remain on until there’s no temperature lower than 2 in the next 12 hours. In other words, it changes to on and stays that way until there’s no risk of frost in the next 12 hours.

You can create a new automation, that’s triggered when the Template Binary Sensor changes state from off to on, and sends you a notification.

Or you can use the Alert integration to monitor the Template Binary Sensor and notify you when it turns on.

1 Like

Solution Check is set - makes sense!

Thanks for the extensive reply! I will check the Template Binary Sensors out! I had no idea that this exists.

1 Like

To help you get started, here’s an example of a Trigger-based Template Binary Sensor that turns on when the temperature is less than 2 in the next 12 hours.

template:
  - trigger:
      - trigger: time_pattern
        hours: '*'
    action:
      - action: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.forecast_home
        response_variable: hourly
    binary_sensor:
      - name: Frost Warning
        unique_id: frost_in_next_12_hours
        device_class: cold
        state: >
          {{ hourly['weather.forecast_home'].forecast[:12]
             | selectattr('temperature', 'lt', 2)
             | list | count > 0 }}

It goes in your configuration.yaml file under the template: key (should be only one template: key in the file).

If the file contains something that looks like this:

template: !include templates.yaml 

Then it means you need to put the example into the templates.yaml file but then you must ensure the first line within that file does not include the template: key.

1 Like

Sorry i didn’t noticed that you answered again! I will test this and give feedback afterwards! Thanks a lot <3