For a while my leaving-the-house automation only did two things: lock the front door and arm the alarm. Everything else kept running. If I walked out with a show playing, the TV played to an empty room until I got back, and so did whatever was on the speakers. I finally sat down to fix that. It turned into a longer rabbit hole than I expected, mostly around getting Plex to pick back up where I left off.
This is where it ended up, plus the parts that wasted my time getting there.
turn_off doesn’t turn off a Shield
My first attempt was the obvious one: call media_player.turn_off on the TVs when the house goes empty. My TVs are NVIDIA Shields, and on a Shield that just stops the app. The TV stays on.
I already power my Shields with ADB in my sleep and wake scripts, so I reused that. androidtv.adb_command with POWER actually cuts the screen. The catch is POWER is a toggle, not a real on or off, so the automation checks the current state first and only sends it if the TV is on. Same pattern my sleep script already used, just backwards.
That part was easy. Turning things back on was where it got interesting.
SmartTube comes back on its own. Plex doesn’t.
I tested a full power cycle while I was watching something. Off, then back on. In SmartTube it came right back playing where it was, nothing for me to do. Then I tried it on Plex and it dropped me on the Plex home screen instead of my show.
Plex won’t show up until you flip a setting
Before I could tell Plex to play anything, I hit a wall. The Plex player entity in Home Assistant, the thing you send play commands to, wasn’t there at all. It only exists while something is already playing.
The fix was a setting on the Shield. In the Plex app, Advertise as player has to be on. Mine was off on the upstairs box. My kitchen TV already worked, which is how I knew the automation itself was fine and the upstairs Shield was the odd one out. Turned it on, ran a scan, and the player showed up.
Playing the show and resuming the show are not the same thing
With the player available, I sent a normal play command for the episode. It played. From the beginning.
Plex knows where I was. Open the app and Continue Watching drops you back in the right spot. But sending a play command by the item’s ID just starts it at zero. The saved position isn’t part of that call.
So I passed the ID with a resume flag. That one broke the Shield: it sat on the Plex menu playing the episode’s audio with no picture. I ran it twice to be sure it wasn’t a fluke. Same thing both times.
What worked was playing by the show’s details instead of its ID, so library, show name, season, episode, and a resume flag. That uses Plex’s own saved position. I powered the TV off partway into an episode, tapped resume, and it came back playing where I’d left it.
The automation that lit up an empty room
One thing I didn’t see coming. I have a separate automation that turns the upstairs lights on when Plex stops, so the room isn’t black when a movie ends. Fine when I’m home. But leaving the house stops Plex, which tripped it, so walking out turned the lights on in an empty living room. That automation now checks someone’s actually home before it runs.
Music was the easy part
For the HomePods I pause instead of stopping. Pausing keeps the queue, so on the way back a plain play command picks it up. No metadata gymnastics like Plex needed.
Not letting it lock me out or trip on a bad GPS reading
Two things I cared about. First, none of the media stuff should be able to get in the way of the door and the alarm, so the media block runs after the lock and arm, and every step is set to keep going if it errors. A Shield that doesn’t answer can’t stop the house from locking. Second, false alarms. My presence is phone GPS and GPS drifts, so the lock and arm already sit behind a 30 second cancel window with a second presence check before it commits. The media shutdown lives inside that same gate. A blip that flips me away for a few seconds and corrects doesn’t turn anything off.
Where it is now
Everyone leaves: TVs off, music paused, doors locked, alarm armed. I get back: one notification asking if I want to pick up where I left off. Tap it and Plex relaunches to my spot, SmartTube resumes itself, and the music starts again.
Coming back is one tap on purpose. I didn’t want the TV blasting the second I open the door, so resume is a choice, not automatic. That’s the piece I might change if the tap starts to annoy me.