Appdaemon "state update"

HI!

Looking for a method for appdaemon to detect state update.
Some background:
Have several wireless temperature sensors reporting in approx 5 minute intervals.
Appdaemon then updates HA with the temperature of the sensor.
If temp sensor doesn’t report in, HA still shows the latest temperature it received from appdaemon which could be hours old.
Therefore need a method to detect if sensor state hasn’t been updated (not changed) within a given period. This then allows me to trigger an alarm.
Can someone suggest a method I could use to see if state has been updated in HA?

Thanks,

Rob.

so you say appdaemon gets the value and updates it on HA?

then why look at HA for the last update :wink:

in the app that updates the sensor from HA create a last updated variable in the initialize
use a run_every (5 minutes) to check if the variable has a time longer then 5 minutes ago
if so send a notify.

Hi Rene,

And thanks for the fast response.
Yes correct, appdaemon updates HA

Hmm…okay need to think about that one.
“in the app that updates the sensor from HA create a last updated variable in the initialize”
little snippet of code would be handy here…
Not sure what gets returned, bu do you think get_state could also do the trick?

Rob.

i would create it like this:

import datetime
initialize(...):
  self.last_update = datetime.datetime.now()
  start_time = datetime.datetime.now()
  self.run_every(self.check_if_updated,start_time,"5*60")
  #do your normal init part

  def check_if_updated(self,kwargs):
    actual_time = datetime.datetime.now()
    time_gone_by = actual_time - self.last_update
    if time_gone_by > datetime.timedelta(seconds=310):
      self.notify(...)

at the place where you update the sensor in HA you put this line after it:

  self.last_update = datetime.datetime.now()
1 Like

Or you could just use the timer itself as the flag


def initialize(self):
   self.timer_handle = self.run_in(self.send_alarm, 5*60)

def send_alarm(self):
   #send notification


Then when you update the status do

  self.cancel_timer(self.timer_handle)
  self.timer_handle = self.run_in(self.send_alarm, 5*60)
3 Likes

Thanks all,

Was rattling my brain on this one…But now so obvious and beautifully simple!

Rob.

1 Like