State variable not updating

Posted on
Fri Aug 12, 2016 5:14 pm
nlagaros offline
Posts: 1646
Joined: Dec 20, 2010

State variable not updating

What am I doing wrong here? I have the script below that is called in an action. The z1v variable does not update even though the volume is adjusting appropriately. I see it in the GUI state list. For some reason the variable is only populated correctly the first time. Once in the loop, it just keeps the initial value.

Code: Select all
z1v = int(dev.states['zone1volume'])
while z1v != -30:
   indigo.server.log("z1v: %s" % z1v)
   if z1v < -30:
      PioneerPlugin.executeAction("zone1volumeUp", deviceId=PioneerFR)
   else:
      PioneerPlugin.executeAction("zone1volumeDown", deviceId=PioneerFR)
   z1v = int(dev.states['zone1volume'])

Posted on
Fri Aug 12, 2016 6:00 pm
FlyingDiver offline
User avatar
Posts: 7190
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: State variable not updating

Is z1v an Indigo variable? Not a local one for the script? If so, you need to push the updated value back to the server:

Code: Select all
indigo.variable.updateValue("z1v", int(dev.states['zone1volume']))


I think that's right. I use the Variable ID in my scripts, not the names.

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

Posted on
Fri Aug 12, 2016 6:28 pm
nlagaros offline
Posts: 1646
Joined: Dec 20, 2010

Re: State variable not updating

z1v is just a local variable that I created for the loop.

Posted on
Fri Aug 12, 2016 6:51 pm
FlyingDiver offline
User avatar
Posts: 7190
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: State variable not updating

nlagaros wrote:
z1v is just a local variable that I created for the loop.


I think dev is a snapshot from when the script is started. If you want updated values there's an api call to get the current values.


Sent from my iPad using Tapatalk

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

Posted on
Sat Aug 13, 2016 5:09 am
nlagaros offline
Posts: 1646
Joined: Dec 20, 2010

Re: State variable not updating

Thanks for the tip. I can re-address the device to get the updated value.

Posted on
Sat Aug 13, 2016 6:23 am
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: State variable not updating

Try changing that last line to:
Code: Select all
z1v = int(indigo.devices[12345].states['zone1volume'])

And see if that helps. There are actual official ways to refresh but that is just as effective since you are pulling the item right from the Indigo collection again.

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Sat Aug 13, 2016 11:21 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: State variable not updating

The dev instance is a cached copy. Use dev.refreshFromServer() to have the copy refreshed.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Aug 13, 2016 4:21 pm
nlagaros offline
Posts: 1646
Joined: Dec 20, 2010

Re: State variable not updating

Thanks!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests