Notification when new devices discovered

I would like to create an automation that sends me a notification when a new device is detected over a specific integration (the router integration). I searched the blueprints and didn’t find anything so far.

I guess the trigger should be an event, but I struggle to define it.

What is this router integration?

This is an automation I use (found on here a while back) for new unifi device_trackers, maybe you can modify this ?

- alias: New network device registered
  id: New device registered
  mode: queued
  trigger:
    platform: event
    event_type: entity_registry_updated
    event_data:
      action: create
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'device_tracker' }}"
      - condition: template
        value_template: "{{ not (trigger.event.data.entity_id.split('.')[1].startswith('unifi_') and trigger.event.data.entity_id.split('.')[1].endswith('default')) }}"
  action:
    - delay: "00:01:00"
    - variables:
        entity: >
          {{trigger.event.data.entity_id}}
    - service: system_log.write
      data:
        message: >
          New device registered: {{state_attr(entity,'friendly_name')}} - {{state_attr(entity,'entity_id')}}
        level: info
        logger: homeassistant.components.device_tracker
    - service: persistent_notification.create
      data:
        title: >
          New device registered: {{state_attr(entity,'friendly_name')}}
        message: >
          Entity: {{entity}}
          Host: {{state_attr(entity,'host_name')}}
          IP: {{state_attr(entity,'ip')}}
          MAC: {{state_attr(entity,'mac')}}
1 Like

it’s the custom OPNsense intregration from @travisghansen .

Nice, thanks, I will have a look and try to make it works with the opnsense custom integration.

This code used to work fine for me but now it gives me the following error:

Error while executing automation automation.aviso_dispositivo_nuevo_conectado: Error rendering data template: TypeError: state_attr() missing 1 required positional argument: ‘name’

Error executing script. Error for call_service at pos 2: Error rendering data template: TypeError: state_attr() missing 1 required positional argument: ‘name’

Any ideas? thank you.

Can you post your automation ?