[ANSWERED] Odd behavior?

Posted on
Thu Apr 17, 2014 10:36 am
akimball offline
Posts: 561
Joined: Aug 07, 2013
Location: Sandy, Utah

[ANSWERED] Odd behavior?

Hi, in my family room I have an 8-button KPL, an OutletLinc plug linked to it on button 7, and it works great. Press button 7 and the plug goes on and the led for button 7 lights. Press it again, plug turns off and led for button 7 reverts to its off state. The problem I solved was that using indigo touch, although I could toggle the plug, I desired the KPL button to track the plugs onState.

So on my indigo graphical layout for my family room, I created a button to toggle the OutletLinc for the first step, then added a 2nd step with the following Python script.

if indigo.devices("FamRmPlug").onState:
indigo.devices.setLedState("FamRmKPL", 6, True)
else:
indigo.devices.setLedState("FamRmKPL", 6, False)

....which does just the exact opposite as what I expected.??

I reversed the statements and it all works right. ...

if indigo.devices("FamRmPlug").onState:
indigo.devices.setLedState("FamRmKPL", 6, False)
else:
indigo.devices.setLedState("FamRmKPL", 6, True)

So what is going on here? I set the outlet state prior to executing this python code.

TIA, Al.

-Al

Posted on
Thu Apr 17, 2014 11:29 am
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: Odd behavior?

use [] not ()
indigo.devices[" devname"].onState gets the state (True or False) of FamRmPlug
indigo.devices(" devname").onState results in an error in the script

this should then work :

if indigo.devices["FamRmPlug"].onState:
indigo.devices.setLedState("FamRmKPL", 6, False)
else:
indigo.devices.setLedState("FamRmKPL", 6, True)


Karl

Posted on
Thu Apr 17, 2014 12:47 pm
akimball offline
Posts: 561
Joined: Aug 07, 2013
Location: Sandy, Utah

Re: Odd behavior?

Thanks Karl, I was doing this from memory so I'm not sure if I used brackets or not till I get home this evening. What is the difference in Python? I'm brand new to python.
Appreciate your response. :)

-Al

Posted on
Thu Apr 17, 2014 12:52 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: Odd behavior?

with my limited py knowledge:

[] looks up or sets an element in a list or dict i.e. variable

() invokes a function / method / class

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 8 guests

cron