Sp here is more of an example of what I am trying to do.
I want a universal "Sonos On" action that will work regardless of situation -- if Sonos is on mute but playing, this action will just unsure and do nothing more.
If Sonos is not playing, this action will play a certain station based on month/day of week (and in the future, hour, when I decide to listen to something else at night).
I need some help on the actual "Play this station" part -- you can see some comments in the existing code.
I'm doing this because of reliability and performance issues with my current action group(s) that do this. I figured having this in code would work better.
I've sone it in both indigo python and regular python using SoCo. Seems harder with SoCo -- more of a delay in getting my own station to play (That's as far as I went).
Thoughts on this?
Thanks
- Code: Select all
sonosID = "com.ssi.indigoplugin.Sonos"
sonosPlugin = indigo.server.getPlugin(sonosID)
from datetime import datetime
SonosLivingRoom = indigo.devices[1904190489] # "Sonos Living Room"
SonosTVRoom = indigo.devices[89173419] # "Sonos TV Room"
SonosOffice = indigo.devices[393468053] # "Sonos Office"
SonosRowingRoom = indigo.devices[986089169] # "Sonos Rowing Room"
SonosBasement = indigo.devices[1177387431] # "Sonos Basement"
SonosBedroom = indigo.devices[1413241449] # "Sonos Bedroom"
def checkZones(zInput, zMaster):
if zInput.states["ZoneGroupID"] == zMaster.states["ZoneGroupID"]:
indigo.server.log("Zone for " + str(zInput.states["ZP_ZoneName"]) + " is already in the zone controlled by " + str(zMaster.states["ZP_ZoneName"]) + ". No action needed.")
else:
indigo.server.log("Zone for " + str(zInput.states["ZP_ZoneName"]) + " is not equal to master")
sonosPlugin.executeAction("actionZP_addPlayerToZone", props={'setting':zInput.id}, deviceId=zMaster.id)
return
def CheckTheZones ():
checkZones (SonosLivingRoom, SonosLivingRoom)
checkZones (SonosTVRoom, SonosLivingRoom)
checkZones (SonosOffice, SonosLivingRoom)
checkZones (SonosRowingRoom, SonosLivingRoom)
checkZones (SonosBasement, SonosLivingRoom)
checkZones (SonosBedroom, SonosLivingRoom)
return
def WMAL ():
print ("WMAL Function Called")
# Need to figure out how to play stuff on Sonos
return
def ChristmasMusic():
print ("Play some Christmas Music")
# Need to figure out how to play stuff on Sonos
return
def SaturdayMusic():
print ("Play some Saturday Music")
# Need to figure out how to play stuff on Sonos
return
def playSelector ():
print ("Play Selecter Called")
day, month, hour = datetime.now().strftime("%w, %m, %H").split(',')
if str(month).replace(" ", "") == "12" and str(day).replace(" ", "") == "7":
ChristmasMusic()
elif str(day).replace(" ", "") == "6":
SaturdayMusic()
else:
WMAL()
return
# Check Zones. Make sure everybody is part of Living Room Zone. Do this before even checking if it is playing or not.
CheckTheZones()
if SonosLivingRoom.states["ZP_STATE"] == "PLAYING" and SonosLivingRoom.states["ZP_MUTE"] == "1":
sonosPlugin.executeAction("actionGroupMuteOff", deviceId=SonosLivingRoom.id)
else:
indigo.server.log("SonosLivingRoom not on mute and not currently playing. Beginning to play")
# Add function to turn on Yamaha Receivers (both zones each) and set volume
playSelector()