Have script wait for Indigo to finish changing device states

Posted on
Thu Nov 10, 2022 1:42 pm
Jason G. offline
User avatar
Posts: 54
Joined: Mar 21, 2018

Have script wait for Indigo to finish changing device states

Hi-

I have a python script that runs and reconciles wall switches with LampLinc device states. E.g., if the lamp is on 100% but the wall switch is off, the script updates the wall switch to be on @ 100%. That can happen if I trigger a light change in Indigo, or via HomeKit/homebridge.

The main point of scripting it is that I update more than one switch - I have several KPLs that reflect the status of the lamps in my living room. So changing one lamp might update 4 or 5 KPLs.

The script works great, but I noticed that the script finishes very quickly, while Indigo is continuing to send the devices their updates after my script completes. My script thinks it is done, but Indigo is still making things happen, sometimes for 4-5 seconds afterwards.

Is there a way to have the python script wait for all the device updates to be completed?

Specifically, I want to make sure all the device updates are sent before allowing the script to start running again.

Posted on
Thu Nov 10, 2022 2:22 pm
FlyingDiver online
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Have script wait for Indigo to finish changing device st

Short answer, No. Indigo does all the device updates asynchronously, so there's no way to know when it's actually finished. And you don't want your script stopped while it's waiting, because it'll block any other scripts (and some other Indigo functions).

How often are you trying to run this script?

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

Posted on
Thu Nov 10, 2022 3:01 pm
Jason G. offline
User avatar
Posts: 54
Joined: Mar 21, 2018

Re: Have script wait for Indigo to finish changing device st

Right now I have the script running every 30 seconds in a Schedule.

And I used to have the same script launched by triggers - so if the lamp brightness changed it would kick off the script. (Multiply by several lamps, ceiling fans, KPLs, etc.), but I turned that off recently to avoid the script running more than once at a time.

I have the script checking a variable "reconcileRunning" - if true, the script exits without doing anything. If false, the script sets the variable to true when it starts, does it's thang, then sets the variable back to false when it stops. But the script finishes long before device updates are finished.

The problem is if Indigo is still sending out Insteon messages to devices, then I would prefer to wait or skip that run of the script.

I get it that Indigo is doing all the device updates asynchronously - that's a good design. Is there some way to check if Indigo has device updates queued up? If that is possible, that might be a better way to have my script bail because stuff is already in flight.

Posted on
Thu Nov 10, 2022 3:03 pm
FlyingDiver online
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Have script wait for Indigo to finish changing device st

Not that I know of. And if you still have commands that have not yet been completed 30 seconds after running the script, that seems like a really bad thing. You're flooding your Insteon network.

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

Posted on
Thu Nov 10, 2022 3:22 pm
Jason G. offline
User avatar
Posts: 54
Joined: Mar 21, 2018

Re: Have script wait for Indigo to finish changing device st

Well, I do have a lot of insteon devices. For example, I have several ceiling fans and KPLs that control them. If I turn on all the ceiling fans from Indigo (which I do from time to time), my script sends out updates to turn on/off the buttons on the KPLs to reflect the running state - the processing time on that can add up.

Most of the time the script runs and nothing needs to be changed, so there are no messages. When there are changes, everything is usually done within 5 seconds or less.

But when I had my script running from triggers, it was possible for the script to fire up multiple times at once, repeatedly trying to do the same updates to the same devices because the queued up events hadn't run yet.

I guess I'm ok leaving the triggers off and just running on a schedule. That's perfectly reasonable.

Thanks for your help!

Posted on
Thu Nov 10, 2022 3:28 pm
FlyingDiver online
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Have script wait for Indigo to finish changing device st

Or add a condition to the triggers that prevents it from running if it's currently running (or has recently run). Set the variable as the first action in the trigger, and put a delayed action to clear the variable after 10 or 15 seconds. Then you could use triggers without overlap.

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

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 7 guests