Magic Cards - Queue music, play movies, or trigger events with RFID cards

I’m using this format for URI to play spotify album


I’m using my:

  • internal IP,
  • then the default 8123 port (or the custom port if you have it),
  • with SSL on (if you have a cert) and
  • SSL verification of (because the cert will be linked to the domain)

You should be able to browser to that URL in the browser. Probably ignoring the warning about the cert. And get to see home assistant. i.e. If you can’t browse that, I would assume magic cards can’t connect to the api either.

Hello @maddox. This looks awesome. I want to do this for my kid so he can select the music to play on Alexa / Spotify.

Few questions regarding this before I purchase everything.

  • I need a RFID reader ==> does EM4100 or Mifare reader would work the same?)
  • I need a RFID cards ==> does it need to be programmable? From what I undestood, the “Manage card” tool does the mapping itself so I guess no need to be programmable

Also, regarding the installation with HA, you say “point at it in your Home Assistant Install”. Do you mean in the configurator.yaml?

Finally, when I add the automation in HA, does it means that it will automatically extract the URL of the spotify song/album I want and play it automatically? (is it the “URI” field in the “Create card” interface?)

Sorry, I’m not too technical so not super sure what I’m doing :stuck_out_tongue:


As long as it can read RFID and presents itself as a keyboard, it should work. One thing to make sure of is that it spits out the same codes on all platforms. I personally keep one at my desk to create the cards in the Magic Cards UI. So I can just make a card there, then scan a physical card, and done.

That means I have a scanner plugged into macOS and Linux. So it’s important they output the same codes.

Nope. They can be read only. You just need their unique ID.

Read the install docs, it’ll show you how to set it up for Home Assistant.

No. It sends along a unique string. You can make it anything you want. You set this URI in the card when you make it. The card has a unique ID that your automation needs to be able to decode and do something with. It’s just sending a simple string. You get to make up that string.

1 Like

Hello mate.

I’ve got the same issue as you. Did you solve it?

Edit: I just found this:
Some people say you can go on without this step. Some readers are properly configured already. I’ll try and let you know

I think this could be quite cool implemented with QR codes - easier to print than a RFID card. Plonk it through the laminator and away you do.

Just an idea, I love this integration.

I ended up not needing to get the tool working as all three readers I bought were already setup to read the portion of the card I wanted. Basically there are 2 versions of this reader out there. One that reads the 1st 10 digits and one that reads the last 8.

Hey guys.
So far so good regarding the installation. I have just one issue.

1/ when I try to create a card with Spotify URL, it doesn’t autofill. I have an error in browser console “SyntaxError: Unexpected token e in JSON at position 0”. In the logs of docker I have

2019-10-29T13:17:51.687718606Z [0] Something went wrong when retrieving an access token { [WebapiError: Bad Request] name: 'WebapiError', message: 'Bad Request', statusCode: 400 }
2019-10-29T13:18:15.281413678Z [0] (node:73) [DEP0013] DeprecationWarning: Calling an asynchronous function without callback is deprecated.

Anything I have done wrong here?
My config.json seems to be ok regarding the tutorial.

EDIT: I have a second issue with my automation to trigger the music on my Amazon Echo device
Here is what I have entered

- alias: Play song from Magic Cards
  - platform: event
    event_type: magic_card_scanned
      card_type: "song"
  - service: media_player.select_source
          entity_id: media_player.spotify
          source: #name of my Amazon Alexa device
  - service: media_player.play_media
          entity_id: media_player.spotify
          media_content_type: playlist

Seems like the automation triggers (in the logs), but nothing really happens after, so I guess it’s the action section that is not good.

cc @maddox for the 1st point if you have any idea


For the second issue, I found out what was happening. Home Assistant only manages Album/Playlist URI :frowning: I have setup a card with an album URI and it works.

Really too bad, wanted to make cards for my kid to play specific kids songs. Anyone has ever done this in another way?

And you have your Spotify developer stuff set up correctly?I wonder if the code has gone bad with changes from Spotify. I don’t have a Magic Cards setup right now as I’ve recently moved, so I can’t test it. Does this Spotify work for anyone else?

Card URIs can be anything you want. It just happens that the album and artist URI that’s being filled in for you match what your spotify media player component uses. If you can figure out what it uses for a single song, enter that as the card URI in the magic cards ui.

For the second issue, I’ve found the solution. Basically the media_content_type: must be “music” for track URI and “playlist” for albums :stuck_out_tongue:

Thanks once again for your work because it’s pretty straightforward and it’s gonna be fun playing around with this.

Regarding the autofill, seems all my conf is alright. Will triple check but it’s not a big deal anyway :slight_smile:

Any chance you had a look into it?

I can give you all information needed. Glad to help on this :slight_smile:

pfff. I’m having hard times on figuring out these logs:

20-01-14T20:31:32.311865355Z [0] Finding card...
2020-01-14T20:31:32.312461349Z [0] Found card: Take From Me. Processing...
2020-01-14T20:31:32.338074113Z [0] Processing action: Home Assistant
2020-01-14T20:31:32.338325111Z [0] { FetchError: request to https://MYLOCALIP:8123/api/events/magic_card_scanned failed, reason: write EPROTO 3070067880:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:827:
2020-01-14T20:31:32.338457109Z [0] 
2020-01-14T20:31:32.338576108Z [0]     at ClientRequest.<anonymous> (/usr/src/app/scanner/node_modules/node-fetch/lib/index.js:1393:11)
2020-01-14T20:31:32.338700107Z [0]     at ClientRequest.emit (events.js:180:13)
2020-01-14T20:31:32.338816106Z [0]     at TLSSocket.socketErrorListener (_http_client.js:395:9)
2020-01-14T20:31:32.338933105Z [0]     at TLSSocket.emit (events.js:180:13)
2020-01-14T20:31:32.339049104Z [0]     at onwriteError (_stream_writable.js:431:12)
2020-01-14T20:31:32.339170103Z [0]     at onwrite (_stream_writable.js:453:5)
2020-01-14T20:31:32.339287102Z [0]     at _destroy (internal/streams/destroy.js:39:7)
2020-01-14T20:31:32.339404101Z [0]     at TLSSocket.Socket._destroy (net.js:548:3)
2020-01-14T20:31:32.339521100Z [0]     at TLSSocket.destroy (internal/streams/destroy.js:32:8)
2020-01-14T20:31:32.339637099Z [0]     at WriteWrap.afterWrite [as oncomplete] (net.js:846:10)
2020-01-14T20:31:32.339756097Z [0]   message: 'request to failed, reason: write EPROTO 3070067880:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:827:\n',
2020-01-14T20:31:32.341059085Z [0]   type: 'system',
2020-01-14T20:31:32.341243084Z [0]   errno: 'EPROTO',
2020-01-14T20:31:32.341374083Z [0]   code: 'EPROTO' }
2020-01-14T20:31:32.341492081Z [0]   null

My actions.json looks like this:

  "Home Assistant": {
    "type": "home_assistant",
    "host": "MYLOCALIP",
    "port": "8123",
    "ssl": true,
    "verify_ssl": false,
    "token": "MYTOKEN"

When I browse to https://MYLOCALIP:8123/api/events/magic_card_scanned, firefox complains about

Secure Connection Failed

An error occurred during a connection to MYLOCALIP:8123. SSL received a record that exceeded the maximum permissible length.


I’m using nginx reverse proxy addon. Probably making things over-complicated with this addon.

Anybody a clue?
Thanks in advance

Do you actually have a cert attached to that reverse proxy? I see you’re using https and there’s an openssl error, this might be the issue. Try just http.

Hey Maddox, I’ll try just http again tomorrow and let you know. Thank you for your quick reply!

Allright, i tried http using this config in actions.json:

  "Home Assistant": {
    "type": "home_assistant",
    "host": "MYLOCALIP",
    "port": "8123",
    "ssl": false,
    "verify_ssl": false,

I can access my home assistant, using http://MYLOCALIP:8123; it gives me the login screen.
I used a chrome extension ‘postman’ to send a POST request to http://MYLOCALIP:8123/api/events/magic_card_scanned
It returns a 401 unauthorized. I guess this means my HA restful-api is reachable.

Unfortunately I still find these errors in my magic-home log:

2020-01-15T19:55:56.274495233Z [0] Finding card...
2020-01-15T19:55:56.274769300Z [0] Found card: Take From Me. Processing...
2020-01-15T19:55:56.274913335Z [0] Processing action: Home Assistant
2020-01-15T19:55:56.275045368Z [0] Error [ERR_INVALID_PROTOCOL]: Protocol "http:" not supported. Expected "https:"
2020-01-15T19:55:56.275173399Z [0]     at new ClientRequest (_http_client.js:132:11)
2020-01-15T19:55:56.275299430Z [0]     at request (http.js:41:10)
2020-01-15T19:55:56.275431462Z [0]     at /usr/src/app/scanner/node_modules/node-fetch/lib/index.js:1375:15
2020-01-15T19:55:56.275558493Z [0]     at new Promise (<anonymous>)
2020-01-15T19:55:56.275689526Z [0]     at fetch (/usr/src/app/scanner/node_modules/node-fetch/lib/index.js:1367:9)
2020-01-15T19:55:56.275817557Z [0]     at HomeAssistantAction.request (/usr/src/app/scanner/actions/HomeAssistantAction.js:50:12)
2020-01-15T19:55:56.275944588Z [0]     at HomeAssistantAction.process (/usr/src/app/scanner/actions/HomeAssistantAction.js:7:10)
2020-01-15T19:55:56.276072619Z [0]     at CardProcessor.processCard (/usr/src/app/scanner/CardProcessor.js:55:23)
2020-01-15T19:55:56.276197650Z [0]     at CardProcessor.process (/usr/src/app/scanner/CardProcessor.js:19:10)
2020-01-15T19:55:56.276324681Z [0]     at Object.<anonymous> (/usr/src/app/scanner/testCard.js:5:15)
2020-01-15T19:55:56.276506726Z [0]   null

It must me something obvious that I’m missing here.

Did you create a token for a normal user? Tokens only actually work for admin users.

I found this out the hard way too.

@Tokast Regarding autofill:

I can confirm that with this config.json autofill works for me:

  "room": "Living Room",
  "input_device": "event0",
  "spotify": {
    "clientID": "MY_ID",
    "clientSecret": "MY_SECRET"

If I paste the spotify web URL from a song I’d like to add, autofill works for me.
I paste for example

Probably this isn’t going to help you. Maybe your generated development credentials for Spotify are wrong?

the 401 is caused because I couldn’t find out how to add the token in the Chrome extension. I only send a empty POST request to the home assistant api. It was just to test if the api was ‘listening’.

Just created a new token, double checked admin rights. Same behavior.
Tried to add api: to home assistant configuration.yaml, no effect. Tried to remove my base_url on the http: component, no effect.

I’ll think about it over night :slight_smile: Maybe I can come up with something different to try.

Got it!

for me (using nginx reverse proxy) magic-cards only worked not using my local IP, but using the external URL:

  "Home Assistant": {
    "type": "home_assistant",
    "host": "MYURL",
    "port": "443",
    "ssl": true,
    "verify_ssl": true,
    "token": "MYTOKEN"

Now getting my automations right and modifying my selfmade reader to fit in the raspberry and the reader:

Thanks Maddox!