DIY Apple AirPrint/Play & Homekit on Rasperry Pi

Overview

Our HomePi was originally cobbled together to integrate older/non-complaint devices into the world of Apple AirPlay/Print. The little gizmo has evolved over time as devices change in/out around the house and now supports Apple HomeKit to integrate non-compliant 'smart' devices.

The HomePi has worked like a champ for years. This recipe is basically a retrace of my steps for future rebuilds, but may be useful to others.

Migrated to new site spring 2021 - original site/recipe @
http://ventures.tpedersen.net/projects/diyappleairplayprintandhomekitonraspberrypi


Background & Capabilities

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 were 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 seemed to be constantly fumbling with a variety of apps provided with our newfangled smart home (lights, switches, appliances, etc) - Waaay too complicated!

The Raspberry Pi was originally dropped onto our network to fill the Air Gap by emulating Apple AirPlay and AirPrint services and ultimately added HomeKit services so Siri could begin helping out around the house.

Evolution

HomePi V1: Raspberry Pi 1 Model B used to integrate an old network printer into the Apple AirPrint world (Cups).

HomePi V2: Added AirPlay services (Shareport-sync) services to allow iPads/iPhones to stream music to Bose Wave Radio.

HomePi V3: Homekit services (homebridge) added to pull together our 'smart' home. Integrates non-compliant smart devices into Apple Homekit world. V3 also involved simplified OS (DietPi) and RPi 3 Model B hardware.

Home Pi V4: V4 involved an OS (Buster) upgrade and more simplification. AirPrint services were dropped due to new network printer that no longer needed help.

Level of Difficulty & Prep Time

A cheap, easy and fun little project - no programming required but Raspberry Pi/Linux knowledge will come in handy. 1-2 hours to get things installed and running.

Hardware

Our current HomePi hardware profile:

*Affiliate Links - Please note: I may get a kickback from Amazon!

Software

Dietpi is now used for the HomePi foundation. It provides a lite version Raspbian and includes a library of optimized Pi software packages.

Step By Step

DietPi Install

Notes to self on OS Prep (DietPi IS Raspbian) and some handy optimized packages ...

  • Download latest DietPi and Etcher. Follow DietPi Quickstart Guide
    // Originally used DietPi_RPi-ARMv6-Stretch.7z (~90MB Download) //

  • Easiest to start DietPi install with Ethernet, keyboard & monitor then switch to ssh after first boot

  • Automatically resizes partitions, forces password changes and updates itself (~5min)

  • Tweak configuration via SSH using DietPi-config utility. Minimally, set the following:

    • DietPi-Config/Audio Options->Soundcard=usb-dac
      // For shairport-sync w/ usb sound //

    • DietPi-Config/Language&Regional->Local=en.US.UTF-8 + Timezone + Keyboard[us]
      // Season to taste, keyboard and country! //

    • DietPi-Config/Network Adapters->WiFi
      // I setup WiFi @ this point and disconnect ethernet on next boot - Remember to Apply/Restart Network //

    • DietPi-Config/Security->Change Hostname
      // Changing Hostname will force reboot //

  • Install Software via SSH using DietPi-Software utility.

    • Software Optimized - Check the following:

      • Media Systems->Shairport Sync (for AirPlay)

      • System Stats->RPi-Monitor (nice web-based monitor)

      • Printing->CloudPrint (aka cups for AirPrint) - No longer available on DietPi, install CUPS

      • Homebridge is a manual install process, see below

    • Remember to scroll down to do the actual Install - select Go >> Start installation for selected software

  • Final/Favorite tweaks 'n such via command line:

    • Install favorite editor if you don't like nano. I like joe:
      apt-get install joe

    • Disabled WiFi Power Management to be safe
      iwconfig wlan0 power off

AirPrint (Cups)

Our old printer finally passed away, so HomePi no longer provides AirPrint services, but here's the original raspbian recipe ... Last used on Stretch (cups 2.2.1) but it should be close, CUPS is pretty solid and common. Install/setup takes ~30 Mins. Here's the original guide, it may be updated for Buster and beyond.

  • Install avahi - required for network discovery
    sudo apt-get install avahi-discover

  • Installs CUPS and friends
    sudo apt-get install cups cups-pdf python-cups

  • Mod user (e.g. user pi) to be CUPS admin, it will be used to login to web interface
    sudo usermod -aG lpadmin pi

  • Make sure CUPS and friends are running after the install
    ps -A | grep cups
    ps -A | grep avahi

CUPS Config, phase 1: cupsd.conf

  • Edit /etc/cups/cupsd.conf to permit remote browser access via port 631. Double check Lynsay's guide, there were a number of edits here ... in case I miss one

    1. Comment out Localhost restriction & add line to permit access via port 631

      #Listen localhost:631
      Port 631

    2. Permit local network access to cups paths via local network - add "Allow @Local" line right after "Order allow,deny" in following sections for http(s) access to server, admin, config and log pages.

      <Location />
      Order allow,deny
      Allow @Local
      </Location>
      <Location /admin>
      Order allow,deny
      Allow @Local
      </Location>
      <Location /admin/conf>
      AuthType Default
      Require user @SYSTEM
      Order allow,deny
      Allow @Local
      </Location>
      <Location /admin/log>
      AuthType Default
      Require user @SYSTEM
      Order allow,deny
      Allow @Local
      </Location>

    3. Remember to bounce CUPS after config updates

      sudo /etc/init.d/cups restart

CUPS Config, phase 2 - via CUPS web interface @ http://<your PI IP address>:631 (https in latest cups)

  • Log in to CUPS administration using pi system user & password

  • Administration page: check "Share Printers" and "Allow Remote Admin"

  • Administration/Add Printer - "Discovered Network Printers" found our Dell M5200 w/ a couple of tweaks:

HowTo Use AirPrint to print from your iPhone, iPad, or iPod touch by Apple Support

AirPlay (Shairport-sync)

Shairport-sync is fully installed via DietPi-Software utility (above). Project page @ https://github.com/mikebrady/shairport-sync

  • One quick edit to config file @ /usr/local/etc/shairport-sync.conf:
    Change the device "name" to something descriptive or it let it default to hostname - 'name' shows on ipad/iphone/itunes
    as speaker/destination.

    general =
    {
    name = "Family Room Bose";
    interpolation = "soxr";
    };

Apples Support's article on using Apirplay - How to AirPlay Audio

HomeKit (HomeBridge)

HomeBridge is still not part of DietPi software library ... manual install required, but it's a LOT easier than it used to be!

This will still take some time, count on an hour with minimal plugin playtime!

Homepage/info @ homebridge.io, github.com/homebridge/homebridge & Raspberry Pi specifics @ .../wiki/Install-Homebridge-on-Raspbian

  • One important preliminary: Check for plugins for your smart devices before you go through all this install stuff - 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 "homebridge-wemo" or "homebridge-" to browse the library.

  • Also note - no need for sudo if you are logged in as root on DietPi

  • Install Steps are dissected from *new* HomeBridge on Raspian Lite instructions

    • Install Node.js

      # setup repo
      curl -sL https://deb.nodesource.com/setup_12.x | sudo bash -
      # install Node.js
      sudo apt-get install -y nodejs gcc g++ make python
      # test node is working
      node -v
      # upgrade npm (version 6.13.4 has issues with git dependencies)
      sudo npm install -g npm

    • Install Homebridge and Homebridge Config UI X

      sudo npm install -g --unsafe-perm homebridge homebridge-config-ui-x
      # To setup Homebridge as a service that will start on boot use hb-service command.
      sudo hb-service install --user homebridge

    • Log into Homebridge Config UI X (This is NICE!) - Default uc/pw = admin/admin

      http://<ip address of your server>:8581

    • Couple of name changes in Configuration Reference Section of guide
      Note: Service management is now via sudo hb-service restart/stop/start/logs instead of systemctl

  • Config using Config UI X installed above.
    The following is a blow-by-blow of our Smartthings and Nest upgrade - mostly for my sake!
    Steps dissected from
    https://www.npmjs.com/package/homebridge-config-ui-x

  • Set up IOS phone via https://support.apple.com/en-us/HT204893

    • if you forgot your pin/scan code dig it out of systemd journal like I did

      sudo journalctl -u homebridge

  • 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/