This doesn't work....

Posted on
Mon Nov 21, 2022 3:16 pm
jltnol offline
Posts: 994
Joined: Oct 15, 2013

This doesn't work....

...... like I think it should.

So I have a very basic python script that is activated by a KPL button when I am leaving the house. If the alarm isn't ready to arm, Indigo simply turns the KPL LED off.

if the alarm is ready to arm, it will then go ahead and arm the alarm, open the garage door, wait 3 seconds, and then execute a "Leave Home" group, depending on whether it is day or night. In the first script, the "Leave Home" group isn't added, but when this script is activated, the alarm arms, and the garage door opens practicaly immediately, just as expected.
Code: Select all
alarmPanel = 15871202
alarmPanelState = indigo.devices[alarmPanel].states['LEDReady']
day = indigo.variables[507666416]
import time



if alarmPanelState == "off":  #alarm not ready to arm
   indigo.dimmer.setLedState(1075498820, index = 4, value = False) #turns off KPL if alarm isn't ready


elif alarmPanelState == "on" and day.value == "true": 
   indigo.actionGroup.execute(1582883331) #Arms Alarm in Away Mode
   indigo.actionGroup.execute(36130583), #opens Garage Door
   
   

elif alarmPanelState == "on" and day.value == "false":
   indigo.actionGroup.execute(1582883331), #Arms Alarm in Away Mode
   indigo.actionGroup.execute(36130583), #opens garage door


But in this sample, when I add in the Leave Home group with a delay, arming the alarm and opening the garage door takes longer.

Code: Select all
alarmPanel = 15871202
alarmPanelState = indigo.devices[alarmPanel].states['LEDReady']
day = indigo.variables[507666416]
import time



if alarmPanelState == "off":  #alarm not ready to arm
   indigo.dimmer.setLedState(1075498820, index = 4, value = False) #turns off KPL if alarm isn't ready


elif alarmPanelState == "on" and day.value == "true": 
   indigo.actionGroup.execute(1582883331) #Arms Alarm in Away Mode
   indigo.actionGroup.execute(36130583), #opens Garage Door
   time.sleep(3)
   indigo.actionGroup.execute(133011708) #leave day group
   

elif alarmPanelState == "on" and day.value == "false":
   indigo.actionGroup.execute(1582883331), #Arms Alarm in Away Mode
   indigo.actionGroup.execute(36130583), #opens garage door
   time.sleep(3)
   indigo.actionGroup.execute(1346050145), #leave night group
   

I added in the 3 sec delay for the Leave Home Groups, thinking Z-wave traffic was delaying the garage door open command, but I'm assuming I don't understand how my 3 second time.sleep is actually working, or there is something else going on. What happens immediately in the 1st script always takes longer for some reason in the 2nd, and I can't figure out why. FWIW, the alarm works thru IP, and the garage door is Z-Wave. Both work as expected in the first script, but are delayed in the 2nd.

And the first few entries in the Event Log are exactly the same, regardless of what script is used and Indigo is doing absolutely nothing else at the time:
Code: Select all
Received INSTEON                "Garage Light" on (button 5)
   Trigger                         XT-125 Arm Alarm-Garage Door (AWAY MODE) copy
   Action Group                    Alarm-Away
   Action Group                    Garage Door Open
   DSC Alarm                       Arming Alarm in Away Mode. (Partition 1 'Bradford Drive'

Posted on
Mon Nov 21, 2022 3:58 pm
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: This doesn't work....

I'm guessing you're running this as an embedded script rather than as a linked script. Try running it as a linked script instead and see what happens.

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

[My Plugins] - [My Forums]

Posted on
Mon Nov 21, 2022 10:37 pm
jltnol offline
Posts: 994
Joined: Oct 15, 2013

Re: This doesn't work....

Hey Dave

You were exactly right. The script is/was embedded in Indigo, and although it too just a bit of trial and error for me to get the script setup correctly, but once that was done, it run perfectly, and on time.

Any ideas or suggestions as to why being embedded was causing issues?

Posted on
Tue Nov 22, 2022 5:59 am
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: This doesn't work....

When an embedded script pauses, it's pausing everything. It's the same reason why embedded scripts have a 10 second limitation on execution (go beyond 10 seconds and Indigo will force-kill the script). Linked scripts run in their own thread and can sleep safely. Your first two lines get sent to Indigo before the sleep--your script sleeps while Indigo moves on.

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

[My Plugins] - [My Forums]

Posted on
Tue Nov 22, 2022 9:30 am
jltnol offline
Posts: 994
Joined: Oct 15, 2013

Re: This doesn't work....

Got it

Thanks..

Posted on
Tue Nov 22, 2022 10:16 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: This doesn't work....

In this case used an external/linked script is probably best, but I wanted to throw out there that it probably would work (not 100% sure) embedded if you changed these lines from:

Code: Select all
time.sleep(3)

to:

Code: Select all
indigo.activePlugin.sleep(3)


The latter is an internal implementation of time.sleep() that is more friendly to Indigo processing.

Update: after thinking about this a bit more, I don't believe using Indigo's implementation will help in this case. It probably is possible to get it working embedded by using python timers/threads, but really the best answer in this case is to not use embedded. Regardless, using indigo.activePlugin.sleep() is generally preferred because it will allow Indigo to more quickly kill the script if the Indigo Server is shutting down.

Image

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 10 guests