Another struggler here - self.run_hourly

What I thought would be the simplest of automations so I am hoping for a quick fix.

import appdaemon.plugins.hass.hassapi as hass
import datetime
import time


class GarageUpReminder(hass.Hass):

  def initialize(self):
    self.sonos = self.get_app("Sonos")
    runtime = datetime.time()
    self.run_hourly(self.garage_up, runtime)

  def garage_up(self, kwargs):
    if (self.listen_state(self.args["entity"]) == 'on'):
      self.log("GARAGE DOOR IS UP REMINDER")
      self.sonos.tts("The garage roller door is not down", 0.5, 10)

Latest appdaemon version on Ubuntu 18/ Virtual Env

Error log showing nothing.

Logfile showing:

2018-10-10 10:35:06.484334 INFO AppDaemon: Currently busy threads: 0

2018-10-10 10:35:06.484589 INFO AppDaemon: Most used threads: 4 at 2018-10-10 09:28:05

2018-10-10 10:35:06.484751 INFO AppDaemon: Last activity: 2018-10-10 10:00:22

2018-10-10 10:35:06.484939 INFO AppDaemon: --------------------------------------------------

2018-10-10 10:35:06.485336 INFO AppDaemon: thread-1 - current callback: idle since 2018-10-10 10:00:22, alive: False

2018-10-10 10:35:06.485573 INFO AppDaemon: thread-2 - current callback: idle since 2018-10-10 10:00:05, alive: False

2018-10-10 10:35:06.485747 INFO AppDaemon: thread-3 - current callback: idle since 2018-10-10 09:59:49, alive: False

2018-10-10 10:35:06.485976 INFO AppDaemon: thread-4 - current callback: idle since 2018-10-10 10:00:05, alive: False

2018-10-10 10:35:06.486184 INFO AppDaemon: thread-5 - current callback: idle since 2018-10-10 10:00:05, alive: False

2018-10-10 10:35:06.486381 INFO AppDaemon: thread-6 - current callback: idle since 2018-10-10 10:00:00, alive: False

2018-10-10 10:35:06.486554 INFO AppDaemon: thread-7 - current callback: idle since 2018-10-10 10:00:22, alive: False

2018-10-10 10:35:06.486729 INFO AppDaemon: thread-8 - current callback: idle since 2018-10-10 09:59:49, alive: False

2018-10-10 10:35:06.486902 INFO AppDaemon: thread-9 - current callback: idle since 2018-10-10 10:00:05, alive: False

2018-10-10 10:35:06.487071 INFO AppDaemon: thread-10 - current callback: idle since 2018-10-10 09:59:53, alive: False

2018-10-10 10:35:06.487217 INFO AppDaemon: --------------------------------------------------

2018-10-10 10:35:46.638781 WARNING AppDaemon: Queue size is 4690, suspect thread starvation

2018-10-10 10:35:46.639091 INFO AppDaemon: --------------------------------------------------

2018-10-10 10:35:46.639250 INFO AppDaemon: Threads

2018-10-10 10:35:46.639436 INFO AppDaemon: --------------------------------------------------

2018-10-10 10:35:46.639643 INFO AppDaemon: Currently busy threads: 0

2018-10-10 10:35:46.639826 INFO AppDaemon: Most used threads: 4 at 2018-10-10 09:28:05

2018-10-10 10:35:46.640085 INFO AppDaemon: Last activity: 2018-10-10 10:00:22

2018-10-10 10:35:46.640386 INFO AppDaemon: --------------------------------------------------

2018-10-10 10:35:46.640835 INFO AppDaemon: thread-1 - current callback: idle since 2018-10-10 10:00:22, alive: False

2018-10-10 10:35:46.641133 INFO AppDaemon: thread-2 - current callback: idle since 2018-10-10 10:00:05, alive: False

2018-10-10 10:35:46.641442 INFO AppDaemon: thread-3 - current callback: idle since 2018-10-10 09:59:49, alive: False

2018-10-10 10:35:46.641696 INFO AppDaemon: thread-4 - current callback: idle since 2018-10-10 10:00:05, alive: False

2018-10-10 10:35:46.641952 INFO AppDaemon: thread-5 - current callback: idle since 2018-10-10 10:00:05, alive: False

2018-10-10 10:35:46.642212 INFO AppDaemon: thread-6 - current callback: idle since 2018-10-10 10:00:00, alive: False

2018-10-10 10:35:46.642476 INFO AppDaemon: thread-7 - current callback: idle since 2018-10-10 10:00:22, alive: False

2018-10-10 10:35:46.642777 INFO AppDaemon: thread-8 - current callback: idle since 2018-10-10 09:59:49, alive: False

2018-10-10 10:35:46.643187 INFO AppDaemon: thread-9 - current callback: idle since 2018-10-10 10:00:05, alive: False

2018-10-10 10:35:46.643560 INFO AppDaemon: thread-10 - current callback: idle since 2018-10-10 09:59:53, alive: False

your appdaemon died.
this has nothing to with this app but with something else that is wrong.
restart appdaemon and find out if you have looping of some kind in another app.

Also, the problem may well be in the Sonos app. Its a bit hard for Rene to debug your code for you when you only show him half of it :grinning:

1 Like

lol, yeah its hard to tell where an error is when i dont see it :wink:
but at least there is no problem with the shown part.

unless off course the self.sonos.tts causes a hanging thread, then after the amount of hours equal the amount of threads set in the appdaemon.yaml AD wil die.
but i dont suspect that, because then AD would have been dead for 4690 hours.

Is this function really correct?

def garage_up(self, kwargs):
    if (self.listen_state(self.args["entity"]) == 'on'):
      self.log("GARAGE DOOR IS UP REMINDER")
      self.sonos.tts("The garage roller door is not down", 0.5, 10)

I’ve never used AppDaemon, so I am just going by the docs and code implementation. listen_state is used to monitor state changes. It takes a callback function as the first parameter, not an entity, and returns a handle, not a state. It’s never going to return “on”/“off”. https://appdaemon.readthedocs.io/en/latest/APIREFERENCE.html#listen-state

Do you mean get_state?

1 Like

thanks @freshcoast i saw the title and just looked at the structure from run_hourly.

yeah that is absolutely wrong.
and i think you are correct that it should be get_state.

and i am absolutely sure that it will give an error in the errorlog. (unless AD was already dead at the time the app was created)

Thanks for the sanity check - it will only error when the app runs and the Sonos apps runs fine with other automations. Will try using the echos as a TTS device and see if that helps. Nothing in the error log as stated using listen_state, only the log with the thread starvation issue.

Thanks freshcoast also, will give the get_state a go

if you use stuff like this self.listen_state(self.args[“entity”]) you are creating hugh problems.
the thread starvation show that you do something terribly wrong in 1 of your apps.
every time you get thread starvation, the only way to get AD back running normal is to restart AD.

and it seems that you also use get_thread_info somewhere. which isnt something you want to use unless you are debugging. your log will fill up faster then you can read.
and i hope that you know that your errors are at another place? (unless you didnt specify where the errors should be shown, in that case your errors are just lost in the big load off info in the log)