Did it freeze last night?

So, this morning I went to drive my kid to school. We were a bit late. When I stepped out the front door I saw that the windshield of my car had frozen over. So Home Assistant to the rescue, to give me a heads-up not to take that second cup of coffee but to go outside to defrost the car.
My approach would be:

  1. Create a boolean flag “did it freeze last night”
  2. Automation 1: set flag to off at midnight
  3. Automation 2: if temp below +3° C between 0:01 and 7:00 then set flag to on
  4. Automation 3: at 7:15, if flag = on then notify

So my question to you: Is this the “cleanest” way to do this?
Perhaps there is a way to have a single automation with a condition “has temp been below +3° C in the last x hours”, which runs at 7:15?

Thx

You can’t use a traditional automation here as what does it do if it’s already below 3 degrees at midnight. 3 degrees is quite a long way from freezing too.
You have two options both involve 3 objects - an automation and your input_boolean being common to both
The last item could be a boolean sensor or a script either one would check your time conditions and determine outcome.
I’d favour a script as that could also turn off your flag at midnight

Your suggestion actually does what you want is understood by you and is thus maintainable, I don’t think the persuit of ‘one automation’ to cure all ills, is desirable.

1 Like

Thanks for your time Mutt.
Reason I asked is to learn new stuff, and to adhere to the KISS principle.
I was actually wondering if there is a way for an automation to look at historical data.
Probably you are right, best to build it like I laid out, and then see what the future holds :slightly_smiling_face:

I don’t think there is a way to look at historical data, (but I’m quite amenable to be proved wrong :smiley: ).
You might be able to do it with the statistics addon but I’ve not played with that, perhaps @petro might be able to give you some pointers ? Else I’ve seen the guy who wrote it around sometimes (but can’t remember his name :flushed: )

Edit: not sure any of what I said counts as a solution :man_shrugging:

numeric conditions do not support triggers, but state conditions do.

Make a binary_sensor template:

binary_sensor:
- platform: template
  sensors:
    below_3_degrees:
      value_template: >
        {{ states('sensor.xxxxx') | float < 3 }}

Then

trigger:
- platform: time
  at: '07:15:00'
condition:
- platform: state
  entity_id: binary_sensor.below_3_degrees
  state: 'on'
  for:
    hours: 3
action:
- service: notify.notify
  data:
    message: "It's cold"

EDIT and if you want to add your little ‘hey it was 3 degrees at midnight bs’

input_boolean:
  was_3_at_midnight:
trigger:
- platform: time
  at: "00:00:00"
action:
- service_template: >
    input_boolean.turn_{{ 'on' if states('sensor.xxxxx') | float < 3 else 'off' }}
  entity_id: input_boolean.was_3_at_midnight
trigger:
- platform: time
  at: '07:15:00'
condition:
- platform: state
  entity_id: binary_sensor.below_3_degrees
  state: 'on'
  for:
    hours: 3
- platform: state
  entity_id: input_boolean.was_3_at_midnight
  state: 'on'
action:
- service: notify.notify
  data:
    message: "It's cold"
1 Like

Petro, not sure this fills the requirements as he wants a notification @ 07:15 if it was below 3° at ANY time between 00:01 and 07:00 that morning (even if it was just for 1 minute)

1 Like

Ok, then also add:

sensor:
  - platform: history_stats
    name: below 3 today count
    entity_id: binary_sensor.below_3_degrees
    state: 'on'
    type: count
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'

and

- condition: numeric_state
  entity_id: sensor.below_3_today_count
  above: 0
1 Like

sorry, it took a while for me to get around to test this, but for me it does what it needs to do, so thanks both for your assistance!