Automating a Home Theater with Home Assistant

Theater of Screams
Disclaimer: Theater enjoyment may be dimished by using it to watch Manchester United

I built out a home theater in my house a couple of years ago, in what used to be a bedroom. From the moment it became functional, we started spending most evenings in there, and got into the rhythm of how to turn it all on:

  • Turn on the receiver, make sure it's on the right channel
  • Turn on the ceiling fan at the right setting
  • Turn on the lights just right
  • Turn on the projector, but not too soon or it will have issues
  • Turn on the Apple TV, which we consume most of our content on

Not crazy difficult, but there is a little dance to perform here. Turning on the projector too soon will make it never be able to talk to the receiver for some reason (probably to prevent me from downloading a car), so it has to be delayed the right number of seconds otherwise you have to go through a lengthy power cycle to get it to work.

It also involves the location of no fewer than 5 remote controls, 3 of which use infrared. The receiver is hidden away in a closet, so you had to go in there to turn that on, remote control or no. Let's see if we can automate this so you can turn the whole thing on with a single button.

IR is not a good solution

The first thing I tried were these IR Repeaters, which I figured would allow me to keep the receiver remote in the theater and not have to go into the closet. I tried a few different models but they were all super weak for some reason, despite being plugged in, to the extent that you need to position the re-emitter within inches of the device's IR sensor. I couldn't achieve that in a way that wasn't ugly with wires hanging everywhere, so I gave up on that idea.

Then I tried these Bestcon IR Blaster things, which in theory allow you to record remote control buttons and repeat them. The IR Blaster can join your network, which means it can be automated using Home Assistant, which I use extensively around the house already. I planned to place one of these in the theater itself (for the projector) and another in the closet (for the receiver).

This kinda worked, but it was a bit of a pain to program and they just weren't reliably triggering the devices. Significantly more than zero percent of the time the signal didn't get through, and as with the IR repeaters, you end up with more wires hanging around as it still relies on line-of-sight to the IR sensor. It's also another moving part, something to go wrong, and another random device on your network so it seems this has more downsides than up.

Finally, the coup de grace was that the IR Blaster doesn't know what state your devices are in (bad if you're trying to turn on your device, it's already on, and now you just toggled it off), nor does it know if the command it tried to send was received or needs to be re-tried. There must be a better way...

TCP/IP to the rescue

It turns out all of the devices I wanted to control were network-connectable. In the case of the receiver (a Denon AVR-X6700H) and the projector (a Sony VPL-VW325ES), there's an ethernet port that lets you plug it directly into your network.

Sony Projector Web UI
The Sony Projector web UI is basic but informative and with some basic setup functions

Both of these devices actually expose a little HTTP server hosting a basic web app. These allow you to both power on/off the device, and do things like change input. The receiver, pleasingly enough, actually publishes a pretty complete API, which allows you to do basically anything you could do with the remote in your hand, including advanced configuration. Awesome.

Denon Receiver Web UI
The Denon web UI is rich - you can do a lot with it. Nice to have for sure.

The documentation is extensive, though rather dense. Contained therein is the fact that we can send commands like ZMON and SIBD to the receiver, which will turn it on and Switch Input to the Bluray Disk input respectively. As well as the web UI, the receiver exposes a way to send those odd little commands over HTTP - in this case we can just send a GET request to http://receiver.local:8080//goform/formiPhoneAppDirect.xml?ZMON, which will turn on the receiver's main zone. Swap ZMON for whatever command you want to run. There's no actual iPhoneApp involved here, but I guess from this url that one exists.

As we'll see in a moment, that's all we need to know to get Home Assistant able to control both of these devices.

Home Assistant Preparation

Home Assistant already has built-in support for controlling the Sony Projector, so now that it has an IP on our network we can just tell Home Assistant where to find the Projector. As per the docs, this requires a manual edit to configuration.json, which is unusual but easy enough.

There are several ways to edit that file, the easiest probably being to use the File Editor addon. Again per the docs, this just means adding lines 12-15 to your configuration.yaml file (replace projector.local with the IP of the projector if you don't have fancy local DNS wizardry running):

Home Assistant Projector Switch

Either restart home assistant or reload the YAML so it can pick that up. Now your projector shows up as a persistent switch in home assistant, so you can turn it on/off at will either via the home assistant UI or via scripts and other automations.

To get Home Assistant able to talk to the receiver, I had to install the Denon AVR integration. That's pretty easy and gives you a pretty basic device page for the receiver, where you can turn it on/off but not much else:

Home Assistant Receiver Device

But it also gives 3 addition services you can call in your automations, one of which is the all-important Denon AVR Network Receivers: Get command.

The Script

At this point the script is pretty easy. In order, we:

  • Use that iPhoneAppDirect.xml path to send the ZMON command (Zone Main On) to the receiver
  • Turn on the fan (using the Bond integration we fixed last time)
  • Set the correct lighting scene (all Philips Hue fixtures and LED strips in this case)
  • Wait the right number of seconds so the projector can talk to the receiver properly
  • Call the receiver again to switch to the XBox input (SIBD)
  • Call the Switch: turn on service on the Projector entity that we added to configuration.yaml

Home Assistant Theater On Script

We switch to the XBox input first in case we're going to watch a Bluray, otherwise we just press any button on the Apple TV remote to wake that device up and the receiver automatically switches to it. There is also a Theater Off script, which basically does the opposite of the above.

An occasionally useful feature is that we can now turn the theater on and off remotely. As the projector does take a couple of minutes to warm up it can be nice to turn it all on with one button on my phone and then waddle over there a couple of minutes later to find everything ready.

Triggering with a light switch

As I had switched all of the lights in the room to be various Philips Hue fixtures and light strips, the 2-gang light switch box by the entry door suddenly became redundant as all of the lights were permanently powered. This gave a delightful opportunity to install on and off switches in their stead:

Physical Switches to turn the theater on and off
The fact these things are a little beat up is just proof of how useful they are...

These two switches are not connected to any power source, but to a Philips Hue Wall Switch Module, which is just a simple battery-powered device that detects when you flip the switch and exposes that event to the rest of the Hue ecosystem. Because Hue integrates well with Home Assistant, that means we can trivially use it as a trigger for our automations.

The Hue wall module approach works well for this, even though it's not really what it's designed for. All it does is track when a switch is flipped - it doesn't know whether it's on or off, doesn't stop you from flipping it several times (though Home Assistant can dedupe that if necessary), and some day the battery will need to be replaced, but it's served as an excellent solution for us. It also means guests don't have to figure out how to turn everything on/off correctly - just flip the switch.

Possible Extensions & Limitations

Home Assistant can also integrate more deeply with XBox and Apple Tv. In the case of XBox, this requires you to switch it into a much more power-hungry standby mode, which would have the device consuming 30 watts in standby. That's a huge amount of power to spend to basically just enable HA to turn it on and off, so I passed on that.

Similarly, HA can integrate more deeply with Apple TV - loading content as well as just turning it on/off. But, as we use a variety of different apps, the integration wouldn't have much of a chance of knowing which one we're going to choose, so while there's no real power consumption downside, it just wouldn't be useful in our case.

Share Post:

What to Read Next