Conditional script - how to write more succintly

Posted on
Thu Nov 21, 2019 8:01 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Conditional script - how to write more succintly

All 4 devices off = True:
The first line looks nicer, but doesn't work (order of execution issue?). The second line works, but is ugly. I suspect there is a more compact way to write an expression to test the onState of 4 devices (AND condition)
Code: Select all
# if not (led1.onState and led2.onState and led3.onState and led4.onState):
if  (not led1.onState and not led2.onState and not led3.onState and not led4.onState):
   indigo.device.turnOff(1580115691) # desk lamp

Posted on
Thu Nov 21, 2019 9:18 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Conditional script - how to write more succintly

The logical equivalent of the second line needs ORs, not ANDs, to be equivalent. You want this:

Code: Select all
if not (led1.onState or led2.onState or led3.onState or led4.onState):

Image

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 16 guests