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

Tag id with special characters is badly forwarded to HA #140

Closed tetienne closed 2 years ago

tetienne commented 2 years ago

Hi,

On an NFC card, I set the the Tag ID to: Various%20Artists/Les%20100%20plus%20belles%20chansons%20Disney%20%5b2018%5d/4.13%20-%20Hakuna%20Matata%20(de%20_le%20Roi%20Lion_).mp3

The purpose is to use it the tag id in an automation:

id: 0a58a4d4-600f-402a-98dc-
alias: NFC card to music
trigger:
  - platform: event
    event_type: tag_scanned
condition: "{{ trigger.event.data.tag_id is match('.*[mp3,flac]$') }}"
action:
  - service: media_player.play_media
    target:
      entity_id: media_player.salle_tv
    data:
      media_content_id: "x-file-cifs://192.168.2.8/musique/{{trigger.event.data.tag_id}}"
      media_content_type: music

When reading the card with the HA companion app, everything works well.

But the NFC tag reader I received from Adonno forward to HA the following tag id: Various%2520Artists/Les%2520100%2520plus%2520belles%2520chansons%2520Disney%2520%255b2018%255d/4.13%2520-%2520Hakuna%2520Matata%2520(de%2520_le%2520Roi%2520Lion_).mp3 which is an url encoded version.

{
    "event_type": "tag_scanned",
    "data": {
        "tag_id": "Various%2520Artists/Les%2520100%2520plus%2520belles%2520chansons%2520Disney%2520%255b2018%255d/4.13%2520-%2520Hakuna%2520Matata%2520(de%2520_le%2520Roi%2520Lion_).mp3",
        "device_id": "ab76ffd9aea0f48ed8208f4cf874f107"
    },
    "origin": "LOCAL",
    "time_fired": "2021-11-25T12:18:46.757663+00:00",
    "context": {
        "id": "3a9969235b406122c93d19499791932a",
        "parent_id": null,
        "user_id": null
    }
}

How can I fix this? Thx

jesserockz commented 2 years ago

You should not url encode your tag id, it is actually part of a url and can handle most characters.

Store it on the tag as Various Artists/Les 100 plus belles chansons Disney [2018]/4.13 - Hakuna Matata (de _le Roi Lion_).mp3

tetienne commented 2 years ago

That’s great, it works perfectly, and I haven’t anymore an ugly tag id. My automation still work with esphome and my phone 👌