Frost warning with Home Assistant 🥶

Marco - Jan 10 - - Dev Community

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.

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
  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')}}"
Enter fullscreen mode Exit fullscreen mode

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

Preview image

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.
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
Enter fullscreen mode Exit fullscreen mode

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) 👏


If you like my posts, it would be nice if you follow my Blog for more tech stuff.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player