I set about to solve problem back in December 2019. Not truly a problem, just an annoyance. In my office I have a music player (RPi 3 + Hifi Berry Pro XLR) that feeds a pair of Behringer powered subwoofers and M-Audio BX5 powered monitors. We have several similar arrangements, creating five separate music zones across the property.
I’ve had this arrangement for years. I’m pretty happy with it, with one exception. The audio gear does not have signal-sensing power on/off. What I wanted was a way to turn the gear on/off automatically based upon the status of the media player. How hard could that be?
Step 1: Amazon Smart Plugs
I started by purchasing some Amazon Smart plugs that were offered cheap on Woot.com. This allowed me remote control of power to the outlet strip. I had control from an app on my phone or an Amazon Echo. I could schedule everything to turn off at night, just in case I’d left it on accidentally. That was a step in the right direction.
Next, I set out to see if there was some way to have the state of the Squeezebox (or PiCorePlayer) control the smart plug. I found that this was not possible. At least, not with the Amazon Smart Plugs. There was no way to trigger the plug directly. I had to issue a command to the Amazon cloud that would in turn control the plug.
Reliance on the Amazon cloud, or any cloud service, is problematic. If our internet connection was down, I had no remote control. As a matter of principle, I didn’t think it was good to have to ask Jeff Bezos for permission to turn the music on/off.
This became a significant point of concern. Our home automation was largely driven by the Echo, which requires internet access. I started to think that a wholly local control scheme would be preferable.
Step 2: TP-Link Kasa Smart Plugs
I detailed my quest to the Squeezebox user community in the Slim Devices forums. Even years after Logitech discontinued the Squeezebox this forum remains relatively active. Eventually, another user pointed me to a Python script that could be run by the Logitech Media server to control a Kasa Smart Plug.
Apparently, these TP-Link Kasa plugs have a locally available API where the Amazon plugs do not. So, I swapped out the Amazon plugs. Good thing all this stuff is cheap. The Amazon plugs could still be used for controlling holiday lights.
Step 3: Home Assistant
About the same time that I received the TP-Link plugs I found out about Home Assistant. Home Assistant is, as the web site says…
Open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server.
I was drawn in by the fact that Home Assistant has an existing integration with Logitech Media Server. It could both control the players and trigger events based upon a change in state. Further, Home Assistant can control the Kasa Smart plugs using the local API. Sweet!
Setting aside the KISS principle entirely, I dove into Home Assistant as the better way to go. After all, I don’t know python and I had some Raspberry Pi hardware available to serve as a host platform.
This is not a “how-to.” I’m not going to into the nitty gritty about how I got everything set-up. In fact, I refer you to this new and quite expansive article at Ars Technica: How to achieve smart home nirvana (or, home automation without subscription)
Our HA server is actually running HASS.IO on a Raspberry Pi 4. Initial installation is about the same as anything for a Pi. Flash the image to an SD card using a PC. Move the card to the Pi, power on and log into a web admin portal. Easy.
HASS.IO is a containerized version of Home Assistant running on a minimal host OS. Updates to the host OS and HA application are done via the web UI or the mobile client.
The only thing even slightly unusual about our installation is that it’s on a Pi4 with a Power-over-Ethernet HAT. I like to use POE where possible so the wee devices run of the UPS that sustains the core switch.
After a bit of time tinkering, I had Home Assistant controlling; Philips Hue lights, Lutron light switches, TP-Link plugs, Squeezeboxes, Netatmo Weather Station and the Fujitsu Halycon air conditioner in my home office. Control of the not-at-all-smart air conditioner was done using Sensibo, as I described previously.
Most of this was readily done using the Home Assistant web UI. Initial integration with the Squeezeboxes require manually editing a few lines of an XML configuration file. Integration with the the Lutron Caseta hubs was the most challenging. It requires multiple steps to extract an XML config file to the Lutron Android app, for import into Home Assistant.
Logging into the HA web UI, this is what we see:
This web user interface is called “Lovelace.” It’s completely configurable. So far, I have only done minimal tinkering with the web UI.
As far as our functionality, at present anything that is a scheduled or triggered function is now executed locally by Home Assistant:
- Yard lights on at dusk.
- Yard lights off at sunset.
- All the house light turn off week days at 9:30am.
- Office lights off at 11pm nightly.
- Halloween and Christmas lights on/off as/when desired.
- When a PiCorePlayer transitions to != OFF its associated speakers are turned on.
- When a PiCorePlayer transitions to OFF its associated speakers are turned off.
- When a PiCorePlayer state has been Idle for 15 minutes its associated speakers are turned off.
Physical Remote Control
The Home Assistant Android app gives me a single, unified remote control of everything. No more switching between apps. It’s relatively easy to create custom UI presentations. Even UI unique a specific user. Thus I could build a UI for Stella’s phone that presented the things she most commonly needs. I haven’t yet, since she mostly uses voice control via Alexa, but I certainly could.
We do not as yet have any direction integration between the Amazon Echo and Home Assistant. They are parallel mechanisms.
HA tracks device state, so it knows when something has been turned on or off. That means that using a voice command to trigger something, say turn on a single light, can in turn trigger additional actions.
As we do things around the house I always consider a means of integration with Home Assistant. For example, I recently installed a new garage door opener. I opted for make/model that had remote control via a smart phone app. That makes integration with HA purely a software issue. Integration via hardware (relays & sensors) is possible, but not as easy or flexible.
I’d like to add a water flow sensor like Flume. This would allow me to setup alerts for certain types of flows. For example, when we accidentally leave the water on an area of the garden.
It’s also possible to integrate video from our security cameras into the HA UI. That would likely require a more capable host platform. It’s something I might consider in the future.
When we bought our home back in 2001 we set about to implement some rudimentary remote control of lighting using the ancient X-10 system. We had handful of lamp modules and a couple of wireless keypads. I bought the RS232 serial interface to try and implement automation via computer, but it was tedious and difficult. Over time the modern IOT world has allowed us to achieve so much more.
A year into use hereabouts, Home Assistant has proven a splendid way to tie all our IOT things together, and reduce our reliance upon third party cloud services. It’s been reliable, and quite a bit of fun. I think we’re just getting started.