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}})