Send notifcation of IP + hostname when a new device is added

So I wanted to share something I couldn’t find fully completed, and is a pretty cool feature I’ve been wanting myself: whenever I connect a new device to the network (e.g. smart wifi device, rpi, etc) I receive a notification on the HA companion app.
Previously I had to log in to the router or HA to see the device’s IP, thats sooo 2020.

An added bonus is the added feeling of security of getting a notification when a new device connects.
(improvement would be to add actionable notifications with block/allow option)

This automation notifies on new device_tracker entries in the registry and sends a notification when its a creation. In my situation, my device_trackers are added via MIkrotik Router integration and the attributes ip and host_name are automatically added. I can imagine other router integrations can also do this. YMMV

alias: Send notification of new network device
trigger:
  - platform: event
    event_type: entity_registry_updated
    event_data:
      action: create
condition:
  - condition: template
    value_template: '{{trigger.event.data.entity_id.split(''.'')[0] == ''device_tracker'' }}'
action:
  - service: notify.mobile_app_sm_g973f
    data:
      title: >-
        devie added to network:
        {{state_attr(trigger.event.data.entity_id,"host_name")}}
      message: >-
        Host [{{state_attr(trigger.event.data.entity_id,"host_name")}}] with IP
        [{{state_attr(trigger.event.data.entity_id,"ip")}}] was added to the network
initial_state: true
mode: parallel
6 Likes

Thanks for sharing this! The script does alert me when a new device is connected to my Asus router, however the message isn’t clear as to what device it was. Here is the output I received:

device added to network: None
Host [None] with IP [None] was added to the network

Any idea of where I might start to trouble shoot this to get the correct Device name and IP?

Do you see the hostname and ip in the dev options, afterwards?

Sometimes it takes another update event to get the extra info on the device registered in my case

Is there anyway to still do this? My understanding is the entity_registry_updated event is no longer fired for new device_trackers.

Mine still works i think? Last one couple of weeks ago

Confirmed it still works, had a guest haha