Notification for new devices

Hi,

I have an automation to notify me if new devices are found:

- alias: Notify for new devices
  trigger:
    platform: event
    event_type: device_tracker_new_device
  action:
    - service: notify.html5
      data_template:
        message: >
          New device:
          {{trigger.event.data.host_name}}
          ({{trigger.event.data.entity_id}})
        title: New device

… and it works. However what I would actually like is to get notifications only when a new device connects to the wifi, but not when the bluetooth tracker finds a new device. I would still like to have track_new_devices True for bluetooth.

So my question is, would it be possible to implement this? I guess it would require adding the name of the platform seeing the device to the dictionary attached to the device_tracker_new_device event but I couldn’t find out how to get the platform name …

6 Likes

Try:

trigger.event.data.source_type

Thanks. While this attribute currently doesn’t exist, adding it would probably indeed achieve what I want, since the bluetooth tracker has source_type='gps' while the wi-fi one has source_type='router'.

However I am actually wondering whether this behaviour is correct. Looking at the relevant PRs, the way I understand the purpose of the source_type attribute, wouldn’t it make more sense for the bluetooth tracker to be 'router' as well?

Another hack that came to my mind was adding the device.mac and checking in the automation whether it starts with BT_, but having the actual platform name would still be much nicer.

A bit off topic here, but was looking for a bit of help/advice. For your “data_template”, is that pre-established using another .yaml or are they built in?

Hi, not sure what you mean. The snippet should work standalone. The trigger.event.data.host_name and trigger.event.data.entity_id are existing attributes of the device_tracker_new_device event.

I know it’s old but trying to have it working with notify.pushbullet service but it just doesn’t work… the problem is with message. Do you know how should it be written to work?

  - alias: Notify for new devices
    trigger:
      platform: event
      event_type: device_tracker_new_device
    action:
      - service: notify.pushbullet
        data:
          title: "New device"
          message: "New device: something"

it works but message:
message: >
New device:
{{trigger.event.data.host_name}}
({{trigger.event.data.entity_id}})

doesn’t work. What do you think?

solved.