Using Sonos API to be a better neighbour

The plan is to get SoCo, a FOSS Sonos controller Python project, to tweak various aspects of the Sonos connected devices in the home at different times.

* Turn bass down to a lower level 8:30PM
* Turn back up 7AM

* If the volume is higher than a certain level after 10PM, set an alert (or turn it down)

SoCo could run on a Pi easy enough. Setting up the actions and timers could be done as a cron job - just drop a bash script as a cron and trigger actions at key times. That's nice and scalable (lol).

Thinking about if someone breaks in to the network, do I need to secure the machine? It's always a good idea, but if they're in the network anyway, then hey. They can piss about with SonosNet as much as they want without my badly written scripts.

Bass goes from -10 to +10, so this should set it nearly all the way off:

from soco import SoCo
my_zone = SoCo('Lounge')
my_zone.bass = -9

Then to set it back again, easy enough:
from soco import SoCo
my_zone = SoCo('Lounge')
my_zone.bass = -3

Volume is between 0 and 100. At night, we could do a one time setting to lower this to 20 or so:
from soco import SoCo
my_zone = SoCo('Lounge')
my_zone.volume = 20

However if it's already lower than 20, we don't want to turn it up to 20. So we should check first.
from soco import SoCo
my_zone = SoCo('Lounge')
currentVolume = my_zone.volume
if currentVolume > 20:
     my_zone.volume = 20




Comments

Popular Posts