Frost warning with Home Assistant 🥶

Do you have a garden and want to be notified when winter is coming? I'll show you how easy it is 🏡

Frost warning with Home Assistant 🥶
Photo by George Hiles / Unsplash / Image / Image

Every garden owner will know the problem: Winter is coming.

There are many things in the garden that should be switched off or prepared accordingly before the first frost, as otherwise they will be damaged and therefore need to be properly winterized. This also applies to my garden irrigation and all other things.

Preparations 🛠️

In order to know when the first frost is coming, you need to prepare a few things. This includes creating a sensor that queries precisely this data and determines it as a Boolean value. Accordingly, the sensor can accept the value true or false.

To do this, we create a new template sensor in our configuration.yaml. The template sensor queries the data of the Weather entity and calculates whether the temperature at the specified location falls below 0°C and if so, for how long.

In addition, the attributes also store what the lowest temperature is and when (i.e. on which date) it occurs.

Please remember to adapt the CHANGE THIS to your circumstances:

- platform: template
      friendly_name: "frost warning"
      unique_id: "39a5e512-b92f-449c-b681"
      icon_template: "mdi:snowflake-alert"
      value_template: >-
        {% if states('sensor.min_temp_forecast') | float < 0 %}
        {% else %}
        {% endif %}
        frostdays: >-
          {% set ns = namespace(frostdays=0) %}
          {%- for fc in THIS.attributes.forecast -%}
              {%- if fc.templow < 0 -%}
                  {%- set ns.frostdays = ns.frostdays + 1 -%}
              {%- endif -%}
          {%- endfor -%}
        first_frost_date: >-
          {% set ns = namespace(date=0) %}
          {%- for fc in THIS.attributes.forecast -%}
              {%- if fc.templow < 0 and == 0 -%}
                  {%- set = fc.datetime -%}
              {%- endif -%}
          {%- endfor -%}
        date_low: "{{state_attr('sensor.min_temp_forecast', 'datetime')}}"
        temp_low: "{{states('sensor.min_temp_forecast')}}"
        forecastdays: "{{state_attr('sensor.min_temp_forecast', 'forecastdays')}}"

In order for the forecast to be fetched correctly, the Weather entity must be configured. You can easily do this with the following instructions:

Instructions on how to setup your Weather platforms with Home Assistant.

Winter is coming, the automation ☃️

With the created sensor, we can therefore determine whether and, above all, when exactly and for how long it will freeze. We can then be notified or other things can be triggered automatically. You can use the following automation for this:

alias: "Frost Warning: Send Notification"
description: >-
  If frost is forecast in the weather forecast, then send out a notification
  so that the water is turned off.
  - platform: state
    entity_id: sensor.frost_warning
    from: "off"
    to: "on"
condition: []
  - service: notify.notify
      title: Winter is coming!
      message: >-
        From {{ as_timestamp(state_attr("sensor.frost_warning",
        "first_frost_date")) | timestamp_custom("%a, %d.%m.%y", True) }} it should
        freeze with temperatures up to {{ state_attr('sensor.frost_warning',
        'temp_low') }}°C on {{state_attr('sensor.frost_warning', 'frostdays') }}
        days in the coming {{state_attr('sensor.frost_warning',
        'forecastdays') }} days.
        priority: 1
mode: single

And from now on you will be notified when frost sets in 😊

Jon Schnee would be proud of you (or maybe not, because he no longer has to stand guard) 👏