conditional loop

Posted on
Sun Apr 03, 2022 7:26 pm
domlazar offline
Posts: 24
Joined: Jan 18, 2012

conditional loop

I was using AppleScript and migrated to Python, I’m not very good for now and need some help

I need to create a conditional loop, turning ON/OFF output device until to reach specific condition, (input value). I was considering python script to do so. My problem is the loop starts on continuous process and never stops. The system does note recognize the condition to stop.

Thank with your help, here is where I am with Python:
Code: Select all
venmarstatus=indigo.variable.updateValue(95594510, value='activation')

while venmarstatus<>"min échange":
    indigo.iodevice.setBinaryOutput(480710969, 0,True)
    indigo.iodevice.setBinaryOutput(480710969, 0,False)

    if indigo.devices[637045073].binaryInputs[0]==1:
        venmarstatus=indigo.variable.updateValue(95594510, value='min échange')
        break

Mac OS Montery 12.2.1 macmini
Indigo Pro 2021.2
Powerlinc 2413U

Posted on
Mon Apr 04, 2022 5:08 pm
anyone offline
User avatar
Posts: 125
Joined: Apr 03, 2011
Location: Norfolk, VA

Re: conditional loop

In your original code:

venmarstatus=indigo.variable.updateValue(95594510, value='activation')

vernmarstatus is set to None because unfortunately the function you used just sets the value.

vernmarstatus = indigo.variables[95594510].value

Would set vernmarstatus to the value of the indigo variable but you really don't need to use that because you know the value, you just set it.

FYI: Both <> and != are the same but use != because it works with both Python2 & 3

This might work...or get you closer to what you are trying to do.

Code: Select all
# update value of variable to 'activation'
indigo.variable.updateValue(95594510, value='activation')

# loop FOREVER or until the break is called
while True:

   # Turn the Binary Output ON
   indigo.iodevice.setBinaryOutput(480710969, 0,True)

   # Turn the Binary Output OFF
   indigo.iodevice.setBinaryOutput(480710969, 0,False)

   # if some devices Binary input is equal to 1
   if indigo.devices[637045073].binaryInputs[0]==1:

      # update value of variable to min échange
      indigo.variable.updateValue(95594510, value='min échange')

      # exit loop
      break

Posted on
Mon Apr 11, 2022 9:18 pm
domlazar offline
Posts: 24
Joined: Jan 18, 2012

Re: conditional loop

With the script below I have a constant loop, the server does not recognize the "binaryInputs[0]==1". Any idea how to stop it?




while True:
indigo.iodevice.setBinaryOutput(1812773431, 0,True)
indigo.iodevice.setBinaryOutput(1812773431, 0,False)
indigo.device.statusRequest(1812773431)
from time import sleep

if indigo.devices[1812773431].binaryInputs[0]==1:
break

Mac OS Montery 12.2.1 macmini
Indigo Pro 2021.2
Powerlinc 2413U

Posted on
Tue Apr 12, 2022 5:47 am
FlyingDiver offline
User avatar
Posts: 7221
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: conditional loop

domlazar wrote:
With the script below I have a constant loop, the server does not recognize the "binaryInputs[0]==1". Any idea how to stop it?




while True:
indigo.iodevice.setBinaryOutput(1812773431, 0,True)
indigo.iodevice.setBinaryOutput(1812773431, 0,False)
indigo.device.statusRequest(1812773431)
from time import sleep

if indigo.devices[1812773431].binaryInputs[0]==1:
break


Please use CODE tags when posting code. ;)

I think the problem is you're not actually doing a sleep(), so the input never has a chance to change.

This might work.

Code: Select all
from time import sleep
while True:
    indigo.iodevice.setBinaryOutput(1812773431, 0,True)
    indigo.iodevice.setBinaryOutput(1812773431, 0,False)
    indigo.device.statusRequest(1812773431)
    sleep(1)
    if indigo.devices[1812773431].binaryInputs[0] == 1:
        break

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

Posted on
Tue Apr 12, 2022 8:25 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: conditional loop

Scripts should use:

Code: Select all
self.sleep(1)

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests