Python help

Posted on
Wed Jul 20, 2016 3:23 pm
dz1rfj offline
Posts: 135
Joined: Mar 13, 2016

Python help

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

Thanks
-Brian

Posted on
Wed Jul 20, 2016 4:04 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python help

What type of device are your speakers? Without knowing that, there's no way to know how to turn them off...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jul 20, 2016 5:07 pm
dz1rfj offline
Posts: 135
Joined: Mar 13, 2016

Re: Python help

Jay, they are airplay, the name of the airplay device is "Airplay-Pool"

Thanks

Thanks
-Brian

Posted on
Wed Jul 20, 2016 5:21 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python help

So, what are you using to control them?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jul 20, 2016 6:54 pm
dz1rfj offline
Posts: 135
Joined: Mar 13, 2016

Re: Python help

Sorry - They are controlled via Airfoil, and using applescript, I can do this, but I want to try this in python.

Thanks,

Brian

Thanks
-Brian

Posted on
Wed Jul 20, 2016 8:39 pm
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Python help

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

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Thu Jul 21, 2016 7:57 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python help

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.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Thu Jul 21, 2016 9:30 am
dz1rfj offline
Posts: 135
Joined: Mar 13, 2016

Re: Python help

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

Thanks
-Brian

Posted on
Thu Jul 21, 2016 9:45 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python help

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.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests