Page 1 of 1

Python help

PostPosted: Wed Jul 20, 2016 3:23 pm
by dz1rfj
HI,
:?:
How can I get the simple script below to disconnect / mute pool speakers if it is before 7:30 AM , then pause 2 seconds to ensure the speakers were shut off? Wife tells me the neighbors do not need to know the time that early in the morning... :roll:


import datetime
---If time is less than 7:30 AM, turn off pool speakers, but time will run in rest of house so everyone stays on schedule ....... ---Name of speakers to be muted, or turned to zero is "Airplay-Pool"
indigo.server.speak ("The time is %s" % datetime.datetime.now().strftime('%I:%M %p'))


Thanks

Re: Python help

PostPosted: Wed Jul 20, 2016 4:04 pm
by jay (support)
What type of device are your speakers? Without knowing that, there's no way to know how to turn them off...

Re: Python help

PostPosted: Wed Jul 20, 2016 5:07 pm
by dz1rfj
Jay, they are airplay, the name of the airplay device is "Airplay-Pool"

Thanks

Re: Python help

PostPosted: Wed Jul 20, 2016 5:21 pm
by jay (support)
So, what are you using to control them?

Re: Python help

PostPosted: Wed Jul 20, 2016 6:54 pm
by dz1rfj
Sorry - They are controlled via Airfoil, and using applescript, I can do this, but I want to try this in python.

Thanks,

Brian

Re: Python help

PostPosted: Wed Jul 20, 2016 8:39 pm
by DaveL17
I believe this will work for the first part, and includes an additional test for time. Sorry, I'm not familiar with Airfoil.

Code: Select all
from datetime import datetime, time

now = datetime.now()
now_time = now.time()

if time(7,30) < now_time < time(21,30):
    # Do some Airfoil stuff here.
else:
   pass

Re: Python help

PostPosted: Thu Jul 21, 2016 7:57 am
by jay (support)
Assuming you're using the Airfoil plugin:

Code: Select all
airfoilPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.Airfoil")
if airfoilPlugin.isEnabled():
   airfoilPlugin.executeAction("disconnectFromSpeaker", props={'speaker':"SPEAKERIDHERE"})


For details on Airfoil scripting, see the Airfoil Plugin's docs.

Re: Python help

PostPosted: Thu Jul 21, 2016 9:30 am
by dz1rfj
So would my complete script look like this ? What does 'pass' do ?

Thanks!


Code: Select all
from datetime import datetime, time

now = datetime.now()
now_time = now.time()

if time(7,30) < now_time < time(21,30):
    # Do some Airfoil stuff here.
    airfoilPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.Airfoil")
    if airfoilPlugin.isEnabled():
       airfoilPlugin.executeAction("disconnectFromSpeaker", props={'speaker':"28CFE97EA754"})

else:
   pass

Re: Python help

PostPosted: Thu Jul 21, 2016 9:45 am
by jay (support)
If you don't need to do anything if the time comparison is false, then you don't need the else. pass is just a do-nothing placeholder.