🎖️ Honor tradition with tech — This project plays the bugle calls Colors at 8:00 AM and Taps at sunset on a Sonos speaker automatically every day.
✅ Play colors.mp3 at 0800 sharp every morning
🌅 Dynamically calculate sunset time to play taps.mp3
🔇 Pause what's playing and restore it after the call
📄 Log every playback to /opt/flag/sonos_play.log
📡 Serve your MP3s via a tiny HTTP server
⚙️ Customize everything via /opt/flag/config.json
- 🐍 Python 3.8+
- 📶 Sonos speaker on the local network
- 🖥️ Ubuntu/Debian VM or LXC container (Proxmox-ready)
- 🎧 Your own
colors.mp3andtaps.mp3in/opt/flag/audio/
Download and run the setup script from any directory (e.g., /root or /opt):
wget --no-cache https://raw.githubusercontent.com/agster27/flag/main/setup.sh -O setup.sh
chmod +x setup.sh
./setup.shYou will be prompted with:
- Update/install the latest scripts (recommended for first install or upgrades)
- Uninstall completely (removes all files and cron jobs)
- Exit without doing anything
The script will automatically download all required files from GitHub using wget (no
git cloneneeded), create a Python virtual environment, install dependencies, and generate a defaultconfig.jsonif needed.
After setup, your /opt/flag/ folder should look like:
/opt/flag/
├── sonos_play.py # Plays the MP3
├── sunset_timer.py # Calculates sunset
├── schedule_sonos.sh # Adds dynamic sunset cron
├── audio_check.py # Audio check script
├── README.md # Project readme (downloaded for reference)
├── LICENSE # Project license (downloaded for reference)
├── requirements.txt # Python requirements (downloaded for reference)
├── sonos_play.log # 🎯 Log file (created at runtime)
├── config.json # 🔧 Settings (auto-generated if missing)
├── sonos-env/ # 🐍 Virtual environment
└── audio/
├── colors.mp3 # 🎶 Morning bugle call (add your own)
└── taps.mp3 # 🌅 Evening taps (add your own)
A systemd-managed HTTP server is set up to serve your audio files directly from /opt/flag/audio/.
You do not need to run git clone or start the server manually.
Your files will be available at:
Check the server status or restart it with:
sudo systemctl status flag-audio-http
sudo systemctl restart flag-audio-httpEdit /opt/flag/config.json to match your Sonos and preferences:
{
"sonos_ip": "192.168.1.50",
"volume": 30,
"colors_url": "http://flag.aghy.home:8000/colors.mp3",
"taps_url": "http://flag.aghy.home:8000/taps.mp3",
"default_wait_seconds": 60,
"skip_restore_if_idle": true,
"latitude": 42.1,
"longitude": -71.5,
"timezone": "America/New_York"
}After setup, you should test that all components work:
Check if your audio files are served correctly:
curl -I http://localhost:8000/colors.mp3
curl -I http://localhost:8000/taps.mp3You should see HTTP/1.0 200 OK in the response headers.
You can also test in your browser: http://flag.aghy.home:8000/colors.mp3
To test playback without waiting for the scheduled time, run:
/opt/flag/sonos-env/bin/python /opt/flag/sonos_play.py http://flag.aghy.home:8000/colors.mp3or, for taps:
/opt/flag/sonos-env/bin/python /opt/flag/sonos_play.py http://flag.aghy.home:8000/taps.mp3If it works, you'll hear the audio play on your Sonos and see log output in /opt/flag/sonos_play.log.
-
Check that the cron jobs are installed:
crontab -l
-
You should see entries for the morning and sunset calls.
-
To test scheduling, you can temporarily edit the crontab to run a minute in the future and observe playback.
Review the log file for any errors or confirmations:
cat /opt/flag/sonos_play.log- Check audio server:
sudo systemctl status flag-audio-http - Check logs:
cat /opt/flag/sonos_play.log - Check crontab:
crontab -l - Test playback manually:
See the section above on manual testing.
Created by agster27.
Inspired by tradition, powered by Python and Sonos.