[Solved] Help with variables on control page

Posted on
Mon Feb 03, 2014 1:25 pm
pgershon offline
Posts: 509
Joined: Jul 10, 2004

[Solved] Help with variables on control page

I have a plugin with device states "SRC1", "SRC2", "SRC3" etc. My device itself uses these values to address it so it is helpful not to change the values. I would like to have a control page that displays text based on the value, so for example, to display "Squeezebox" if state is SRC1 and "CD" if SRC2. I can display the state but I do not know how to insert logic to control different variable text. On idea I have is to set up a variable that has the identity of the state. I know how to set the variable value with the state, but how can I use python to update (say if state =="SRC1" then variable="Squeezebox). Probably easy but I am striking out trying.

Also, is there an easy way to call a function within my plugin from the control page without having an action for it. For example, my plugin has this line: self.commQueue.append(dev.pluginProps["zoneselect"] + "FWD")
How could I run this from the control page?
Last edited by pgershon on Tue Feb 04, 2014 6:22 am, edited 1 time in total.

Posted on
Mon Feb 03, 2014 2:12 pm
jay (support) offline
Site Admin
User avatar
Posts: 18246
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Help with variables on control page

pgershon wrote:
I have a plugin with device states "SRC1", "SRC2", "SRC3" etc. My device itself uses these values to address it so it is helpful not to change the values. I would like to have a control page that displays text based on the value, so for example, to display "Squeezebox" if state is SRC1 and "CD" if SRC2. I can display the state but I do not know how to insert logic to control different variable text.


So, you have 3 states for the device or just one state whose value is in that set of strings in the first sentence? If it's the latter, can just just add another state to the device that shows the human-readable version - so whenever the state changes to "SRC1" then the human-readable version would change to "Squeezebox", etc. No variables needed then, you just show the human-readable state on your control page.

pgershon wrote:
On idea I have is to set up a variable that has the identity of the state. I know how to set the variable value with the state, but how can I use python to update (say if state =="SRC1" then variable="Squeezebox). Probably easy but I am striking out trying.


Assuming that scenario two above is what you've got (one state, multiple fixed values):

Code: Select all
if dev.states["stateIdHere"] == "SRC1":
    indigo.variable.updateValue(VARIDHERE, value="Squeezebox")
elif dev.states["stateIdHere"] == "SRC2":
    indigo.variable.updateValue(VARIDHERE, value="CD")
# etc for each possible value


pgershon wrote:
Also, is there an easy way to call a function within my plugin from the control page without having an action for it. For example, my plugin has this line: self.commQueue.append(dev.pluginProps["zoneselect"] + "FWD")
How could I run this from the control page?


Nope, you'll need to expose an Action to do it. Exposing an action is quite simple though.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Feb 03, 2014 2:44 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Help with variables on control page

So, you have 3 states for the device or just one state whose value is in that set of strings in the first sentence? If it's the latter, can just just add another state to the device that shows the human-readable version - so whenever the state changes to "SRC1" then the human-readable version would change to "Squeezebox", etc. No variables needed then, you just show the human-readable state on your control page.

I have used plugins that do both the variable and the state method and, personally, I prefer the additional state variable as Jay suggests here... this eliminates a lot of potential issues with the variable approach (such as if the variable is accidentally renamed, deleted, etc.) as well as cuts down on the clutter of variables and, potentially, a conflict of having multiple devices defined; in that case you need to pre-or-postfix your variable with a device identifier.

Posted on
Mon Feb 03, 2014 3:25 pm
pgershon offline
Posts: 509
Joined: Jul 10, 2004

Re: Help with variables on control page

Thanks. Another no so smart question: How do I pass along the value of an Indigo variable to an embedded script on a control page. I can update the value but how can I use it?

I am trying to make a device ID globally available. It is there within my plugin script but I cannot find it on the control page script. I saved in in an Indigo variable, but I still cannot access it.

Posted on
Mon Feb 03, 2014 5:47 pm
jay (support) offline
Site Admin
User avatar
Posts: 18246
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Help with variables on control page

If your plugin is sticking it into an Indigo variable, then you get it the exact same way from a script that's executed from a control page:

Code: Select all
myVar = indigo.variables[VARIDHERE]
# now just use myVar.value however you want, for instance
if myVar.value = "Something":
    # do whatever


Did you build the plugin or did someone else?

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Feb 03, 2014 6:57 pm
pgershon offline
Posts: 509
Joined: Jul 10, 2004

Re: Help with variables on control page

Thanks,

I did a substantial modification to an existing plugin. I know enough to get stuff to work, but not enough to really know how to use python

Posted on
Mon Feb 03, 2014 8:22 pm
jay (support) offline
Site Admin
User avatar
Posts: 18246
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Help with variables on control page

Just curious. If this topic is closed, would you mind pretending [SOLVED] to the original post's subject line? Thanks...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests