Unifi Device Tracker - Notification of New Device

I have recently switched over to Unifi Presence Detection via integrations and has been working well so far. Prior to the move I was using Nmap and it notified me when a device was added to the network via tts and ios using the following app.

> class NewDeviceNotify(hass.Hass):
>   def initialize(self):
>     self.listen_event_handle_list = []
>     self.listen_event_handle_list.append(self.listen_event(self.newdevice, "device_tracker_new_device"))
>   def newdevice(self, event_name, data, kwargs):
>     self.log("NEW DEVICE ADDED")
>     self.log("DATA: {}".format(data))
>     self.call_service(globals.notify_ios_grant, title = "Device Added to HA", message = "Device {} has been added to HA".format(data))
>     self.call_service("notify/alexa_media", target = ["media_player.kitchen_alexa","media_player.study_alexa"], message = "A new device has been added to the network", data = {"type":"announce"})
>   def terminate(self):
>     for listen_event_handle in self.listen_event_handle_list:
>       self.cancel_listen_event(listen_event_handle)

Under the new integration, no new devices are written to the know_devices.yaml anymore as part of Unifi. Instead they are written directly to the entity_registry. I assume this is why the app wont work anymore? Is there a way around this?

There is an event from entity registry you could listen to,

self.hass.bus.async_fire(EVENT_ENTITY_REGISTRY_UPDATED, {“action”: “create”, “entity_id”: entity_id})

EVENT_ENTITY_REGISTRY_UPDATED = “entity_registry_updated”

It is a quite generic signal but you can at least see if something has changed

1 Like

Thanks Robban, will check it out

Have you figured out how to do this? Unfortunately I don’t understand your script (Java Script I believe? Which I don’t know), so I cannot try and/or modify it myself.

I’d like to be alerted via Telegram whenever a new devices joins the network. Is this possible? Thank you :slight_smile:

This is the AppDaemon category. This script is in Python and you can’t just use/modify this script within Home Assistant, you need to have AppDaemon installed for this.

I recently upgraded to the new unifi integration and had the same problem.
I updated my appdaemon app to support the event @Robban mentioned above.

You can find the code under https://github.com/eifinger/appdaemon-scripts/blob/8fc61aba63cb85baf973d3083a04a5e0e1d2af70/newWifiDeviceNotify/newWifiDeviceNotify.py