Read the statement by Michael Teeuw here.
MMM-HomeKit | Control your MagicMirror with Apple HomeKit
-
MMM-HomeKit
This is not a MagicMirror module but it allows you to control your mirror from the Home application with Apple HomeKit
How it works
To use HomeKit with your MagicMirror it will not be enough to install a module. For this we will have to use
HomeBridge
which is an emulator of the iOS HomeKit API. This will allow us to connect our Apple device to the Raspberry. Then we will have to install thehomebridge-cmdswitch2
module that will allow us to perform bash commands when switching on / off from the Home application.Screenshot
Prerequisites
- MagicMirror2
- HomeBridge (I let you look here to see how to install HomeBridge. It’s very simple.)
Step 1 - Install the module
cd sudo npm install -g homebridge-cmdswitch2
Step 2 - Edit HomeBridge config
sudo nano .homebridge/config.json
Now Copy/paste this piece of JSON code into the “platform” section
"platforms": [{ "platform": "cmdSwitch2", "name": "Raspberry Pi", "switches": [{ "name" : "Mirror", "on_cmd": "tvservice --preferred && sudo chvt 6 && sudo chvt 7", "off_cmd": "tvservice -o", "state_cmd": "tvservice --status | grep -i 'HDMI DMT'", "manufacturer": "Raspberry Pi Foundation", "model": "Raspberry Pi 3 Model B", }] }]
Save the file.
Step 3 - Start HomeBridge
cd homebridge
Configuring
Here is the descriptive table of the module parameters (this table comes from the cmdSwitch2 Github)
Fields Description Required platform Must always be cmdSwitch2
.Yes name For logging purposes. No switches Array of switch config (multiple switches supported). Yes |- name* Name of your device. Yes |- on_cmd Command to turn on your device. No |- off_cmd Command to turn off your device. No |- state_cmd Command to detect an ON state of your device. No |- polling State polling (Default false). No |- interval Polling interval in s
(Default 1s).No |- timeout** Commands execution timeout in s
(Default 1s).No |- manufacturer Manufacturer of your device. No |- model Model of your device. No |- serial Serial number of your device. No Use
Now you can fully use MagicMirror and HomeKit to turn the screen of your raspberry on and off ! Enjoy it well !
Turn off the mirror from the Home application Turn on the mirror with Siri Contributing
If you find any problems, bugs or have questions, please open a GitHub issue in this repository.
-
@XC2DN
Can we add additional cmdSwitch2 platform for other shell command? If so, module controlling could be added besides screen on/off -
@Sean said in MMM-HomeKit | Control your MagicMirror with Apple HomeKit:
Can we add additional cmdSwitch2 platform for other shell command? If so, module controlling could be added besides screen on/off
Yes! Absolutely. Just add this to the “switches” sections.
{ "name" : "Name of the HomeKit command", "on_cmd": "bash command to show a module", "off_cmd": "bash command to hide a module", "state_cmd": "bash command to get the hide / show status'", "manufacturer": "Raspberry Pi Foundation", "model": "Raspberry Pi 3 Model B", }
Your config.json should look something like this.
"platforms": [{ "platform": "cmdSwitch2", "name": "Raspberry Pi", "switches": [{ "name" : "Mirror", "on_cmd": "tvservice --preferred && sudo chvt 6 && sudo chvt 7", "off_cmd": "tvservice -o", "state_cmd": "tvservice --status | grep -i 'HDMI DMT'", "manufacturer": "Raspberry Pi Foundation", "model": "Raspberry Pi 3 Model B", }, { "name" : "Name of the HomeKit command", "on_cmd": "bash command to show a module", "off_cmd": "bash command to hide a module", "state_cmd": "bash command to get the hide / show status'", "manufacturer": "Raspberry Pi Foundation", "model": "Raspberry Pi 3 Model B", }] }]
-
Excellent module!
Got everything working fairly easily. I am attempting to add my own switches, but the issues I am having is that the “on_cmd” and “off_cmd” do not use npm correctly. Any ideas? This is the error it’s throwing. Didn’t have luck Googling.
[3/10/2019, 1:42:17 PM] [Raspberry Pi] npm ERR! path /home/pi/package.json npm ERR! code ENOENT npm ERR! errno -2 npm ERR! syscall open npm ERR! enoent ENOENT: no such file or directory, open '/home/pi/package.json' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent
-
Okay, looks like something with my npm was broken. It was working before, so I think installing this module or Homebridge did it. Attempting to fix.
-
@p4lsec said in MMM-HomeKit | Control your MagicMirror with Apple HomeKit:
Excellent module!
Hello ! Thank you for that compliment.
Unfortunately, I don’t know where your problem comes from. What is the command you are executing that gives you this error?
Keep me informed :wink: -
@XC2DN
My Homebridge is at another Pi then the Mirror. How I have to use it? -
@Niggich Making connection to the other pi through ssh to send commands? Or if your using a module which allows to give commands through a url u can use curl… In this example I use both…
{ "name" : "Magic Mirror", "on_cmd": "curl -s 'http://192.168.X.XX:8080/remote?action=MONITORON'", "off_cmd": "curl -s 'http://192.168.X.XX:8080/remote?action=MONITOROFF'", "state_cmd": "sshpass -p 'sshpassword' ssh -oStrictHostKeyChecking=no pi@192.168.X.XX vcgencmd display_power | grep -q '1' && echo '1'", "polling": true, "interval": 10, "manufacturer": "XXX", "model": "v 1.0.0" }
You might need to install sshpass: apt-get install sshpass, which allows you to connect through ssh with password without being prompted on the command line for the password.
-
@Caimin Thank you a lot. It is working like this. I install sshpass to send the Commands via ssh.
-
This post is deleted!