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.py for persistent token handling on Windows

๐Ÿ“‚ Files

roonapi.py

  • Custom patched version of the Roon API Python module
  • Adds token_path support 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:
    • PLAYING if any zone is active
    • IDLE if 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.flag exists
  • Calls check_playback.py for 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

  1. Place all files in:
    C:\Scripts

  2. Run check_playback.py once โ†’
    Authorize in Roon Remote โ†’
    Token saved to roon_token.json

  3. 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"
    
  4. 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 .flag to 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 .flag file enables manual sleep override
  • Fully offline-friendly โ€“ no cloud dependency
  • Extensive logging to aid in debugging and monitoring

๐ŸŽง Enjoy intelligent, robust sleep automation for your Roon-based audio system!