Ok I promise I’m not trying to bomb out the forum today.
So problem #2 for me today. While researching how to track an unchanged state I found this example here
which I took and set it up for what I needed it to do as
import appdaemon.appapi as appapi
import homeassistant.util.dt as dt_util
import datetime
#
# 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
# minute = 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["sensorID"], "last_updated")
sensor_last_updated = dt_util.parse_datetime(sensor_last_updated_str)
minutes = int(self.args["minutes"])
stale_time = now - sensor_last_updated
if stale_time.seconds > minutes*60:
self.log("The power meter hasn't updated in a while so we're going to restart it")
self.turn_off(self.args["switchID"])
self.run_in(self.switch_on_function, 5)
def light_off(self,kwargs):
self.turn_on(self.args["switchID"])
I have an aeon lab energy meter that occasionally throughout the day just decides it no longer wants to report so the fix is I stuck a leviton zwave plug module on it and I turn that off and back on. In ST I was monitoring the value for it to remain the same over 4 mins. Problem is that I get a lot of false positives where the energy usage value has changed but the reading from 4 min ago vs now is actually the same. So the fix is turn it off for 5 seconds and then back on.
My hope is that with appdaemon I can do this a little more graceful and this code example looked like it would do the trick. But HA complains about this
import homeassistant.util.dt as dt_util
I’m guessing that either HASSIO doesn’t know how to import that or its been deprecated with HASSIO and there is possibly another library that I can utilize instead to accomplish what this library was accomplishing. Thank you for your help with this and if there is a better api reference for a value unchanged and I just can’t find it in the docs please feel free to slap me around, as I am def not trying to waste ones time with simple things although I’m sure that others might have a need for monitoring a value that isn’t changing.