test of a condition: repeat or proceed

Posted on
Mon Nov 25, 2019 6:26 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

test of a condition: repeat or proceed

I have a button that I press which is designed to change my house status to occupied or vacant, with the following script:
Code: Select all
hseOcc = indigo.variables[612296111].getValue(bool)
import time
time.sleep(5)
if hseOcc:
   indigo.variable.updateValue(612296111,"false") # hse Vacant
   indigo.iodevice.setBinaryOutput(1375390279, 0, False)
   time.sleep(1)
   indigo.variable.updateValue(612296111,"false") # hse Vacant
   indigo.iodevice.setBinaryOutput(1375390279, 0, False)
   time.sleep(1)
   indigo.variable.updateValue(612296111,"false") # hse Vacant
   indigo.iodevice.setBinaryOutput(1375390279, 0, False)
else:
   indigo.variable.updateValue(612296111,"true") # hse Occupied
   indigo.iodevice.setBinaryOutput(1375390279, 0, True)
   time.sleep(1)
   indigo.variable.updateValue(612296111,"true") # hse Occupied
   indigo.iodevice.setBinaryOutput(1375390279, 0, True)
   time.sleep(1)
   indigo.variable.updateValue(612296111,"true") # hse Occupied
   indigo.iodevice.setBinaryOutput(1375390279, 0, True)
   time.sleep(1)

The problem is that the script doesn't always work. I am attempting to deal with this by repeating the commands after short delays. I think I can do better.
Would it make sense to create 2 loops - 1) to test for the desired variable value, and repeat, until the desired value is set, and then 2) do the same for the iodevice?
If so, is there a model I could use? - or more likely, a better way to achieve a reliable result?

Posted on
Mon Nov 25, 2019 9:53 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: test of a condition: repeat or proceed

would something like this work?
Code: Select all
hseOcc = indigo.variables[612296111].getValue(bool)
if hseOcc:
   while indigo.variable.value != false
      indigo.variable.updateValue(612296111,"false") # hse Vacant
   while indigo.iodevice.BinaryOutput(1375390279, 0, False) #need statement to obtain iodevice value - maybe use a variable?
      indigo.iodevice.setBinaryOutput(1375390279, 0, False)

Posted on
Tue Nov 26, 2019 6:19 am
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: test of a condition: repeat or proceed

You shouldn't need to repeat commands like you did in your first post. When you say "the script doesn't always work", what do you mean?

Are you getting an error?
Is the state of the binary output device not updating properly?
Is the button that you press battery powered or is it attached to the mains?

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

[My Plugins] - [My Forums]

Posted on
Tue Nov 26, 2019 1:38 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: test of a condition: repeat or proceed

A better designation of the issue would be system failure, not script failure.
The system: it starts with the press of a button that is an iodevice: it is green when the house is occupied, and red when vacant. the problem arises when a push of the button does not result in a quick change in color, with people pressing the button again - and again. What can result is two triggers (house open / house close) running simultaneously, multiple times, and the hseOccupied variable being out of sync with the color of the button. This requires my intervention, and others having no faith in the operation of the button. They have a point.
My goal is to have a simple button press resulting in the opening or closing of the house (with the relevant trigger). The house is located in the mountains, where it can be very cold, and the consequences of unreliable settings ranging from uncomfortable (cold water, cold house) to disastrous - frozen water pipes.
Using the python 'while' seems like a way to insure that any delays caused by slow insteon response could be overcome.

Posted on
Tue Nov 26, 2019 2:08 pm
DaveL17 offline
User avatar
Posts: 6756
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: test of a condition: repeat or proceed

What I would do is create an Indigo variable -- call it updating_house_status or something like that--that will be used to signal that Indigo is in the process of changing the status of the house. If the variable is False, process the button press. If the variable is True (the status is currently being updated) then ignore the button press. When all of your tasks have completed and you're sure that the house is in the state you want, set the variable to False again so it will be ready to process the next change in status.

The key here is that button presses will be ignored if the house updating status is True.

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

[My Plugins] - [My Forums]

Posted on
Wed Nov 27, 2019 1:03 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: test of a condition: repeat or proceed

I understand what you suggest, but wonder if the variable solution would be vulnerable to the same delay issue. - if the variable doesn't change very quickly, and an impatient operator pressed a second time, I'd have the same chaos.
Assuming my concern is valid, wouldn't a python script would be more reliable?

Posted on
Wed Nov 27, 2019 2:06 pm
peszko offline
Posts: 311
Joined: Mar 07, 2012

Re: test of a condition: repeat or proceed

I had slightly similar issue with my living room lights (among other things) that were controlled by insteon switches with scenes (and some sensors). What would happen, is when somebody pressed a button to activate a scene like mood light and then several seconds later decide to activate it to turn it off (or fully on), the previous action wasn't finished and nothing happened. So most people pressed it again withing couple seconds, adding again more delay. As most people will do, they then pressed several more times since nothing happened. this resulted in lights going on and off for the next minute or so, as insteon signals started to colide and retried. This also blocked most other commands, so you couldn't control other insteon devices in the mean time. Telling family and guests to wait 15 seconds between presses was not an option. (I tried. Wife response: "If its so unreliable then we need to get rid of it completely")

For me the solution was to get rid of all keypadlinks (the function would turn on/off several buttons on several keypadlinks (turning on 6 keypadlink buttons on 3 keypad links).) I also got rid of scene clean up. This helped a lot but still not 100% Eventually, I replaced many modules with z-wave equivalents and the whole problem went away. The only thing I miss is that when scene worked properly, all lights responded at the same time. With z-wave there is a slight delay between them, but it works every time.

Moral of the story: it might be worth looking to see if a z-wave equivalent devices would work for you.

Posted on
Sun Dec 01, 2019 2:19 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: test of a condition: repeat or proceed

Hah! Thad does sound all too familiar. My 'solution' to deal with an impatient wife and family was to rebrand the system as "Italian" - for whom they all have a great fondness and tolerance for things not working just right. Didn't fork for me though, and am now trying to make my systems more robust.
I have not tried Z-Wave. I am replacing my Insteon keypads with Lutron RadioRa2 keypads. I should have compared theZ-wave with Lutron first, but didn't. I'm using Indigo to connect the new keypads to both existing Insteon switches and outlets, and to new Lutron dimmers . I'm not done yet, but so far, the result has been very good, I believe you are responsible for that plug-in, and thank you for it.
I continue to have the question on my last posting -
I understand what you suggest, but wonder if the variable solution would be vulnerable to the same delay issue. - if the variable doesn't change very quickly, and an impatient operator pressed a second time, I'd have the same chaos.
Assuming my concern is valid, wouldn't a python script would be more reliable?

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 11 guests