Home Assistant Tags

hm this seams to be an issue with handling over from HA to chromecast, due to the fact that i use sonos system i can not help you there.
Play music on chromecast work with HA and other automations?

Actually I have to admit, I never tried it. I can launch a song from Spotify on this speaker then control the media player from HA. But never succeeded in launching a song directly from HA


Hi,

to start playing on a chromecast you need Spotcast - custom component to start playback on an idle chromecast device

That is because the “normal” integration needs the chromecast already as player in spotify


1 Like

Indeed, that worked, thank you!
So here is my code for anyone who wants to get inspired.

- alias: 123
  mode: single
  # Hide warnings when triggered while in delay.
  max_exceeded: silent
  variables:
    # Map tag ID to content
    tags:
      D0-56-31-22:
        media_content_id: 'spotify:playlist:37i9dQZF1DWV0gynK7G6pD'
  trigger:
    platform: event
    event_type: tag_scanned
  condition:
    # Test that we support this device and tag
    - "{{ trigger.event.data.tag_id in tags }}"
  action:
    - variables:
        media_content_id: "{{ tags[trigger.event.data.tag_id].media_content_id }}"
    - service: spotcast.start
      data:
#        account: 
        device_name: "Device friendly name in Spotify"
        uri: "{{ media_content_id }}"
    - delay: 2 # timeout before we allow processing next scan

Little detail, what I am trying to achieve does NOT work YET:

  • Some tags will change the song/playlist/album
  • Some other tags will change the account or the speaker

Any clue how to tell the automation not to change this or that parameter without having to duplicate the automation?

- alias: 123
  mode: single
  # Hide warnings when triggered while in delay.
  max_exceeded: silent
  variables:
    # Map tag ID to content
    tags:
      D0-56-31-22:
        media_content_id: 'spotify:playlist:37i9dQZF1DWV0gynK7G6pD'
      67-12-D1-C2:
        media_player_entity_id: "Friendly name of the device in Spotify"
  trigger:
    platform: event
    event_type: tag_scanned
  condition:
    # Test that we support this device and tag
    - "{{ trigger.event.data.tag_id in tags }}"
  action:
    - variables:
        media_player_entity_id: "{{ tags[trigger.event.data.tag_id].media_player_entity_id }}"
        media_content_id: "{{ tags[trigger.event.data.tag_id].media_content_id }}"
    - service: spotcast.start
      data:
#        account: 
        device_name: "{{ media_player_entity_id }}"
        uri: "{{ media_content_id }}"
    - delay: 2 # timeout before we allow processing next scan

HI @adonno,
Thanks for the devices, I ordered a pair, it works great!
Is there a way to control the buzzer from HA? I would love to make it beep few times when I need.
Is is also possible to control the volume?

And if i change in future my smartphone, this automation will work the same or i am forced to use always the smartphone who created the tag_scanned?

1 Like

Just change the device_id later when you get a new phone. Or if you leave out the device_id it should just work with any registered device as far as I understand.

1 Like

Thanks, but in case, where to find the device_id?

When you scan a tag you can view that data in dev tools. See this post above with some screen shots:

May I ask what RANGE you guys get with these NFC Modules V3?
I built the circuit with a Wemos D1 and BEST i can get like 5mm. If I put it in a case that is 1.5mm thick it’s almost impossible to read tags. Any idea on that?

This tagreader is a great addition to my Home Assistant! Like most people I use it for playing music. My 2-year old son has his own nfc cards, and can easiliy use it to play his favourite songs on my Nest Audio speakers. He is addicted to it :slightly_smiling_face:
I added a Xiaomi wireless switch in order to control the songs in the playlist: one press is next song, double press is previous song, long press is stop. I bought a Canon TS8350 printer and a pvc card tray to print images on the cards. I’m very happy with this project, and so are my family members. Thanks @adonno for the great work!

QR-Codes generated from Tags works great when I scan them with my Galaxy S7 Edge using any third party App, except for when I use the Microsoft Launcher for Android. The integrated QR-Code scanner in the MS Launcher persistently forwards the URL to the default browser no matter what I do.
How can I make it forward this URL to the HA Companion App - like any other well behaved scanner will do?

Now is it possible to start playing tracks/podcasts/streams/favorites stored on Logitecht Media Server and play it on my squeezebox classic? Do I need to customize scripts or anything. I’m not really a programmer/scripter. :slight_smile:

Is it possible to retrieve the device_id of the device who scanned the tag? I just want to know which phone scan the tag that enable or disable my alarm.

The event data has the attribute “device_id” that is the id of the device that scanned the tag.

I know this event data but i am not able to use it. There is my yaml for the notification in my automation.

service: notify.mobile_app_mi_8_bbo
data:
message: ‘Alarm desactivated by {{ state_attr(’‘trigger.device_id’‘, ‘‘friendly_name’’) }}.’
title: ALARME HA

PS: Sorry for my english, i’m French :sweat_smile:

It would be trigger.event.data.device_id and it doesn’t have a friendly name. You could translate the id to a string with variables. Take a look at the examples

1 Like

Many thanks to you it works fine ! I learn everyday :wink:

alias: Test TAG 02
description: ''
variables:
  telephones:
    id_tel1: Téléphone BBo
    id_tel2: Téléphone FPo
trigger:
  - platform: tag
    tag_id: xxxxxx-xxxx-xxx-xxx-xxxx
    device_id:
      -  id_tel1
      -  id_tel2
condition: []
action:
  - service: notify.mobile_app_mi_8_bbo
    data:
      message: 'Alarm desactivated by {{ telephones[trigger.event.data.device_id] }}.'
      title: ALARME HA
mode: single

*note that id_tel1 is the id of the first Téléphone_BBo and id_tel2 the one for Téléphone_FPo

2 Likes

Coming here to share the solution to a problem I had with the original code shared in the blog post. hoping it will be of use to someone else searching for this error.

The sensor has been working fine for months. I noticed today that ESPhome wanted to do a firmware update but validation failed with the error


INFO Reading configuration /config/esphome/RFID Reader.yaml...
Failed config

pn532: [source /config/esphome/RFID Reader.yaml:76]
  
  This component has been moved in 1.16, please see the docs for updated instructions. https://esphome.io/components/binary_sensor/pn532.html.
  - [source /config/esphome/RFID Reader.yaml:77]
    cs_pin: D3
    update_interval: 2s
    on_tag: 
      then: 
        - homeassistant.tag_scanned: !lambda |-
            return x;
        - if: 
            condition: 
              switch.is_on: buzzer_enabled
            then: 
              - rtttl.play: success:d=24,o=5,b=100:c,g,b
        - if: 
            condition: 
              switch.is_on: led_enabled
            then: 
              - light.turn_on: 
                  id: activity_led
                  brightness: 100%
                  red: 0%
                  green: 100%
                  blue: 0%
                  flash_length: 500ms

The solution was to simply change line 76 from pn532: to pn532_spi:

I hope this helps someone else.

In the Configuration Tag section, you can assign friendly names to tag numbers. What would the template look like to pull these friendly names out for a notify data in the following code?

- alias:  Scan
  trigger:
    - platform: tag
      tag_id:
        - 1234 # Larry
        - 4321 # Curly
        - 2244 # Moe
  action:
    - service: notify.notify
      data_template:
        message: '{{ trigger.what.goes.here? }}
            

1 Like