View Full Version : How do I have one set of control (on/off) buttons for multiple devices?
Sendero
11-07-2006, 04:44 PM
I want to create a small UI for my PPC that will allow me to control the lights from it. I'd like to have a number of buttons along the top for the diff rooms. Below those I'd like to have controls for On, Off, and the level of lighting. When I tap on the "Living Room" button I can click the On button to turn on the Living room lights. Then I tap on "Kitchen" and click the same On buttong to turn on the kitchen lights. Is this possible? How do I do this?
Pretty easy in 2.0 using a global variable and an if-then. Set a global variable i.e., "RoomToControl"=LivingRoom when you tap the "living room" button.
Then, in the "On" command button, have the following (it's psuedo-code. The actual code looks scary, but it's mostly done through point&click so I won't post it)
IF GVar:RoomToControl = LivingRoom
THEN
WhateverYouDoToTurnOnLivRmLights
ELSE
IF GVar:RoomToControl = Kitchen
THEN
WhateverYouDoToTurnOnKitchenLights
ENDIF
ENDIF
Sendero
11-07-2006, 04:58 PM
Pretty easy in 2.0 using a global variable and an if-then. Set a global variable i.e., "RoomToControl"=LivingRoom when you tap the "living room" button.
Then, in the "On" command button, have the following (it's psuedo-code. The actual code looks scary, but it's mostly done through point&click so I won't post it)
IF GVar:RoomToControl = LivingRoom
THEN
WhateverYouDoToTurnOnLivRmLights
ELSE
IF GVar:RoomToControl = Kitchen
THEN
WhateverYouDoToTurnOnKitchenLights
ENDIF
ENDIF
Hmm, thats close, but not quite what I want. I want to have something more like:
"Devices::Field Write(GVAR:RoomToControl,100) On Click"
And any time I click the room button it will set the GVar:RoomToControl to the correct value.
I don't want to have to do a lot of IF statements. That makes it a pain to add any new rooms and the code gets very long when I have at least 8 rooms already.
Is this possible in 2.0?
Dean Roddey
11-07-2006, 05:05 PM
As long as the lighting fields you want to write to are consistently named, then you can set up a variable in each button that can be used to then build up the correct field in the buttons of the overlay, by just appending a few things to a variable to build up the whole name, and then do the write.
If they are consistently enough named, then no logic would be required. I.e. if every reach had a XXXLights, where XXX is the name of the room, then just set the variable to that XXX value, then build up a string by setting a variable to XX value, then append Lights and then write the value.
ellisr63
11-07-2006, 05:14 PM
Would you use a Global Variable if you want to control a device from multiple zones? If so why would you ever not make it a Global Variable?
Sendero
11-07-2006, 05:32 PM
As long as the lighting fields you want to write to are consistently named, then you can set up a variable in each button that can be used to then build up the correct field in the buttons of the overlay, by just appending a few things to a variable to build up the whole name, and then do the write.
If they are consistently enough named, then no logic would be required. I.e. if every reach had a XXXLights, where XXX is the name of the room, then just set the variable to that XXX value, then build up a string by setting a variable to XX value, then append Lights and then write the value.
Yup, all lights will be named consistently. I don't think I understand exactly how to do what you're saying though. In my current implementation I am only doing it on a single screen that is not using multiple overlays. I admit I still learning at this :) I'd like to have just one variable (selectedLight) that any button can set and then when I click the On button it uses that variable name as in my wish code above.
Also, how do I go about getting a download of the 2.0 beta? :)
ellisr63
11-07-2006, 05:36 PM
Yup, all lights will be named consistently. I don't think I understand exactly how to do what you're saying though. In my current implementation I am only doing it on a single screen that is not using multiple overlays. I admit I still learning at this :) I'd like to have just one variable (selectedLight) that any button can set and then when I click the On button it uses that variable name as in my wish code above.
Also, how do I go about getting a download of the 2.0 beta? :)
try this..
http://www.charmedquark.com/Web2/Downloads/Installers/CQC_1_7_15.Zip
Dean Roddey
11-07-2006, 06:07 PM
Wait a bit and get the 1.7.16 version. It fixes some known issues, and you might as well start with that. I'm testing it now.
Dean Roddey
11-07-2006, 06:08 PM
Yup, all lights will be named consistently. I don't think I understand exactly how to do what you're saying though. In my current implementation I am only doing it on a single screen that is not using multiple overlays. I admit I still learning at this :) I'd like to have just one variable (selectedLight) that any button can set and then when I click the On button it uses that variable name as in my wish code above.
That'll work. The buttons at the top just set the variable. The buttons at the bottom, when pressed, use that variable to build up the name of the fields they will write to.
You will want to have an OnLoad of the template to set the variable to some initial value so that it's always set.
Sendero
11-07-2006, 06:39 PM
That'll work. The buttons at the top just set the variable. The buttons at the bottom, when pressed, use that variable to build up the name of the fields they will write to.
You will want to have an OnLoad of the template to set the variable to some initial value so that it's always set.
Cool, I'll wait for the next version of the beta to be ready.
In the meantime, another question: Is there an easy way to do search/replace on a set of widgets? The full experience UI has a number of lightswitch graphics for controlling lights in diff areas. When I make new areas I select the set of widgets and copy/paste them but then I manually have to go into each one and change the target. I figure there has to be an easier way to do this.
Dean Roddey
11-07-2006, 06:43 PM
No, there currently isn't a way to do that. It's now very high on the list, as are usability issues in general.
Sendero
11-21-2006, 08:24 PM
OK, I got 2.0 setup and tried to get this workin. Here is an example of what I do on a button to select the light:
[OnClick]
GlobalVars::SetVariable(GVar:CurrentLight, Insteon.Den)
And when I click the On button I have this:
[OnClick]
Devices::FieldWrite(GVAR:CurrentLight, On)
But, I just get an error of
"'GVAR:CurrentLight' is not a valid field name. It must be in the form 'moniker.fldname'"
Did I miss something? How do I do what I wanted to do without using a ton of IF statements? My reading of this thread was that this code would work.
OK, I got 2.0 setup and tried to get this workin. Here is an example of what I do on a button to select the light:
[OnClick]
GlobalVars::SetVariable(GVar:CurrentLight, Insteon.Den)
And when I click the On button I have this:
[OnClick]
Devices::FieldWrite(GVAR:CurrentLight, On)
But, I just get an error of
"'GVAR:CurrentLight' is not a valid field name. It must be in the form 'moniker.fldname'"
Did I miss something? How do I do what I wanted to do without using a ton of IF statements? My reading of this thread was that this code would work.
Try making it GVar
(lowercase ar
actually, one of them is a fieldwrite, one of them is a setvariable.
make the fieldwrite a setvariable, does that work?
Sendero
11-21-2006, 08:45 PM
well, using the SetVariable doesn't error, but since I have another problem with the Insteon driver not loading I can't tell if its working right or not :) hopefully that was it, I'll report back if it wasn't. Thanks for the advice.
Sendero
11-28-2006, 02:37 PM
OK, got the new Insteon driver and now back to having issues with my UI.
The UI has only two 'room' buttons on it right now : Den and Kitchen.
The UI also has two 'action' buttons : On and Off
The Den button has this code:
[OnClick]
GlobalVars::SetVariable(GVar:CurrentLight, INSTEON.Den)
The On button has this code:
[OnClick]
GlobalVars::SetVariable(GVar:CurrentLight, 100)
When I click Den and then On, nothing happens. I know I have to be missing something here.
On a test button I have this code and it works fine:
[OnClick]
Devices::FieldWrite(INSTEON.Den, 100)
How do I have one button set the name of the driver:field and another button actually use that for a FieldWrite action?
Sendero
11-29-2006, 11:13 AM
OK, I got it working. In the click method for the On button, the code has to be a FieldWrite after all:
Devices::FieldWrite(%(GVar:CurrentLight), 100)
works like charm now
vBulletin v3.5.4, Copyright ©2000-2013, Jelsoft Enterprises Ltd.