Using Firewalla to broadcast messages to Sonos speakers
Hey all..
Over the last 10 years, I had an automation device, saying at a various occurence messages to a loud speaker. It came to a point where this device is not helpful anymore with an old interface.. but I also saw that there is a python command line availabe to manage Sonos equipment.. which I m having !! :-)
Warning> This is maybe not the best idea to connect home automation to security equipement...
Anyhow.. first ... soco and soco-cli to control Sonos Equipment from any python command line, run:
sudo -H pip install -U soco-cli
Then.. you can discover your environment directly (if connected to the same household as the speakers) from any command prompt / shell :
sonos-discover
Now.. you should RTFM... There is an extensive Git repo for this package.. really well described to play, make snapshots, resume, use favorites..
But.. IN SHORT : To play a file command line is
sonos SPEAKER play_file FILENAME
Hense, play mymusic MP3 file on the Kitchen speaker.. (assuming mp3 is on the same folder for sure)
sonos Kitchen play_file mymusic.mp3
This is the theory on a raspberry Pi, I indeed tried on a Windows 11 :-)
With Firewalla this is a bit more epic, because each reboot will remove the formerly installed packages, or manual entries in the crontab, Indeed.. Crontab is not really having the smae paths as user or root.. as I understood..
First, install your best PuTTy client, and connect to your firewalla with something like
C:\Users\Username>putty pi@192.168.xx.xx -pw vNbzQdCSS7
Where you have the correct ip from Firewalla and the password generated through the Firwealla App (Settings > Advanced > Configurations > SSH Console > Tap on password)
As you may have understood. You would need to
1) Install the pip + soco-cli package
2) Configure a persistent Cron job
Reading through the community and support posts, I found out a way.. this may not be the best way - but it works.
1----
mkdir /home/pi/.firewalla/config/post_main.d/
vi /home/pi/.firewalla/config/post_main.d/socosetup.sh
sudo apt-get update
sudo apt-get install -y pip
sudo -H pip install -U soco-cli
2----
vi ~/.firewalla/config/user_crontab
*/5 * * * * /usr/local/bin/sonos Kitchen if_stopped play_file mymusic.mp3 &> /tmp/sonoscmd.log
sudo reboot
Note: If you want to start playing the sound now in a cron job, just edit crontab -e.. but this won't persist after a reboot unless written under ~/.firewalla/config/user_crontab
And.. then.. after the next reboot.. pip will be installed, with soco and each 5 minutes, you will ear this mymusic in the Kitchen
Hope this helps.. ;-)
Please sign in to leave a comment.
Comments
0 comments