Finding new devices - device tracker events not working?

Hi all,

For ages I have had the following automation that alerts me if a new device is added to my LAN:

  - alias: System - New device connected
    initial_state: true
    trigger:
      - platform: event
        event_type: device_tracker_new_device
    action:
      - service: notify.pb
        data_template:
          message: >
            New device:
            {{trigger.event.data.host_name}}
            ({{trigger.event.data.entity_id}})
            Mac: {{trigger.event.data.mac}}
          title: Home Assistant

I have noticed it no longer works.

Looking at my known_devices.yaml it seems this hasn’t been updated since August 5th. I know new devices are being picked up as in states I can see them.

The following is my device_tracker.yaml:

#NMAP
  - platform: nmap_tracker
    new_device_defaults:
      track_new_devices: true
    hosts:
      - xx.xx.xx.xx/24

I also track unifi direct from my configuration.yaml file.

Am I missing anything?

Thanks

mb

known_devices.yaml has been deprecated for some time, and as integrations are updated they’ve stopped using it.

1 Like

So is there a different event to track now? As I was triggering an alert on the event.device_tracker_new_device ?

Thanks

mb

Don’t know about the events I’m afraid

No worries thanks

just had a quick test here, but my Nmap scanner still adds to the known_devices.yaml just perfectly.

The notification belonging to the add has indeed stopped, to exact: 6 days ago:-)

this must have been after the systems update to 102.2

33

1 Like

I’ve been searching for an answer to this with no luck - does anyone have a way to get a notification for a new device on the network (specifically for the unifi controller integration) now that known_devices is going away?

A friend of mine has worked out something in Node Red - I think once it is worked out perfectly he will share here.

My friend has sorted it out:

It works like a charm. I have the script on my Node Red server (it is separate from my HA server) and from within NR run it every 5 mins using the script node.

What it does is the first time it runs a full scan and populates a list of all network devices (bit like the old known_devices.yaml is suppose). Then every 5 mins it runs again and compares the output against this file and pipes out any new devices.

[{"id":"8297d552.5ccb3","type":"exec","z":"9072b774.d4ad9","command":"python /root/network-monitor/network-monitor.py","addpay":true,"append":"","useSpawn":"false","timer":"120","oldrc":false,"name":"Check Net","x":330,"y":640,"wires":[["53c115f7.d3878c","327184a0.03ae0c"],[],[]]},{"id":"819a2d52.30ea18","type":"inject","z":"9072b774.d4ad9","name":"","topic":"","payload":"","payloadType":"date","repeat":"900","crontab":"","once":true,"onceDelay":0.1,"x":130,"y":640,"wires":[["8297d552.5ccb3"]]},{"id":"53c115f7.d3878c","type":"switch","z":"9072b774.d4ad9","name":"","property":"payload","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":620,"wires":[["80753070.cd63e8"]]},{"id":"80753070.cd63e8","type":"function","z":"9072b774.d4ad9","name":"","func":"msgtext = msg.payload;\nmsg.payload = {\"data\":  {\"title\": \"New Network Device Alert\",\"message\": msgtext,\"data\":{\"push\":{\"sound\":{\"name\":\"default\"}}}}};\nnode.status({fill:\"green\",shape:\"ring\",text:msgtext});\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":620,"wires":[["8bd96b1f.c14828"]]},{"id":"8bd96b1f.c14828","type":"api-call-service","z":"9072b774.d4ad9","name":"iOS Mark","server":"d8c83d48.4dc3f","version":1,"debugenabled":false,"service_domain":"notify","service":"ios_mark_iphone_8_plus","entityId":"","data":"{}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":840,"y":600,"wires":[[]]},{"id":"327184a0.03ae0c","type":"debug","z":"9072b774.d4ad9","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":490,"y":560,"wires":[]},{"id":"d8c83d48.4dc3f","type":"server","z":"","name":"HA","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

I hope that helps anyone - I cannot take credit for the code, and it seems to work perfectly for me in NR. I am sure the script can be as an automation in HA too.

cheers

mb

2 Likes

Is it really impossible nowadays to alert on new devices when using the nmap tracker in HA (other than that that node red app)?

try:

automation:

##########################################################################################
# System automation
##########################################################################################

  - alias: New Device Tracked
    id: New Device Tracked
    trigger:
      platform: event
      event_type: device_tracker_new_device
    condition: []
    action:
      service: persistent_notification.create
      data_template:
        title: >
          Newly tracked: {{trigger.event.data.entity_id}}
        message: >
          New device tracked: ({{trigger.event.data.entity_id}})
          Host: {{trigger.event.data.host_name}}
          Mac-address: {{trigger.event.data.mac}}
          Data: {{trigger.event.data}}
1 Like

Thanks, it’s working perfectly.

fwiw, you can leave out the last line in the message
Data: {{trigger.event.data}}.
I’ve only put that there, to see which data(fields) are in the full event, so I could template the necessary ones in the final message.

glad you got it working

1 Like

I can’t seem to get this to work. Here’s a copy of the automation from my automations.yaml file.

In my case, the new device is coming from the smartthings integration. And to get the new device to show up in HA, I have to restart the HA server (not the OS)

- id: '4'
  alias: Marius New Device Tracked
  trigger:
    platform: event
    event_type: device_tracker_new_device
  condition: []
  action:
    service: persistent_notification.create
    data_template:
      title: >
        Marius Newly tracked: {{trigger.event.data.entity_id}}
      message: >
        New device tracked: ({{trigger.event.data.entity_id}})
        Host: {{trigger.event.data.host_name}}
        Mac-address: {{trigger.event.data.mac}}
        Data: {{trigger.event.data}}