AppDaemon does not see new entities till module is reloaded

I tried searching here but couldn’t find anything relevant. A bit surprised as I can’t be the only one.

I am creating a Dynamic Group module in Hassio using AppDaemon. All works well except the module doesn’t see any new entities added by, for example nmap till the module is reloaded. (reboot, or touch the module python file) .

I hope this is something small that I missed. Any pointers would be appreciated.

what version from HA and AD do you use?
what does the app look like?

i think your trigger might be the problem.

I am using Hassio 0.71.0 with the addon 1.2.0 (AppDaemon 3.x) .
My code is based on Wildcard Group here

Thank you.

that app has only an initialise function.
so thats why it only starts once, when AD is started.

you have to change the app if you want it to be triggered by something else.
you could create a manual restart with an input_boolean and then use a listen_state for it, or you could try to find an event you can listen to with listen_event.
i dont know if there is a new entity event or something like that, thats something you should need to find out in that case.

Thank you Rene. I am totally new to this. Will look into this.

then maybe it might help to read the beginners guide

thank you Rene! Also realized that you are the one wrote the Wildcard group code. : )
I added the following to the code, but currently, I do not have new devices to connect to my wifi.
self.listen_state(self.AutoGenGroup, "device_tracker", new = "home")

Thanks a lot

i dont know if that what you want.
now the group gets reloaded whenever ANY devicetracker gets home.

but if its new devicetrackers you want to track then you can do the following:

self.listen_state(self.AutoGenGroup, "group.all_devices")

that group is an autogenerated group in HA and with that you will recreate your groups any time there is a change in the device list.

I should have explained myself better: I often have Airbnb guests at home so the device_tracker list changes frequently. I want to know who is home/away, by using the bluetooth tracker for my wife and myself and NMAP for others.

That’s why wildcard group is perfect for it. so, is group.all_devices what I need? isn’t this including a lot more than necessary?

Thank you very much

oke if you want to know who is home then listening to the group isnt an option.

in that case you could use what you have, but i would remove the new= “home”
you want the group also updated when someone goes away
be carefull to set your nmap tracking with enough delay.
you dont want to get the group updated several times a minute.

I finally got it working exactly how I wanted.
Now I have an inclusion and exclusion list. Also if a device that hasn’t been updated for more than 24 hours then it is no longer in the group list (guest has left).

Thanks for all your help Rene. Love AppDaemon.

1 Like

spoke too soon. New guests arrived, entities created but the module didn’t get reloaded. I had to touch the file to trigger the reload.

Any ideas why? currently I have:
self.listen_state(self.AutoGenGroup, “device_tracker”)

the new devices are not in the AD device list at that time, so a state change for those items isnt recorded.
i really think you need to listen to the “group.all_devices” because that is an existing group and a new device is automaticly added there so the attribute state from that is changed and that will trigger a state change.

Make sense. Revised the code. Will report back when I have a new device. Thanks Rene.

1 Like

well, it didn’t work. group.all_devices also does not update/call the function. the group list has not been updated for 2 days. As soon as I touch the py file it worked.
Maybe I’ll just use a timer.

hmm, strange, i would suspect that there is a change in that group.
but if you can live with a delay then you can use run_every or run_hourly or run_minutely.
dont set the timeframe to short because else it will kill your performance. :wink:

maybe something I am not doing it correctly. The hourly run did not work either.
would you mind taking a look? here is how I set it up.

def initialize(self):
self.listen_state(self.AutoGenGroup, “group.all_devices”)
runtime =
self.run_hourly(self.AutoGenGroup(), runtime)

if you look at your errorlogs then you see you have errors.

listen_state needs a callback that takes several args. like this:

def what_we_want_to_do (self, entity, attribute, old, new, kwargs):

and run_hourly takes less args, like this:

def what_we_want_to_do (self, kwargs):

you cant use 1 type of callback for both, then it will give errors that to much or to few args were given.
also a callback doesnt contain () when it is called, so not:

self.run_hourly(self.AutoGenGroup(), runtime)


self.run_hourly(self.AutoGenGroup, runtime)

if you want to learn how to program things, the first thing you need to learn is to check your logs, when you make changes. if you do something wrong it will always show up in your logs and you can learn from what it says there.
if you dont know how to check your logs or where they are then i am glad to help.

edit: 1 other remark:
run_hourly takes a time object and not a datetime object.
from the docs:

# Run every hour, on the hour
import datetime
runtime = datetime.time(0, 0, 0)
self.run_hourly(self.run_hourly_c, runtime)

I do check my logs and see no errors that why I assumed that everything was working.
corrected a few things and will see if this works:

from datetime import datetime
def initialize(self):
      self.listen_state(self.AutoGenGroup, "group.all_devices")
      runtime =
      self.run_hourly(self.AutoGenGroup, runtime.time())

and my appdaemon config:
logfile: /config/appdaemon.log
errorfile: /config/appdaemonError.log

do you get anything at all in your logs?
are the logs automaticly created when you restart AD?

this must definitly give errors and when you dont have them, i assume there is a problem with your logfiles.