I think I am asking for a virtual device. But I was surprised that there is no way via the gui to create one and/or set a global variable that could be used as true/false tests on scenes (outside the scope of the creating scene). Am I missing something?
I did this with a simple virtual device:
http://forum.micasaverde.com/index.php/topic,9022.0.html
I found no other way…
It depends on what variable you were looking to set. But the way I have mine setup was just a simple 0 or 1 to denote if I was home or not to use when running a scene with luup code.
To create a variable like this, choose any module you currently have setup on your Vera (I chose my office light). Click on the wrench of the device you want to use to hold your variable and navigate to the “Advanced” tab. If you scroll all the way down you will see three open fields (New Service, New Variable, New Value). This is where you can define a new variable that will be held within your preexisting device that can be called at anytime.
I used the following parameters:
New Service: Home1
New Variable: Home
New Value: 1
When you click the add button to the right of the “New Value” field you should now see that the new variable you created, in the “Advanced” tab.
When calling the variable in Luup code make sure you use the below code, otherwise just calling the lamp module will not pull anything.
local cur_home = luup.variable_get("Home1","Home",Your-Own-DEVICE-ID) or 0
If you want to have a scene update the variable here is the code for that as well:
luup.variable_set("Home1","Home","New-Variable",Your-Own-DEVICE-ID)
Hope this helps,
Pavs
bpavlica,
Thanks so much for this little bit of info. I have looked for an explanation of those parameters for a while, and never found anything. I never considered the fact that the 3 were used together, and never had any luck just trying to set just the ‘variable’. Now I understand why! Knowing how this works adds another useful tool in my arsenal of programming skills.
kartcon
bpavlica,
I’ve been struggling to reproduce what you provided for kartcon. I hope you can help me as my frustration level is getting the better of me.
If you could indulge me could I explain what I’ trying to do?
I have a domestic hot water circulation pump. I use a variety of motion sensors to cycle the pump for 5 minutes when motion detected. The problem is the pump ends up running all the time.
My mission: Add a New Variable in the pump “Light Module”. Store when the pump was last run in this variable. Make sure that at least 15 minutes have passed since the “Last Run” before allowing it to run again.
Now to my sad tale…
I have added a new variable to a lamp module with the following settings;
Device ID: 6
New Service: “PtServa1”
New Variable: “LastRun”
New Variable: “PutAValue” This is just test string. I will store os.time() when I get the process to work.
I pasted the following into the Develop Apps/TEST Luup code:
luup.variable_set(“PtServa”,“LastRun”,“PutAValue”,6)
return true
Actually, I ran the above a couple times, checking the Advanced Properties each time.
Much to my surprise, I now find the variable “LastRun” Three times in a row!
Now my advanced tab looks like this
LastRun 1327606662 (This is a value I hand typed in before running the above code.)
LastRun PutAValue
LastRun PutAValue
This seems drastically wrong, correct?
QUESTION #1: How can I rid myself of the multiple entries? Delete and re-add this device? I’ve been researching this for some time, elsewhere I saw this question asked (how to remove a new service/variable). I believe the answer was to hand edit some files with the advice that this should not be done by the inexperienced and better to let this alone as it was not hurting anything.
QUESTION #2: What is the correct syntax to write and read this value from a scene?
I really much appreciate any light you can shed on this issue.
Thanks!
Hello PhilTMan,
Question1:
The first thing I notice is that you start the new variable with:
New Service: “PtServa1”
New Variable: “LastRun”
Then you call the variable by using luup.variable_set(“PtServa”,“LastRun”,“PutAValue”,6)
It appears that you left out a “1” to the PtServa when you set the variable, meaning Vera created an additional Service and Variable. So that takes care of why there are two LastRun - Variables. The third is because all modules are inherently setup with a “LastRun” variable that Vera can call.
I have not had to reset my modules yet, but logically it makes sense that removing it and adding the module will be your best bet.
Question2:
When calling/reading the variable in Luup code make sure you use the below code, otherwise just calling the lamp module will not pull anything.
local cur_home = luup.variable_get("Home1","Home",Your-Own-DEVICE-ID) or 0
If you want to have a scene update/write the variable here is the code for that as well:
luup.variable_set("Home1","Home","New-Variable",Your-Own-DEVICE-ID)
Also, you don’t need to return true after you set the variable if that is the only bit of Luup code you are using.
Hope this helps,
Pavs
Bpavlica,
Thanks your your reponce. Can you clairfy “Question2:”?
With:
local cur_home = luup.variable_get("Home1","Home",Your-Own-DEVICE-ID) or 0
What value do I use for “Your-Own-Device-ID”? The only device ID involved is the ID of the device I have added the new variable to. When I create a new variable under this device, I don’t provide a Device ID.
Really confused. Thanks for your help.
Hey PhilTMan,
The Device ID is just what you said, the device where you added the new variable. Since you can have many variable and services that are the same you have to point Vera to a particular device so that it knows where to look for the new variable that you created. So in your situation that would be device 6.
Pavs