How to get name of Trigger in a Python Action script?

Posted on
Sun Nov 08, 2020 7:57 pm
wideglidejrp offline
User avatar
Posts: 555
Joined: Jan 15, 2012
Location: Danbury, CT

Re: How to get name of Trigger in a Python Action script?

Action Group Sonos Test Action Group List
Script Error sonos_action_groups.py: 'ActionGroup' object does not support indexing
Script Error Exception Traceback (most recent call shown last):

sonos_action_groups.py, line 2, at top level
TypeError: 'ActionGroup' object does not support indexing

John R Patrick
Author of
Home Attitude

Posted on
Sun Nov 08, 2020 8:07 pm
FlyingDiver offline
User avatar
Posts: 7211
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: How to get name of Trigger in a Python Action script?

Check your case. The initial A should not be capitalized.


Sent from my iPhone using Tapatalk

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

Posted on
Sun Nov 08, 2020 8:08 pm
DaveL17 offline
User avatar
Posts: 6751
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: How to get name of Trigger in a Python Action script?

Line 2 should be:
Code: Select all
indigo.server.log(str(actions[0]) + "," + str(actions[1]))

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

[My Plugins] - [My Forums]

Posted on
Sun Nov 08, 2020 8:10 pm
wideglidejrp offline
User avatar
Posts: 555
Joined: Jan 15, 2012
Location: Danbury, CT

Re: How to get name of Trigger in a Python Action script?

Action Group Sonos Test Action Group List
Script Error sonos_action_groups.py: 'ActionGroup' object does not support indexing
Script Error Exception Traceback (most recent call shown last):

sonos_action_groups.py, line 2, at top level
TypeError: 'ActionGroup' object does not support indexing

John R Patrick
Author of
Home Attitude

Posted on
Sun Nov 08, 2020 8:13 pm
wideglidejrp offline
User avatar
Posts: 555
Joined: Jan 15, 2012
Location: Danbury, CT

Re: How to get name of Trigger in a Python Action script?

Code: Select all
actions = [(a.name, a.id) for a in indigo.actionGroups.iter() if "Sonos Play" in a.name]
indigo.server.log(str(a[0]) + "," + str(a[1]))
song_ids = [a.id for a in indigo.actionGroups.iter() if "Sonos Play" in a]
indigo.server.log(song_ids)


Nothing in the script has a capital A

John R Patrick
Author of
Home Attitude

Posted on
Sun Nov 08, 2020 8:16 pm
DaveL17 offline
User avatar
Posts: 6751
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: How to get name of Trigger in a Python Action script?

I see it now, you left out the iteration of my original second case example:
Code: Select all
for a in actions:
    indigo.server.log(str(a[0]) + "," + str(a[1]))


actions in this case is a list of tuples. You need to iterate over the list to inspect each one.

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

[My Plugins] - [My Forums]

Posted on
Sun Nov 08, 2020 8:23 pm
wideglidejrp offline
User avatar
Posts: 555
Joined: Jan 15, 2012
Location: Danbury, CT

Re: How to get name of Trigger in a Python Action script?

Almost there......

Code: Select all
Action Group                    Sonos Test Action Group List
   Script                          Kitchen - Sonos Play Escape,1396610428
   Script                          Office - Sonos Play KBAQ,177155493
   Script                          Sonos Play - Dinner Time,1671794151
   Script                          Sonos Play Spotify - All Out 60s,514484958
   Script                          Sonos Play Spotify - Breakout Country,1682926896
   Script                          Sonos Play Spotify - Dinner with Friends,1682158368
   Script                          Sonos Play Spotify - Mellow Classical,132352282
   Script                          Sonos Play Spotify - Peaceful Piano,1194201585
   Script                          Sonos Play Spotify - Pop Soul Classics,578812952
   Script                          Sonos Play Spotify - Soft Pop Hits,805964757
   Script                          Sonos Play Spotify - The Beattles Radio,1218019482
   Script                          Sonos Play Spotify - Yacht rock 70s and 80s music,255752137
   Script                          Sonos Play Tunein - KBAQ,1767657221
   Script                          Sonos Play Tunein - KDFC,1699839823
   Script                          Sonos Play Tunein - WSHU,802721542
   Script                          Sonos Play XM - 50s on 5,996327141
   Script                          Sonos Play XM - 60s on 6,1780939210
   Script                          Sonos Play XM - 70s on 7,1331629382
   Script                          Sonos Play XM - 80s on 8,1941038111
   Script                          Sonos Play XM - 90s on 9,1999860605
   Script                          Sonos Play XM - Escape,888270062
   Script                          Sonos Play XM - Pop2K,751792234
   Script                          Sonos Play XM - Pop2K copy,1657739732
   Script                          Sonos Play XM - Pops,1883969970
   Script                          Sonos Play XM - Symphony Hall,1935270793
   Script                          Sonos Play XM - The Blend,561938481
   Script                          Sonos Play XM - The Bridge,1639471455
   Script                          Sonos Play XM - The Coffee House,232370722
   Script                          Sonos Play XM - The Loft,344802199
   Script Error                    sonos_action_groups.py: argument of type 'ActionGroup' is not iterable
   Script Error                    Exception Traceback (most recent call shown last):

     sonos_action_groups.py, line 4, at top level
TypeError: argument of type 'ActionGroup' is not iterable


John R Patrick
Author of
Home Attitude

Posted on
Sun Nov 08, 2020 8:25 pm
wideglidejrp offline
User avatar
Posts: 555
Joined: Jan 15, 2012
Location: Danbury, CT

Re: How to get name of Trigger in a Python Action script?

Here is current code.....

Code: Select all
actions = [(a.name, a.id) for a in indigo.actionGroups.iter() if "Sonos Play" in a.name]
for a in actions:
    indigo.server.log(str(a[0]) + "," + str(a[1]))
song_ids = [a.id for a in indigo.actionGroups.iter() if "Sonos Play" in a]
for a.id in actions:
    indigo.server.log(song_ids)

John R Patrick
Author of
Home Attitude

Posted on
Sun Nov 08, 2020 8:28 pm
DaveL17 offline
User avatar
Posts: 6751
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: How to get name of Trigger in a Python Action script?

song_ids is a list of values so you can just print that. In this case, you can't print a list without recasting it as a string, so:
Code: Select all
actions = [(a.name, a.id) for a in indigo.actionGroups.iter() if "Sonos Play" in a.name]
for a in actions:
    indigo.server.log(str(a[0]) + "," + str(a[1]))
song_ids = [a.id for a in indigo.actionGroups.iter() if "Sonos Play" in a]
indigo.server.log(str(song_ids))

Should do it.

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

[My Plugins] - [My Forums]

Posted on
Sun Nov 08, 2020 8:31 pm
wideglidejrp offline
User avatar
Posts: 555
Joined: Jan 15, 2012
Location: Danbury, CT

Re: How to get name of Trigger in a Python Action script?

Still getting an error.....

Script Error sonos_action_groups.py: argument of type 'ActionGroup' is not iterable
Script Error Exception Traceback (most recent call shown last):

sonos_action_groups.py, line 4, at top level
TypeError: argument of type 'ActionGroup' is not iterable

John R Patrick
Author of
Home Attitude

Posted on
Sun Nov 08, 2020 8:32 pm
wideglidejrp offline
User avatar
Posts: 555
Joined: Jan 15, 2012
Location: Danbury, CT

Re: How to get name of Trigger in a Python Action script?

Ok, I see the error. All working now. Thanks!

John R Patrick
Author of
Home Attitude

Posted on
Sun Nov 08, 2020 8:33 pm
DaveL17 offline
User avatar
Posts: 6751
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: How to get name of Trigger in a Python Action script?

Should have seen that one coming. That's on me.
Code: Select all
song_ids = [a.id for a in indigo.actionGroups.iter() if "Sonos Play" in a.name]

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

[My Plugins] - [My Forums]

Posted on
Mon Nov 09, 2020 11:05 am
jay (support) offline
Site Admin
User avatar
Posts: 18212
Joined: Mar 19, 2008
Location: Austin, Texas

Re: How to get name of Trigger in a Python Action script?

wideglidejrp wrote:
a few decades before Jay and Matt were born.!


Thanks for the compliment, though you may be underestimating my age... :wink:

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Nov 17, 2020 5:34 pm
mundmc offline
User avatar
Posts: 1060
Joined: Sep 14, 2012

Re: How to get name of Trigger in a Python Action script?

LIKE

Posted on
Thu Nov 10, 2022 5:19 pm
gbreeze offline
Posts: 15
Joined: Jan 27, 2007

Re: How to get name of Trigger in a Python Action script?

matt (support) wrote:
autolog wrote:
In a Trigger, is it possible to get the name of the invoking Trigger in a Python Action script :?:

Not currently, but that is on our feature request list. Right now the action is very disconnected (internally) from what is causing it to execute.


Is this still the case or has there been any action on this feature request?

Who is online

Users browsing this forum: No registered users and 3 guests