Frost warning with Home Assistant 🥶
Published: 2024-01-10 19:02:58

![](https://blog.disane.dev/content/images/2024/01/frost_warning-with-home-assistant_banner.jpeg)Do you have a garden and want to be notified when winter is coming? I'll show you how easy it is 🏡

---

Every garden owner will know the problem: _Winter is coming._

![](https://blog.disane.dev/content/images/2023/12/image.gif)

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:

```yaml
- platform: template
  sensors:
    frost_warning:
      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 %}
            on
        {% else %}
            off
        {% endif %}
      attribute_templates:
        frostdays: >-
          {% set ns = namespace(frostdays=0) %}
          {%- for fc in states.weather.CHANGE THIS.attributes.forecast -%}
              {%- if fc.templow < 0 -%}
                  {%- set ns.frostdays = ns.frostdays + 1 -%}
              {%- endif -%}
          {%- endfor -%}
          {{ns.frostdays}}
        first_frost_date: >-
          {% set ns = namespace(date=0) %}
          {%- for fc in states.weather.CHANGE THIS.attributes.forecast -%}
              {%- if fc.templow < 0 and ns.date == 0 -%}
                  {%- set ns.date = fc.datetime -%}
              {%- endif -%}
          {%- endfor -%}
          {{ns.date}}
        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:

[Weather![Preview image](https://www.home-assistant.io/images/default-social.png)Instructions on how to setup your Weather platforms with Home Assistant.](https://www.home-assistant.io/integrations/weather/)

![](https://blog.disane.dev/content/images/2023/12/image-1.gif)

## 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:

```yaml
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.
trigger:
  - platform: state
    entity_id: sensor.frost_warning
    from: "off"
    to: "on"
condition: []
action:
  - service: notify.notify
    data:
      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.
      data:
        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) 👏

![](https://blog.disane.dev/content/images/2023/12/image-2.gif)

---

If you like my posts, it would be nice if you follow my [Blog](https://blog.disane.dev) for more tech stuff.