posted May 9, 2017, 6:33 AM by Tom Pedersen
[
updated May 3, 2021, 7:53 AM
]
I cobbled together a Raspberry Pi to stand-in as an Apple HomeKit and AirPlay/Print server as an experiment. The little gizmo allows us to control smart devices, print on household printer and play music on our stereo from iPhones & iPads. The HomePi has been working like a champ, so I decided to retrace my steps and share the recipe - hopefully useful to others.
Background/Overview
Many of the techno problems around our home tend to revolve around integrating older equipment with modern devices or attempting to deal with the deluge of new 'smart' devices, each with its own App or interface. Our 'vintage' stereo and network printer are prime examples of the old world - simply not iPhone/iPad compatible in terms of streaming music or printing. On the other end of the spectrum, we seem to be constantly fumbling with a variety of apps provided with our newfangled smart home (lights, switches, appliances, etc). I originally dropped the Raspberry PI onto our network to fill the Air gap by emulating Apple AirPlay and AirPrint services and recently added HomeKit services so Siri could begin helping out around the house . A cheap, easy and fun little project - no programming but RPI/Linux knowledge will come in handy. Probably a couple of hours to get things installed and running.
Hardware
Our original AirPi was built on a Raspberry Pi 1 Model B, which worked great for Play/Print services for a couple of years - totally amazed by reliability and performance, it even handled print jobs while playing streamed music without missing a beat. The latest HomePi is based on a RPI 3 Model B which seems to be just as reliable and handle the additional HomeKit activity. The contraption is connected to our WiFi network and wired to an aux port on our stereo via headphone (3.5mm) to RCA Y-Cable.
Here's the list of hardware components involved. There is flexibility here, but the following works for me:
Software
The software used for the original AirPi was somewhat version specific due to the combination of hardware and software required to pull the thing together using Raspbian Weezy, Shairport open source project and some sound/alsa struggles attempting to get my cheap-o USB sound card up and running. The HomePi rebuild went VERY smoothly under Jessie, but noted original software versions below - just in case. Seems to work fine under Stretch too.
- Latest Raspbian via NOOBS - NOOBS v2.4 (approx 1.5g download) and Raspbian Jessie
- Requires formatted SD card. I use gparted to create/format single FAT32 partition for NOOBS
- AirPlay services via Shairport-Sync v3.0.2
- AirPrint - CUPS print services v1.75 to handle print from iPhone/iPad
- HomeKit - Home Automation using Homebridge project v0.4.19
Installation
Following is a sing-a-long with stopping
points along the way for systems that won't require all services. Not
exactly a HowTo, more of the personal log used to build/rebuild
this rascal. It does Include links to installation guides and a number of HowTo articles that I
found useful during the project. Hopefully helpful to others.
Raspberry Pi OS Prep
- Follow Raspberry Pi Setup Guide for initial setup - Approx 15 Minutes, not including download time
- Couple of notes/potential gotcha's:
- Remember to set Language and Keyboard at bottom of NOOBS initial screen (I always forget)
- Raspbian only - no need to install other OSs for this project
- Some post installation cleanup from my checklist and log
AirPrint (CUPS)
AirPlay (Shairport-sync)
- USB Sound Card setup (also dependent on Jessie):
U se aplay to get list of playback hardware - see below output, USB card highlighted //
aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
Subdevice #0: subdevice #0
card 1: Device [USB Audio Device], device 0: USB Audio [USB Audio]
Subdevice #0: subdevice #0
- Modify /home/pi/.asoundrc, setting card # to USB Audio Device. File appears to be auto generated/created if you start in the GUI, I had to create it myself from CLI ... it looks like this
$ cat .asoundrc
pcm.!default {
type hw
card 1
}
ctl.!default {
type hw
card 1
}
- copy .asoundrc to /etc/asound.conf to get thing to work at boot/service
sudo cp /home/pi/.asoundrc /etc/asound.conf
- Make sure Serice is up and OK. After reboot too
sudo systemctl start
shairport-sync
sudo systemctl status shairport-sync
- I preset volumes to minimize fiddling with device volume using
alsamixer
- Set Mic to zero
- Set Capture to zero
- Set Speaker to redline (93 on mine)
- HomeBridge homepage @ https://github.com/nfarina/homebridge.
Install can take some time, count on an hour with minimal plugin playtime!
- One preliminary - check for plugins for your smart devices before you go through install - just to make sure you'll be able to control your device. Go to https://www.npmjs.com and search for "homebridge-<your dev>". For example https://www.npmjs.com/package/homebridge-wemo or https://www.npmjs.com/package/homebridge-philipshue
- RPI Homebridge Install from https://github.com/nfarina/homebridge/wiki/Running-HomeBridge-on-a-Raspberry-Pi :
- Plugins installation. Steps are dependent on the smart device. Plugins are also installed using npm, will have their own readme/instructions including a snippet to add to your config.json file. Get plugins by searching for "homebridge-" on https://www.npmjs.com. Expect some trial/error and fiddling to get plugins working
- Testing: Once Plugins are installed, Fire up Homebridge and test. I test in a terminal window for a day or two to keep an eye on message chatter
- To start Homebridge when RPI boots, create a systemd service from https://github.com/nfarina/homebridge/wiki/Running-HomeBridge-on-a-Raspberry-Pi#running-homebridge-on-bootup-systemd
- Create /etc/default/homebridge file using example from https://gist.github.com/johannrichard/0ad0de1feb6adb9eb61a/#file-homebridge
cat /etc/default/homebridge
# Defaults / Configuration options for homebridge
# The following settings tells homebridge where to find the config.json file
# and where to persist the data (i.e. pairing and others)
HOMEBRIDGE_OPTS=-U /var/lib/homebridge
# If you uncomment the following line, homebridge will log more
# You can display this via systemd's journalctl: journalctl -f -u homebridge
# DEBUG=*
- Create /etc/systemd/system/homebridge.service file using example from https://gist.github.com/johannrichard/0ad0de1feb6adb9eb61a/#file-homebridge-service
- Check homebridge location - response should be usr/bin or usr/local/bin
$ which homebridge
/usr/bin/homebridge
- Edit /etc/systemd/system/homebridge.service - set ExecStart to homebridge location (e.g. usr/bin/)
$ cat /etc/systemd/system/homebridge.service
[Unit]
Description=Node.js HomeKit Server
After=syslog.target network-online.target
[Service]
Type=simple
User=homebridge
EnvironmentFile=/etc/default/homebridge
# Adapt this to your specific setup (could be /usr/bin/homebridge)
# See comments below for more information
ExecStart=/usr/bin/homebridge $HOMEBRIDGE_OPTS
Restart=on-failure
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target
- Set execute permissions for service
sudo chmod +x /etc/systemd/system/homebridge.service
- Add Homebridge system account, user and group created, no home directory (-M)
sudo useradd -M --system homebridge
- Create system dir and copy config.json file for new homebridge service - set ownership and write
sudo mkdir /var/lib/homebridge
sudo chmod +w /var/lib/homebridge
sudo chown -R homebridge:homebridge /var/lib/homebridge
sudo cp /home/pi/.homebridge/config.json /var/lib/homebridge/.
- Enable/Run/Check the service
sudo systemctl daemon-reload
sudo systemctl enable homebridge
sudo systemctl start homebridge
sudo systemctl status homebridge
- Check /var/log/daemon.log if anything goes bump.
tac /var/log/daemon.log | less
- Reboot to get the witches out and test service startup
sudo shutdown now -r
- Set up phone via https://support.apple.com/en-us/HT204893
- Debugging: Troubleshooting Guide @ https://github.com/nfarina/homebridge/wiki/Basic-Trouble-Shooting
- Running in terminal window is very helpful
- See Also: Common Issues section in the README
- Apple Home info @ https://www.apple.com/ios/home/
Revision History
That's it for now - works for me! Quite amazed by these little PIs. I'll post some utilization stats at some point in the future. Drop me a line if you see something or have need or comment. Hope it helps
---------------
* T. Pedersen Ventures is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com.
|
|
|