Siri Activated Apple TV Sleep Timer

It really shouldn't be this hard

Apple TV logo with a sleeping face emoji I recently added an Apple TV to my bedroom TV. The Apple TV interface is so much better than the ten year old LG Smart TV software. The one issue I have is using the sleep timer. When the TV’s sleep timer turns off the TV, it doesn’t always stop the Apple TV. This led me to look into Apple TV sleep timer options.

No native sleep timer

My wife often watches TV in bed. If she starts a show on Netflix and falls asleep, the entire series will be marked watched by the time we wake up. I tried the TV’s built in sleep timer, but it wouldn’t put the Apple TV to sleep and it would continue to play. On a whim I asked Siri if they could set a sleep timer, but they could not. Google didn’t give me anything for a built in Apple TV sleep timer.

Shortcuts

Multiple subreddits suggested a sleep timer using Apple’s Shortcuts app. The shortcut would simply wait some amount of time and then put the Apple TV to sleep. While the shortcut is waiting, you can’t run other shortcuts (but automations triggered by a schedule or an NFC tag worked just fine).

While I was setting up the Shortcut I ran into a weird quirk. I was unable to actually select my Apple TV.

To actually select my Apple TV in Shortcuts, I had to switch to my account on the Apple TV. I have my Apple ID as the main account, but my wife is an additional Apple ID that is usually active (so she can sync her Apple Arcade progress). If you run into the same problem, try switching accounts.

An Apple TV Sleep Timer

The sleep timer shortcut worked great. It would put my Apple TV to sleep and turn off my TV through HDMI-CEC. My wife didn’t love having to use shortcuts, but she was happy enough. If you’re interested in using this shortcut, It’s on RoutineHub.

Apple TV Sleep Timer on RoutineHub

Using Siri on the Apple TV

Not content to leave well enough alone, I wanted to take this a step further and use Siri on the Apple TV to activate the sleep timer. I could use Siri to active the sleep timer shortcut on my iPhone, but Siri on the Apple TV can’t do much.

In a previous project I setup Homebridge to automate my Sonos. Since I already had Homebridge running, I decided I’d try to use the Homebridge Dummy button plugin to create a Timed Switch. The plugin creates a virtual button in the Home app that you can turn on and will automatically turn off after some amount of time. I created a test button that ran for five minutes and then turned off.

Using Siri on my Apple TV I could turn the button on, and Homebridge would turn the timer off after five minutes. I then created an automation that triggered when the dummy switch turned off. Unfortunately, HomeKit automations are limited in what they can control. At best I could pause the Apple TV.

HomeKit automation pausing Apple TV

Home Assistant

Home Assistant is open source software that pulls together different smart home ecosystems, and it has a very robust automation framework. I was already looking for an excuse to explore Home Assistant, and it looked like it might help with my Apple TV Sleep timer.

My Raspberry Pi is running DietPi and it was fairly simple to install Home Assistant from the DietPi-Software list. There are detailed guides on the Home Assistant site for other hardware and OSes.

Home Assistant Setup

Once I logged in to Home Assistant, I was overwhelmed by all the options and settings. The user experience to add new devices and create automations definitely needs some work, but I clicked around and figured it out.

First I went to the integrations page (Settings > Devices & Services > Integrations) to add the Apple TV integration. This exposes my Apple TV in Home Assistant so Home Assistant can display the media being played, and, more importantly, send commands to the Apple TV. One of the quirks is that it can’t send a sleep command, but can send combinations of buttons. By sending a long press of the home button and then the select button, it will put the Apple TV to sleep.

Next I went to the Helpers section (Settings > Devices & Services > Helpers) to create a dummy button. I created a button called Sleep Button. The dummy button does nothing, but would be the trigger for the automation.

Finally I created my automation (Settings > Automations & Scenes > Automations) by following the below steps.

  1. Named my automation Apple TV Sleep
  2. Picked Restart for the mode
  3. Added a trigger with a trigger type State and picked my dummy Sleep Button as the entity.
  4. Under Actions added Wait for time to pass with a duration of 30 minutes
  5. Also under actions added Call Service with
    • Service as Remote: Send Command
    • Targets with the Apple TV Remote Entity
    • Command as “- home_hold” on line 1 and “- select” on line 2
    • Delay Seconds enabled with 1 second

Expose Home Assistant Devices in HomeKit

The last setup step was to expose Home Assistant devices in the Home app. Back on the integrations page, I added the HomeKit integration. The integration makes Home Assistant entities available in HomeKit and controllable with Siri.

One downside of the integration is that, by default, it exposes all Home Assistant entities to HomeKit. Some of my devices (like smart lights) appeared in HomeKit twice. I had to edit my Home Assistant’s configuration.yaml to only make the Sleep Button entity available in HomeKit.

After several hours experimenting with Home Assistant, I was finally able to activate my Apple TV sleep timer with Siri. In the video below I changed the delay from 30 minutes to 15 seconds.

After all the work I put into this, it's kind of anticlimactic

Wrap Up

While this worked, it was way too much work. I’m excited to see what else I can do with Home Assistant, but it wasn’t worth the effort just for this project. My advice is to just use the Apple TV Sleep Shortcut. It works well and is pretty easy to setup.


See also