adonno / tagreader

Simple to build/use NFC tag reader, specially created for Home Assistant
https://adonno.com
GNU General Public License v3.0
1.13k stars 176 forks source link

Homeassistant read ANY tag #193

Closed IAmTheMilkManMyMilkIsDelicious closed 1 year ago

IAmTheMilkManMyMilkIsDelicious commented 1 year ago

This is probably more of a homeassistant question than the tagreader itself. But does anyone know how I could create an automation that is triggered by reading any tag?

I can make a trigger in my automation for a specific tag such as:

platform: tag
tag_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

But what I'd like to do is a trigger on any tag (even unknown tags). Then a condition will check if the scanned tag is equal to a specific tag and do an action, otherwise send me a notification that an unknown tag was scanned.

Has anyone implemented something like this?

luka6000 commented 1 year ago

you can do this by triggering homeassistant.event service instead of homeassistant.tag_scanned. Look at the code how it’s done for music_tags and just modify it for uid scanned tags as needed. This would be breaking change for adonno reader so it’s probably not going to happen here.

Mindsgoneawol commented 1 year ago

I had tags triggering automationsto play movies on roku media player from jellyfin integration up until I updated to this last esphome version. Can't seem to fix this issue. (was fun while it lasted lol)

luka6000 commented 1 year ago

I had tags triggering automationsto play movies on roku media player from jellyfin integration up until I updated to this last esphome version. Can't seem to fix this issue. (was fun while it lasted lol)

This issue is a feature request so this never worked in tagreader. Your video automations probably can be switched to tags scanned with tagreader and will work just fine.

adonno commented 1 year ago

not sure i'm following, what is it you want to do exactly since at first you want to trigger an automation based on any tag and then you talks about movies playing issues ?

IAmTheMilkManMyMilkIsDelicious commented 1 year ago

I was the original poster and I have solved my issue which was creating an automation that can read any tag. Here is an example of the automation yaml:

This automation runs a script if the tag is is xxxx..., a different script for yyyy... and finally a notify script when an unknown tag is scanned.

alias: Tag Scan
description: ""
trigger:
  - platform: event
    event_type: tag_scanned
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {% set data = trigger.event.data %} {{ data.tag_id ==
              "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" }}
        sequence:
              - service: script.xxx_tag_scan_script
                data: {}
      - conditions:
          - condition: template
            value_template: >-
              {% set data = trigger.event.data %} {{ data.tag_id ==
              "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy" }}
        sequence:
              - service: script.yyy_tag_scan_script
                data: {}
    default:
      - service: script.notify_invalid_tag
        data_template:
          input_text: |-
            An unknown NFC key was used!
            ID: {{ trigger.event.data.tag_id }}
mode: single
Mindsgoneawol commented 1 year ago

The issue was esphome. Updating it to I think it was 10.0.0 buggered the tagreader. The tagreader would read the tag but home assistant wasn't seeing the tag scanned. After many attempts I managed to get esphome to roll back to 8 something (last backup), delete any pieces of the tagreader I could find, and reflash all the readers I put together. Now its all back up and working. I backed up everything, then updated esphome to 10.1 and it seems to be working fine. Not sure what happened.