Created
February 19, 2017 22:40
-
-
Save adrianlzt/f0c073dd163e4512510ca3d8fa91a4c2 to your computer and use it in GitHub Desktop.
Home Assistant, App Daemon module to monitor for stale sensors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import appdaemon.appapi as appapi | |
import homeassistant.util.dt as dt_util | |
# | |
# Notify stale sensors. | |
# Each minute last update of sensor is checked to see if it is higher than the configured value | |
# | |
# Args: | |
# sensor = sensor to monitor | |
# tiempo = minutes threshold to notify | |
# notify = comma separated list of notifiers | |
# | |
class StaleSensor(appapi.AppDaemon): | |
def initialize(self): | |
time = datetime.time(0, 0, 0) | |
self.run_minutely(self.check_sensor, time) | |
def check_sensor(self, kwargs): | |
now = dt_util.now() | |
sensor_last_updated_str = self.get_state(self.args["sensor"], "last_updated") | |
sensor_last_updated = dt_util.parse_datetime(sensor_last_updated_str) | |
tiempo = int(self.args["tiempo"]) | |
stale_time = now - sensor_last_updated | |
if stale_time.seconds > tiempo*60: | |
print("Se ha pasado de tiempo") | |
for notifier in self.args["notify"].split(","): | |
self.notify("Sensor {} is stale for {}".format(self.args["sensor"], stale_time), title="Sensor without updates", name=notifier) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment