To get a notification when a new device is discovered on my network I added the following to my Automations.
- alias: Notify when new device discovered
trigger:
platform: event
event_type: device_tracker_new_device
action:
- service: notify.telegram
data_template:
message: >
New device:
{{trigger.event.data.host_name}}
({{trigger.event.data.entity_id}})
title: New device
Unfortunately this is not working. The new device is being recognized but I do not get a notification. When I remove the {{trigger.event.data.entity_id}} it’s working correctly: I receive a message with the host name.
Is the attribute entity_id for this event broken with HA 0.75?
Thanks, but I am afraid that’s not going to help. In that thread the OP is looking for the attribute to get the entity_id. I know the attribute (according to the documentation): trigger.event.data.entity_id
Unfortunately it’s not giving back any data or maybe it even generates an error somewhere because the notification isn’t being send at all.
You need to look at the event response. Everything in the data section is dependent on the device that is created. This information will change between components. If entity_id is not returned in the event, that method will not work.
I recommend you turn info on in logging and look at the event data.
I mean, you could just use this method, but you may not always get an entity_id:
- alias: Notify when new device discovered
trigger:
platform: event
event_type: device_tracker_new_device
action:
- service: notify.telegram
data_template:
message: >
New device:
{{ trigger.event.data.host_name if trigger.event.data.host_name is defined else "NA" }}
({{ trigger.event.data.entity_id if trigger.event.data.entity_id is defined else "NA" }})
title: New device
Thanks for your reply! I will try this this evening.
Actually I wonder why there should not always be an entity_id for a newly discovered device. I cannot imagine a situation in which it can be empty. trigger.event.data.entity_id is a valid attribute according to the documentation and a lot of other examples.
It’s because you are using an event trigger. Event triggers do not contain entity id’s because they aren’t always there. Almost all other triggers contain an entity_id.
Again, that is dependent on the component being used. For example, a IOS device tracker may have different event data than a ASUS router device tracker. It all depends on the component being used. Apparently the component you are using doesn’t give entity_id inside the event data.
It hasn’t changed for a long time. And I don’t see that method being overridden in any device_tracker platform code. So it would appear that trigger.event.data.entity_id should be valid no matter which device_tracker platform is being used.
Of course, that doesn’t explain why it’s not working for you. You should do as @petro suggests and look in your HA log for that event and see what data is actually logged.
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: >
New device:
{{trigger.event.data.host_name}}
({{trigger.event.data.entity_id}})