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

I’ll investigate some more on my part and open an issue on git if the problem reoccurs.

i would be also interested in realizing this project in my home. but I was wondering if I would need to buy a separate rpi for the nfc reader as my hass.io is already running on a rpi 3.

Can’t I just connect the nfc reader to the rpi running hass.io? or does it need to be used on a separate rpi?

Adding running software to hass.io requires it to be bundled as a hass.io add-on. Magic Cards does not support that.

I had the same problem for some software installations, but I wanted to take advantages of both worlds.
It is possible to install hass.io on a Hassbian image :wink:
It was fluent, but needed some work. When I have some time left, I’ll post a tutorial…if someone is interested

BTW I love your Magic Cards :slight_smile:

1 Like

my pi zero w arrived and i tried getting it to run but with no luck. this is what i got:

pi@raspberrypi:~ $ ls -al /dev/input
total 0
drwxr-xr-x  4 root root     120 Sep  7 08:44 .
drwxr-xr-x 14 root root    3280 Sep  7 08:44 ..
drwxr-xr-x  2 root root      60 Sep  7 08:44 by-id
drwxr-xr-x  2 root root      60 Sep  7 08:44 by-path
crw-rw----  1 root input 13, 64 Sep  7 08:44 event0
crw-rw----  1 root input 13, 63 Sep  7 08:44 mice
pi@raspberrypi:~ $ docker ps
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                    NAMES
ddf4ac219f0d        jonmaddox/magic-cards   "/usr/bin/entry.sh s…"   17 minutes ago      Up 2 minutes        0.0.0.0:5000->5000/tcp   magic-cards
pi@raspberrypi:~ $ curl 192.168.1.60:5000
curl: (7) Failed to connect to 192.168.1.60 port 5000: Connection refused

do you guys have an idea what is going wrong?

did you try checking the log output of the docker container to see if it was reporting any errors? Are you sure that’s the right IP?

Try curl localhost:5000 as well.

yupp, i am sure and local host is no different unfortunately. i cannot check the log output as apparently the container is restarting the whole time.

sorry, found the log:

2018-09-07T19:15:41.729044995Z [0] yarn server exited with code null
2018-09-07T19:15:41.822298739Z error Command failed with exit code 1.
2018-09-07T19:15:46.983919605Z Starting Magic Cards...
2018-09-07T19:16:50.250412181Z [0] $ cd server && yarn start
2018-09-07T19:16:50.427021723Z [1] $ cd scanner && yarn start
2018-09-07T19:17:26.022959641Z [0] $ node server.js
2018-09-07T19:17:26.535814347Z [1] $ node scanner.js
2018-09-07T19:17:46.879829407Z [1] internal/modules/cjs/loader.js:550
2018-09-07T19:17:46.880082406Z [1]     throw err;
2018-09-07T19:17:46.880214406Z [1]     ^
2018-09-07T19:17:46.880335405Z [1] 
2018-09-07T19:17:46.880453405Z [1] Error: Cannot find module '/usr/src/app/scanner/actions/../../config/config.json'
2018-09-07T19:17:46.880571405Z [1]     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)
2018-09-07T19:17:46.880691404Z [1]     at Function.Module._load (internal/modules/cjs/loader.js:475:25)
2018-09-07T19:17:46.880809404Z [1]     at Module.require (internal/modules/cjs/loader.js:598:17)
2018-09-07T19:17:46.880927404Z [1]     at require (internal/modules/cjs/helpers.js:11:18)
2018-09-07T19:17:46.881043404Z [1]     at Object.<anonymous> (/usr/src/app/scanner/actions/Action.js:1:84)
2018-09-07T19:17:46.881166403Z [1]     at Module._compile (internal/modules/cjs/loader.js:654:30)
2018-09-07T19:17:46.881288403Z [1]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
2018-09-07T19:17:46.881407403Z [1]     at Module.load (internal/modules/cjs/loader.js:566:32)
2018-09-07T19:17:46.881563402Z [1]     at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
2018-09-07T19:17:46.887332388Z     at Function.Module._load (internal/modules/cjs/loader.js:498:3)
2018-09-07T19:17:46.999663109Z [1] error Command failed with exit code 1.
2018-09-07T19:17:47.010395082Z [1] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
2018-09-07T19:17:47.199604612Z [1] error Command failed with exit code 1.
2018-09-07T19:17:47.214484575Z [1] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
2018-09-07T19:17:47.424539053Z [1] yarn scanner exited with code 1
2018-09-07T19:17:47.440248014Z --> Sending SIGTERM to other processes..
2018-09-07T19:17:49.457024008Z [0] internal/modules/cjs/loader.js:550
2018-09-07T19:17:49.457249008Z [0]     throw err;
2018-09-07T19:17:49.457372007Z [0]     ^
2018-09-07T19:17:49.457491007Z [0] 
2018-09-07T19:17:49.457609007Z [0] Error: Cannot find module '/usr/src/app/server/../config/config.json'
2018-09-07T19:17:49.457726007Z [0]     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)
2018-09-07T19:17:49.457921006Z [0]     at Function.Module._load (internal/modules/cjs/loader.js:475:25)
2018-09-07T19:17:49.458050006Z [0]     at Module.require (internal/modules/cjs/loader.js:598:17)
2018-09-07T19:17:49.458163005Z [0]     at require (internal/modules/cjs/helpers.js:11:18)
2018-09-07T19:17:49.458280005Z [0]     at Object.<anonymous> (/usr/src/app/server/server.js:7:16)
2018-09-07T19:17:49.458396005Z [0]     at Module._compile (internal/modules/cjs/loader.js:654:30)
2018-09-07T19:17:49.458508005Z [0]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
2018-09-07T19:17:49.458621004Z [0]     at Module.load (internal/modules/cjs/loader.js:566:32)
2018-09-07T19:17:49.458735004Z [0]     at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
2018-09-07T19:17:49.484382940Z     at Function.Module._load (internal/modules/cjs/loader.js:498:3)
2018-09-07T19:17:49.523788843Z [0] error Command failed with exit code 1.
2018-09-07T19:17:49.532776820Z [0] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
2018-09-07T19:17:49.638052559Z [0] error Command failed with exit code 1.
2018-09-07T19:17:49.646811538Z [0] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
2018-09-07T19:17:49.703851396Z [0] yarn server exited with code null
2018-09-07T19:17:49.804025148Z error Command failed with exit code 1.
2018-09-07T19:17:56.011190790Z Starting Magic Cards...
2018-09-07T19:19:01.518884784Z [1] $ cd scanner && yarn start
2018-09-07T19:19:01.622494540Z [0] $ cd server && yarn start

and github tells me to use

script/install

in order to start magic cards but it just gives the following:

pi@raspberrypi:~ $ script/install
-bash: script/install: No such file or directory

I think you need to be in the magic-cards directory.

cd magic-cards
script/install

You’re conflating the installation instructions. You only use that command if you’re installing onto your system. But you are using the docker image. You don’t use that when using docker.

2018-09-07T19:17:49.457609007Z [0] Error: Cannot find module '/usr/src/app/server/../config/config.json'

It’s erroring because you didn’t create your config file. You need to have a config.json file for the project, and have it mounted into your docker container.

Please re-read the instructions on how to set things you. You’ve left a few things out.

regarding the script/install topic:
Yeah, I thought so as it did not make sense to me. But no harm was done anyway so I tried. The reason I tried anyway was because it was listed as a seperate item on the table of content of the instructions and not as part of the standalone installation topic.

regarding the missing config.json:
I followed the instructions carefully, which is why I already had a config file:

pi@raspberrypi:~/magic-cards $ cd config
pi@raspberrypi:~/magic-cards/config $ ls -l
total 12
-rw-r--r-- 1 root root  125 Sep  7 08:04 actions.json
-rw------- 1 pi   pi   1319 Sep  7 08:22 actions.json.save
-rw-r--r-- 1 root root   61 Sep  7 08:19 config.json
  • I do not know what the actions.json.save is. can I delete it? there is a chance that it was created by me by mistake
  • i think the missing part is the “mount it into your docker container”. There is no word about “mounting” in the instructions. How do I do that?

That actions.jaon.save file looks like some cache or something from your editor. You can delete it.

In the instructions it show that you start the container like this:

  --name magic-cards \
  --restart=always \
  -d \
  -p 5000:5000 \
  -v `pwd`/config:/usr/src/app/config \
  --device=/dev/input/event0 \
  jonmaddox/magic-cards

The -v part is where it’s mounting the config directory into your docket container. Run this command inside the project directory for it to work as pasted. Otherwise you need to adjust the path in that line to your config directory.

ok, now i just formated the sd card and set everything up again from scratch and I end up with the same error. so frustrating and I honestly am following the instructions. the only thing I can think of is that I am installing the container wrongly. Both times I ran Docker from within the rpi root folder (not from within the magic-cards folder) . And the actions and config json files are placed in magic-cards/config/ and the content is as follows:
config.json:

{
  "room": "Living Room",
  "input_device": "event0"
}

actions.json:

{
  "Home Assistant": {
    "type": "home_assistant",
    "host": "192.168.1.15",
    "port": "8123",
    "ssl": true,
    "password": "MY_HA_API_PASSWORD"
  }
}

I now deleted the container and rerun the command from within the magic-cards folder. it still does nto work but the log has changed:

 Starting Magic Cards...
 [1] $ cd scanner && yarn start
 [0] $ cd server && yarn start
 [1] $ node scanner.js
 [0] $ node server.js
 [0] /usr/src/app/server/server.js:11
 [0]   clientId: config.spotify.clientID,
 [0]                            ^
 [0] 
 [0] TypeError: Cannot read property 'clientID' of undefined
 [0]     at Object.<anonymous> (/usr/src/app/server/server.js:11:28)
 [0]     at Module._compile (internal/modules/cjs/loader.js:654:30)
 [0]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
 [0]     at Module.load (internal/modules/cjs/loader.js:566:32)
 [0]     at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
 [0]     at Function.Module._load (internal/modules/cjs/loader.js:498:3)
 [0]     at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
 [0]     at startup (internal/bootstrap/node.js:201:19)
 [0]     at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)
 [0] error Command failed with exit code 1.
 [0] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
 [0] error Command failed with exit code 1.
 [0] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
 [0] yarn server exited with code 1
 --> Sending SIGTERM to other processes..
 Starting Magic Cards...
 [1] $ cd scanner && yarn start
 [0] $ cd server && yarn start
 [1] $ node scanner.js
 [0] $ node server.js
 [0] /usr/src/app/server/server.js:11
 [0]   clientId: config.spotify.clientID,
[0]                            ^
 [0] 
 [0] TypeError: Cannot read property 'clientID' of undefined
 [0]     at Object.<anonymous> (/usr/src/app/server/server.js:11:28)
 [0]     at Module._compile (internal/modules/cjs/loader.js:654:30)
 [0]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
 [0]     at Module.load (internal/modules/cjs/loader.js:566:32)
 [0]     at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
 [0]     at Function.Module._load (internal/modules/cjs/loader.js:498:3)
 [0]     at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
 [0]     at startup (internal/bootstrap/node.js:201:19)
 [0]     at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)
 [0] error Command failed with exit code 1.
 [0] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
 [0] error Command failed with exit code 1.
 [0] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
 [0] yarn server exited with code 1
 --> Sending SIGTERM to other processes..

ok, it now works for me after some trial and error and logical thinking, although i had no knowledge about this terminal stuff before.

the mistakes I made, which were also not crystal clear in the github readme:

  1. the container needs to be run from within the magic-cards folder
  2. the config.json MUST include room, input device AND spotify components (in the readme it just says that the given config parameters are just an example)

now, magic cards is running. but that was jsut the setup, i will now try to use it and I am pretty sure that I will bother you again with further advice request :slight_smile:

I just tried to create a card, while it auto populates the required fields, I was hoping that the Card Code will automatically be populated when I swipe the RFID card over the RFID reader (which is attached to the rpi zero via micro usb). but it does not and honestly I do know what the readme exactly means here:

What do I need to do to auto populate the card ID? Does my rpi recognize the rfid scanner as “mice”?

pi@raspberrypi:/dev/input $ ls -1
by-id
by-path
event0
mice
pi@raspberrypi:/dev/input $ cd /dev/input/by-id/
pi@raspberrypi:/dev/input/by-id $ ls -l
total 0 
lrwxrwxrwx 1 root root 9 Sep 9 12:38 usb-Sycreader_USB_Reader_08FF20150112-event-kbd -&gt; ../event0`

Heya, glad to see you got it up and running. Thanks for the feedback on what failed if it wasn’t set up. Yes, a lot of assumptions are built into it.

As for the Card ID, you will need to have the scanner plugged into your computer that you’re using to create cards. With it plugged in…focus the Card ID field in the card editor, and scan your card. That will input the card’s ID. The scanner acts just like a keyboard.

This is why the instructions suggest purchasing 2 card scanners. One for your Magic Cards install and one for managing cards from your computer. Be sure you also follow the instructions for setting up the card scanner. You need to use windows software to configure the scanner and put it into a specific mode for this to work. The instructions are in there.

true, it actually works if I connect the rfid card reader to the computer where I am using magic cards. I will consider buying a second device…

now, I do not seem to get the automation within home assistant working. this is the automation I set within home assistant:

# Magic Cards
- alias: Play MC playlist
  trigger:
    platform: event
    event_type: magic_card_scanned
    event_data:
      card_type: album
  action:
      service: script.turn_on
      data_template:
        entity_id: "script.{{ trigger.event.data.card_uri }}"

where card uri within the magic cards interface contains the name of the script (e.g. “jazz”) so that script.jazz is called.

but the trigger somehow is not working as nothing seems to arrive at hassio. Now I am beginning to think that I cannot access hassio via the actions.json due to the new hassio auth method for which I activated 2 factor authentication. you think that might be an issue?

That’s absolutely the issue. Ensure you keep legacy password support going for now.

I myself haven’t even updated to latest Home Assistant because I’m afraid it will break all of my different integrations. I’ll have to find a time where I can have things down while I update things.

so, magic cards is working for me now, but it took a while as another set of trial and error was required:

  1. When I tried using my rfid reader at the computer checking if the card id is auto populated it somehow reset the hardware settings, as plugging it back into my pi zero did not enable my pi zero to identify it as a device anymore. so weird. So I had to reprogramm it with the windows software as apparently the settings have been reset. after reprogramming, the card reader worked again

  2. I am running hassio via dns and https using duckdns. somehow, using the local ip of my hassio including setting port and ssl= true, did not work at all. but the following setup of actions.json did work for me:

    {
       "Home Assistant": {
         "type": "home_assistant",
         "host": "YOURDNS.duckdns.org",
         "port": "443",
         "ssl": true,
         "password": "YOUR_API_PASSWORD"
       }
     }
    
  3. as long as you are using legacy api with hassio you are good to go, regardless if you activate 2 factor authentication or not

  4. if you want to save money and not buy a second reader, you can scan the rfid card at the reader attached to your pi zero and copy paste the the card id from the container logs into the magic cards browser interface. given that I am not regularly creating cards, it might be the more economic option. but on the other hand: what’s awful about 12EUR for a new reader? :slight_smile:

in my setup I can now easily trigger any script in hassio with magic cards. just awesome. thanks for this project, my kid loves it already as he can choose between kodi movies/ shows via cards and also how much screen time he has left (movie card in “used” box? -> sorry, u already had 2h screentime :grinning: )