RoonCommandLine + SmartSleep Integration for Windows
July 11, 2025 ยท View on GitHub
By Jon Spijker โ July 2025
๐ง Overview
This setup enables a Windows-based Roon Core (optionally with HQPlayer) to enter reliable S3 sleep mode automatically when idle โ while intelligently staying awake during playback or media activity.
It combines:
- โ
A Python script (
check_playback.py) to detect Roon playback via the Roon API - โ
A PowerShell script (
SmartSleep.ps1) with:- Logging
- Mutex protection
- Manual override flag
- Fallback audio detection (via SoundVolumeView)
- Optional Plex Media Server activity detection
- โ
A patched
roonapi.pyfor persistent token handling on Windows
๐ Files
roonapi.py
- Custom patched version of the Roon API Python module
- Adds
token_pathsupport for Windows - Replace the original at:
C:\Python313\Lib\site-packages\roonapi\roonapi.py
check_playback.py
- Lightweight Python script
- Connects to the Roon Core via API
- Returns:
PLAYINGif any zone is activeIDLEif no playback is detected
- Stores token at:
C:\Scripts\roon_token.json
SmartSleep.ps1
Main automation script:
- Uses a mutex to prevent double execution
- Skips sleep during Roon backup window (2:00โ5:00)
- Aborts if
smartsleep_disabled.flagexists - Calls
check_playback.pyfor Roon state - Fallback: detects active audio devices via SoundVolumeView
- Optional: delays sleep if Plex server is active (CPU/memory thresholds)
- Logs all events to:
C:\Scripts\smartsleep.log - Triggers S3 sleep via
psshutdown
๐ Requirements
-
Windows 10 or 11
-
Roon Core and/or HQPlayer
-
Python 3.11+ installed at
C:\Python313 -
Roon API client:
pip install git+https://github.com/RoonLabs/python-roon.git -
PsShutdown (Sysinternals)
-
SoundVolumeView by NirSoft
โ๏ธ Setup
-
Place all files in:
C:\Scripts -
Run
check_playback.pyonce โ
Authorize in Roon Remote โ
Token saved toroon_token.json -
Edit paths in
SmartSleep.ps1:$python = "C:\Python313\python.exe" $checkPlayback = "C:\Scripts\check_playback.py" $soundview = "C:\Tools\SoundVolumeView.exe" $disableFlag = "C:\Scripts\smartsleep_disabled.flag" -
Schedule SmartSleep.ps1 to run every 10 minutes using Windows Task Scheduler
๐ฒ Optional: Siri Shortcuts / SSH Control
- Start Mediaserver: SSH into Raspberry Pi โ delete
smartsleep_disabled.flag - Stop Mediaserver: SSH โ create
.flagto pause sleep logic
๐ Notes
- Uses mutex to avoid overlapping tasks
- Designed for HQPlayer users where glitch-free DSD playback is critical
- Plex detection includes CPU/memory usage โ sleep may be delayed after a stream ends
- Simple
.flagfile enables manual sleep override - Fully offline-friendly โ no cloud dependency
- Extensive logging to aid in debugging and monitoring