Hi, I set up an NFC tag that opens an electric lock of a gate. I have declared in the automation the Device ids of the smartphones authorized to launch the automation. Now I would like to receive a notification on my iPhone when the tag is scanned with the indication of which device to the tag is scanned. Can you help me? For info post below the automation I did:
alias: Tag pedonale finale
description: ""
trigger:
- platform: event
event_data: {}
event_type: pedonale
context: {}
- platform: tag
tag_id: lknvnvkdsj2nkrfoòi398
device_id:
- 353537.........
- 9494094-.........
- 80E2B08E........
condition: []
action:
- service: switch.turn_on
data: {}
target:
entity_id: switch.esp_citofono_pedonale
- service: notify.mobile_app
data:
title: TAG PEDONALE
message: Tag attivato da {{ trigger.from_state.attributes.friendly_name }}
mode: single
This is a shot in the dark since I don’t use NFC and there isn’t any info in the docs about the trigger variable for Tag triggers… Maybe it follows the rules of the Event trigger, not the State trigger. If so, you would need to use that format for your template. You should be able to verify the available information from the trigger variable by sending yourself the full contents of the variable.
- service: notify.mobile_app
data:
title: TAG PEDONALE
message: >-
{{ trigger }}
mode: single
The following is what you would use with a tag_scanned Event trigger like that given in the Tags docs example:
- service: notify.mobile_app
data:
title: TAG PEDONALE
message: >-
{% set dev_name = expand(device_entities(trigger.event.data.device_id))
| selectattr('domain', 'eq', 'device_tracker')
| map(attribute='name') | join %}
Tag attivato da {{ dev_name }}
mode: single
Hi I was able to display a notification with the name of the person who scanned the tag using this code.
- service: notify.mobile_app
data:
title: TAG PEDONALE
message: '{% set person = states.person|selectattr(''attributes.user_id'', ''eq'',
trigger.event.context.user_id)|first %}{{ person.attributes.friendly_name
}}'
mode: single