App #7: Boiler Temperature Alert

Hello/Hallo/Hola :grinning:

New Example!

This automation is not final or complete, and probably there is a way to make more generic. My aim is to share examples that maybe can help new members starting with HA+AppDaemon.

Suggestions or recommendations to improve the implementation are welcome!

Predictive maintenance for domotics is as important as for big industries. We always want to system online and avoid breakdowns :grinning:

App #7: Boiler Temperature Alert
Notify me if the temperature of my boiler reaches more than three times X °C (e.g., 60) within a time window of an hour.

Entities
sensor.boiler_temperature

app.yaml

boiler_temperature_alert:
  module: boiler_temperature_alert
  class: BoilerTemperatureAlert  
  sensor: sensor.boiler_temperature

boiler_temperature_alert.py

import appdaemon.plugins.hass.hassapi as hass
from datetime import datetime, timedelta

class BoilerTemperatureAlert(hass.Hass):

    def initialize(self):
        self.log('initializing ...')
        self.times = []
        self.listen_state(self.on_temperature_change, self.args["sensor"])

    def on_temperature_change(self, entity, attribute, old, new, kwargs): 
        if int(new) > 60: # validate temperature condition
            if len(self.times) == 2: # check that we already enough temperature values
                oneHourAgo = datetime.now() - timedelta(hours= 1)
                if all(map(lambda t: t > oneHourAgo, self.times)): 
                    self.log("Sending notification ...")
                    # your notification

                self.times.insert(0, datetime.now()) 
                self.times = self.times[:2]  # remove the oldest time
            else:
                self.times.insert(0, datetime.now()) 
                self.log('Temperature > 60 but still not enough values to fire an alert')

Happy coding!
Humberto

Previous post: App #6: Window Alert
Next post: App #8: Detect a particular sequence of events

1 Like