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

Posted on
Mon Sep 23, 2013 9:20 am
autolog offline
Posts: 3991
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

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

In a Trigger, is it possible to get the name of the invoking Trigger in a Python Action script :?:

Posted on
Mon Sep 23, 2013 9:28 am
matt (support) offline
Site Admin
User avatar
Posts: 21429
Joined: Jan 27, 2003
Location: Texas

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

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.

Image

Posted on
Fri Oct 04, 2013 9:11 am
autolog offline
Posts: 3991
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

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.

It would also be useful to be able to get the name of the invoking Schedule / Action Group in a Python Action script (I guess this might already be on the feature list but thought I would mention it) :)

Sort of loosely related, is it possible to pass a parameter to a python script file :?:

I can't see anyway to do it other than setting a variable before the script is called. In some cases I just want to pass a specific value to the script. So if I have an Action Group that is say "Open dining room curtains" it is going to process a known device which I could just pass straight into a common curtain control script via a parameter - it doesn't really need a variable to be set.

Even more loosely related to the above, because the list of actions is processed in parallel, doing this (setting a variable prior to calling a script file) is slightly problematical - you have to put in a delay for the call to the script) It would be great it was possible to request the actions (or selected actions) to run serially.

Of course, because I am still new to all this, I might have missed something :?:

Posted on
Fri Oct 04, 2013 3:32 pm
jay (support) offline
Site Admin
User avatar
Posts: 18261
Joined: Mar 19, 2008
Location: Austin, Texas

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

If you define your curtain method in a shared Python file then you can just call that method from an embedded script and pass it any parameters.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Nov 07, 2020 11:54 am
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?

I have a loosely related question. I would like to create a Python list containing all of my action groups and corresponding group IDs. I could then filter the list to extract action groups which contain a Sonos play command and use that information in other scripts. If I can get help on creating that initial list, I think I can take it from there.

John R Patrick
Author of
Home Attitude

Posted on
Sat Nov 07, 2020 7:12 pm
DaveL17 offline
User avatar
Posts: 6787
Joined: Aug 20, 2013
Location: Chicago, IL, USA

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

wideglidejrp wrote:
I have a loosely related question. I would like to create a Python list containing all of my action groups and corresponding group IDs. I could then filter the list to extract action groups which contain a Sonos play command and use that information in other scripts. If I can get help on creating that initial list, I think I can take it from there.

This should do it.
Code: Select all
actions = [(a.name, a.id) for a in indigo.actionGroups.iter()]
indigo.server.log(u"{0}".format(actions))

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 5:07 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?

Looks like I need a little more help than I thought. Here is what I am trying to do:

1. Get the list of action groups and IDs for those action groups where the action contains "Sonos Play"

2. print a list of actions and IDs like this (str, not unicode).....
Sonos Play - Song A, 12345678
Sonos Play - Song B, 24689752
Sonos Play - Song C, 2658794521

3. create a list containing all the IDs like this....
song_ids = [12345678, 24689752, 2658794521]

Then I can take it from there.

John R Patrick
Author of
Home Attitude

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

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

Obviously untested.

Number 1:
Code: Select all
actions = [(a.name, a.id) for a in indigo.actionGroups.iter() if "Sonos Play" in a]

Number 2:
Code: Select all
for a in actions:
    indigo.server.log(str(a[0]) + "," + str(a[1]))

Number 3:
Code: Select all
song_ids = [a.id for a in indigo.actionGroups.iter() if "Sonos Play" in a]

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 6:12 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?

Dave, you make this look so easy! I have taken several Python tutorials, and I learned two things....
1. The language is incredibly powerful. I learned a lot at the time I was taking the tutorial.
2. If you only use it occasionally, it is difficult because it is not always intuitive.

When I was in grad school in the 1970s, I wrote code every day, in Fortran. In all modesty, I was a wiz in Fortran. I could do anything. Fortran was developed by John Backus at IBM in 1952, a few decades before Jay and Matt were born.! When it came to simulation and mathematics, Fortran was king. Now, none of my kids or grandkids have ever heard of it.

All that aside, thank you very much for the assistance. I can definitely take my project from here.

John R Patrick
Author of
Home Attitude

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

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

When I first came over to Indigo, I didn't even know what Python was. I had a lot of help getting over the initial learning curve and I'm still learning things all the time. The ability to use Python in my automation setup made it feel like almost anything could be added to Indigo.

I'm glad I could be of some small help John.

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 7:33 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?

Getting...
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 12, at top level
TypeError: argument of type 'ActionGroup' is not iterable

John R Patrick
Author of
Home Attitude

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

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

No problem -- can you post your whole script (or at least up to line 12)? I'll need to see which line is causing the problem.

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 7:47 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]
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)

John R Patrick
Author of
Home Attitude

Posted on
Sun Nov 08, 2020 7:49 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: argument of type 'ActionGroup' is not iterable
Script Error Exception Traceback (most recent call shown last):

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

John R Patrick
Author of
Home Attitude

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

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

Change line 1 to this:
Code: Select all
actions = [(a.name, 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]

Who is online

Users browsing this forum: No registered users and 5 guests