Embedded vs External python file

Posted on
Mon Aug 29, 2016 5:58 pm
dz1rfj offline
Posts: 136
Joined: Mar 13, 2016

Embedded vs External python file

Hi Pyton experts...

So it took me a good part of last night looking at examples on the internet, but managed to put this together. From reading information on delays, I decided to use an external file to be proceed.

The code below works FINE as an embedded python scrips, but will not run as an external file.

As a complete novice to Python, I am surprised just how much it cares that each line be indented just so...

Here is the code, any thing jump out as to why I cannot run as an external file in indigo action group?


Code: Select all
#Gate Logic Script

import time

if indigo.variables[1335916415].value == "false" : # if it is nighttime do this
   
    indigo.actionGroup.execute(387291483) # "ag_Security"
    indigo.actionGroup.execute(513003517) # "Backyard On"
    time.sleep(2)
    indigo.server.speak("Hi there, since it is after hours, we would rather you rang the doorbell.")
    time.sleep(9)
    indigo.actionGroup.execute(1142413630) # "Audio_RestoreAudioState"

else:
   
   
   
    indigo.actionGroup.execute(165084610) # "Audio_SaveAudioState"
    time.sleep(2)

    indigo.actionGroup.execute(387291483) # "ag_Security"
    indigo.server.speak("HI, and Welcome to Cassa Divina!  I have announced your arrival.  Enjoy your visit!" )

    time.sleep(9)
    indigo.actionGroups[1142413630] # "Audio_RestoreAudioState"




Thanks!

Thanks
-Brian

Posted on
Tue Aug 30, 2016 9:13 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Embedded vs External python file

I surrounded it in code tags so we can see it in it's real state. Python interprets blocks based on indentation rather than opening/closing tags like other languages.

The very last line of the script is incorrect - it's missing ".execute". Either way though it should work identically in both environments (though you're pushing the 10 second limit of embedded scripts). You'll want to start liberally adding "indigo.server.log()" calls in the script to see where it stops working.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Aug 30, 2016 9:14 am
dz1rfj offline
Posts: 136
Joined: Mar 13, 2016

Re: Embedded vs External python file

Thanks, will take a look tonight!


Sent from my iPhone using Tapatalk

Thanks
-Brian

Posted on
Wed Aug 31, 2016 9:17 am
dz1rfj offline
Posts: 136
Joined: Mar 13, 2016

Re: Embedded vs External python file

Jay - I added .Execute, and no difference. Can you show me what you mean when you said

"I surrounded it in code tags so we can see it in it's real state." I did not see the change in your reply, and not sure what code tags are.

Here is what I tried:

#Gate Logic Script

import time

if indigo.variables[1335916415].value == "false" : # if it is nighttime do this

indigo.actionGroup.execute(387291483) # "ag_Security"
indigo.actionGroup.execute(513003517) # "Backyard On"
indigo.server.speak("Hi there, since it is after hours, we would rather you rang the doorbell.")
time.sleep(9)
indigo.actionGroup.execute(1142413630) # "Audio_RestoreAudioState"

else:



indigo.actionGroup.execute(165084610) # "Audio_SaveAudioState"
time.sleep(2)

indigo.actionGroup.execute(387291483) # "ag_Security"
indigo.server.speak("HI, and Welcome to Cassa Divina! I have announced your arrival. Enjoy your visit!" )

time.sleep(9)
indigo.actionGroups[1142413630] # "Audio_RestoreAudioState"
.execute

Thanks
-Brian

Posted on
Wed Aug 31, 2016 11:59 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Embedded vs External python file

Select the code in your post and click the "Code" button in the Selection style section above the post editing window.

In your latest code, you just stuck ".execute" at the very end of the script. That won't work. See where it is in your previous action group lines?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Aug 31, 2016 12:38 pm
dz1rfj offline
Posts: 136
Joined: Mar 13, 2016

Re: Embedded vs External python file

I think I am with you, so when posting code, just place it between the "
Code: Select all
" and the "
"

Also changed the .execute line, not sure how I missed that, but it was late that night, and since it worked in the embedded editor, I figured I was way off.,


Question: is this:

indigo.actionGroup.execute(1142413630) # "Audio_RestoreAudioState"
the same as:
indigo.actionGroup.execute[1142413630] # "Audio_RestoreAudioState" ?

Script runs now, as you suspected it would :wink:

Thanks!

Code: Select all

import time

if indigo.variables[1335916415].value == "true" : # if it is nighttime do this
   
    indigo.actionGroup.execute(387291483) # "ag_Security"
    indigo.actionGroup.execute(513003517) # "Backyard On"
    indigo.server.speak("Hi there, since it is after hours, we would rather you rang the doorbell.")
    time.sleep(9)
    indigo.actionGroup.execute(1142413630) # "Audio_RestoreAudioState"

else:
   
   
   
    indigo.actionGroup.execute(165084610) # "Audio_SaveAudioState"
    time.sleep(2)

    indigo.actionGroup.execute(387291483) # "ag_Security"
    indigo.server.speak("HI, and Welcome to Cassa Divina!  I have announced your arrival.  Enjoy your visit!" )

    time.sleep(9)
    indigo.actionGroup.execute(1142413630) # "Audio_RestoreAudioState"


Thanks
-Brian

Posted on
Wed Aug 31, 2016 2:00 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Embedded vs External python file

execute is a method and in Python method/function calls are followed by parenthesis (with any parameters in them). Brackets in Python indicate indices into arrays or dictionaries (or slices).

I highly recommend working through one of the many Python tutorials out on the net to get a grasp of the basics - it'll help you more easily get past issues like this.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests