Trigger notification based on condition between inside and outside temperature but only trigger once

All, the idea is simple. Sometimes you have a very hot day. My house is good at keeping itself cold but only if i close all doors/windows. Eventually the temperature will go up but less then outside during the daytime. When it is dark the outside temperature is lower then inside so i need to open the windows again.

I would like to compare 2 temperature values with eachother, report if i have to close or open the windows/doors based on that compare. But the trick here is that i only want to be notified once when the temperature ‘flip’ happens.

{% if states('sensor.average_house_temp') >= ('sensor.weather_temperature') %}
  It is hotter outside ({{ states('sensor.weather_temperature') }}) then inside ({{ states('sensor.average_house_temp') }}), close windows and doors
  **some magic send notification and don't repeat next time**
{% else %}
  It is cooler outside ({{ states('sensor.weather_temperature') }}) then inside ({{ states('sensor.average_house_temp') }}), open windows and doors
  **some magic send notification and don't repeat next time**
{% endif %}

This works, that is part one. But i presume i need to set another sensor to know if a notification was sent. But should i use a template, or perhaps have a input_boolean (so i can turn it on again too if i want too) or should i use condition template. There are more roads to choose from.

If anyone has something similar that would help a lot too. This could also be helpfull for people to turn on the AC or something similar (although those would just work on a temperature value on its own) but you get the idea.

Thanks.

I would suggest creating a template binary sensor. You can watch that for state changes (it will change to True or False only once. And use an alert instead of an automation.

binary_sensor:
  - platform: template
    sensors:
      warm_inside:
        friendly_name: "Inside temperature higher than outside"
        value_template: "{{ states('sensor.average_house_temp') >= states('sensor.weather_temperature') }}"

alert:
  warm_inside:
    name: "Inside temperature higher than outside"
    done_message: "Inside temperature lower than outside"
    entity_id: binary_sensor.warm_inside
    state: 'on'
    notifiers:
      - notify
2 Likes

Thanks appreciate the full config! Only was missing the required “repeat” but found that in the docs.

But this does mean you need to acknowledge the alert otherwise it will keep on repeating. The idea would be to just have 2 alerts a day (hotter/colder) and during winter times this would never happen.

For other people to find too, using this for my average house temperature:

average_house_temp:
  friendly_name: 'Average House Temp'
  unit_of_measurement: "°C"
  value_template: >-
    {{ (float(states('sensor.thermostaat_erik_temperature')) + float(states('sensor.motion_berging_temperature')) + float(states('sensor.motion_entree_temperature')) + float(states('sensor.motion_gang_1e_temperature')) + float(states('sensor.motion_gang_2e_temperature')) + float(states('sensor.motion_gang_begane_grond_temperature')) + float(states('sensor.motion_keuken_temperature'))) / 7 | round(2) }}

Also noticed that:
image
did not trigger an alert.

The added value of the binary sensor is that you can use it as a trigger or condition in any future automation. Like turning on or off a fan or climate device.

That is indeed nice. It just now triggered back, but no push message. Am I missing something?

Ignore that, just got one. Forgot the repeat interval.

This is great, but now I bother my wife every 30 minutes. I’ve tried to make the alert acknowlegeable, and have successfully set up a button in the push notification, but the binary sensor doesn’t get set to idle. How can I tweak my code?

alert:
  warm_inside:
    name: "It's nice out, OPEN the window!"
    entity_id: binary_sensor.warm_inside
    state: "on"
    repeat: 30
    can_acknowledge: true
    data:
      actions:
        - action: "DONE"
          target:
            entity_id: binary_sensor.warm_inside
          title: "Windows opened"
    notifiers:
      - notify