Python and Airfoil

Posted on
Mon Oct 16, 2017 9:19 pm
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Python and Airfoil

So I've read the Wiki for AirFoil, and it has been a big help, since my Python ability is limited. I am curious about "chaining" commands... like the ability to connect 2 different speakers... or connect a speaker and set the volume....

While the following does work, I'm curious is there is a simpler way to do this, since most of the 2 commands are identical. I've tried a few things, re-arranging pieces, parts, deleting things that seemed redundant, including listing the execute actions part in (parentheses) back to back, then with a space, and then with a comma, but didn't get anywhere..

Is there a way to make multiple commands like this simpler?



Code: Select all
airfoilPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.airfoilpro")
if airfoilPlugin.isEnabled():
    try:
        result = airfoilPlugin.executeAction("connect", deviceId= 1346544642, waitUntilDone=True)  # ID of Speaker device
    except Exception, e:
        print "Exception occurred: %s" % unicode(e)


airfoilPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.airfoilpro")
if airfoilPlugin.isEnabled():
    try:
        result = airfoilPlugin.executeAction('setVolume', deviceId=1346544642, props={'volume': 52}, waitUntilDone=True)  # ID of Speaker device
    except Exception, e:
        print "Exception occurred: %s" % unicode(e)

Posted on
Tue Oct 17, 2017 4:16 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python and Airfoil

Code: Select all
airfoilPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.airfoilpro")
if airfoilPlugin.isEnabled():
    try:
        result = airfoilPlugin.executeAction("connect", deviceId= 1346544642, waitUntilDone=True)  # ID of Speaker device
    except Exception, e:
        print "Exception occurred  on connect: %s" % unicode(e)
    try:
        result = airfoilPlugin.executeAction('setVolume', deviceId=1346544642, props={'volume': 52}, waitUntilDone=True)  # ID of Speaker device
    except Exception, e:
        print "Exception occurred on setVolume: %s" % unicode(e)

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Tue Oct 17, 2017 6:49 am
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: Python and Airfoil

Thanks ever so much

this is one of the combos that I tried, but obviously didn't have something exactly right.

Posted on
Tue Oct 17, 2017 6:52 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python and Airfoil

Notice I added text to identify which exception was caught. You probably want to change the print statements to indigo log statements.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Tue Oct 17, 2017 9:53 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python and Airfoil

You could further simplify by putting all calls in the same try block:

Code: Select all
airfoilPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.airfoilpro")
if airfoilPlugin.isEnabled():
    try:
        result = airfoilPlugin.executeAction("connect", deviceId= 1346544642, waitUntilDone=True)  # ID of Speaker device
        result = airfoilPlugin.executeAction('setVolume', deviceId=1346544642, props={'volume': 52}, waitUntilDone=True)  # ID of Speaker device
    except Exception, e:
        print "Exception occurred: %s" % unicode(e)


Exceptions here are pretty unlikely, so my guess is that if the first one works the second one will almost always work, and any exception you get will very likely be because of some systemic problem and you're probably seeing a LOT of other problems as well.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Aug 06, 2019 5:22 pm
mgolden50 offline
User avatar
Posts: 247
Joined: Jan 29, 2007
Location: Chandler, AZ

Re: Python and Airfoil

Hi Jay,

I've been trying to use your example below for how to set speaker volumes and it doesn't change the volume levels shown on the Airfoil UI.

airfoilPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.Airfoil")
if airfoilPlugin.isEnabled():
airfoilPlugin.executeAction("setVolume", props={'volume':"99", 'speakerIds':["127530933","1824678982"]})

Also can you provide a Python example for getting a speaker volume setting into a local Python variable?

Thanks,
Mike

Posted on
Tue Aug 06, 2019 5:58 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python and Airfoil

You have the volume as a string rather than a number.

Code: Select all
airfoilPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.Airfoil")
if airfoilPlugin.isEnabled():
    airfoilPlugin.executeAction("setVolume", props={'volume':99, 'speakerIds':["127530933","1824678982"]})


I have no idea if that syntax is correct for multiple speakers.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Aug 07, 2019 8:27 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python and Airfoil

FlyingDiver is correct - volume should be a number.

Examine the Set Volume action script example:

Code: Select all
airfoilPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.airfoilpro")
if airfoilPlugin.isEnabled():
    try:
        result = airfoilPlugin.executeAction('setVolume', deviceId=135305663, props={'volume': 50}, waitUntilDone=True)  # ID of Speaker device
    except Exception, e:
        print "Exception occurred: %s" % unicode(e)


The action targets a single speaker, so you specify the speaker device using the deviceId param. To set the volume on multiple speakers, you need one executeAction call per speaker.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Aug 17, 2019 10:57 am
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: Python and Airfoil

Belated THANKS!

Posted on
Wed Jul 06, 2022 6:25 pm
Alain offline
Posts: 88
Joined: Apr 19, 2008

Re: Python and Airfoil

Hi,

Since the recent update to Python, I am not getting an error when I set the Airfoil volumes from variables.

The error seems to be associated with the line:
exception Exception, e:

and the error I get is: "multiple exception types must be parenthesized".

Can anyone help?
Thanks
Alain

Posted on
Wed Jul 06, 2022 7:56 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python and Airfoil

Are you using the old Airfoil plugin or the Airfoil Pro plugin included with Indigo?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jul 06, 2022 7:59 pm
Alain offline
Posts: 88
Joined: Apr 19, 2008

Re: Python and Airfoil

I believe the one that comes with Indigo. I haven’t done anything deliberate to stay with an old plug-in.

Posted on
Thu Jul 07, 2022 5:58 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python and Airfoil

Alain wrote:
I believe the one that comes with Indigo. I haven’t done anything deliberate to stay with an old plug-in.


What's the actual name of the plugin in the plugin list?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Thu Jul 07, 2022 6:02 am
Alain offline
Posts: 88
Joined: Apr 19, 2008

Re: Python and Airfoil

In the Plugin list, it says Airfoil Pro, and in its pulldown menu it says "About Airfoil Pro v2022.1.0"

Posted on
Thu Jul 07, 2022 6:03 am
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Python and Airfoil

Can you copy the complete section of the log with the error? It should have a code line number.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Who is online

Users browsing this forum: No registered users and 1 guest