We have moved at community.getvera.com

Author Topic: Creating changable variables?  (Read 2055 times)

Offline computerScience

  • Jr. Member
  • **
  • Posts: 70
  • Karma: +0/-0
Creating changable variables?
« on: September 19, 2011, 02:24:50 pm »
Hello folks,

Does anyone know how I can create a device that keeps variables that are changable from luup?

I've tried to create a device Description: "System"and left all other fields empty.
Then I created a Variable: Service: "SystemDevice1", variable: "Mode", value: "out"

And I am trying to change this variable from luup code with no great success:
luup.variable_set("SystemDevice1", "Mode", "home", 28)

What am I doing wrong here?

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: Creating changable variables?
« Reply #1 on: September 19, 2011, 05:37:56 pm »
Hi computerScience,

You may not be doing anything wrong.  If you are following the variable's value in the Advanced tab, then you won't see it change.  But it is changing.  To see it change in real time you'd have to get the variable to display on the dashboard by creating a Static JSON file.

Offline computerScience

  • Jr. Member
  • **
  • Posts: 70
  • Karma: +0/-0
Re: Creating changable variables?
« Reply #2 on: September 19, 2011, 07:01:21 pm »
Thank you very much for your reply.

I assumed the change is not visible under the advanced tab but I am still not getting it to work, I tried this code:
Code: [Select]
  luup.variable_set("serviceTest", "variableTest", "1", 28)

local var1=luup.variable_get("serviceTest", "variableTest", 28)


if (var1=="1") then
 luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "0"}, 17)
   return false
else
 luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "50"}, 17)
   return false
end

This code results in a dimming level of 50% which means that the variable 'var1' is not equal to "1".
Am I allowed to use such simple service names as only "serviceTest"?
What am I doing wrong here?


Thanks in advance,
ComputerScience90

Offline computerScience

  • Jr. Member
  • **
  • Posts: 70
  • Karma: +0/-0
Re: Creating changable variables?
« Reply #3 on: September 19, 2011, 07:13:18 pm »
ok I actually got the above code working while using a static JSON file (D_PluginName.xml) while creating the device.
However it does not update the variable under advanced tab dynamically. I did not fully understand how to solve this?

Thanks Again,
ComputerScience90

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: Creating changable variables?
« Reply #4 on: September 19, 2011, 08:33:36 pm »
What is there to solve? The Advanced tab doesn't update in real time. It isn't meant to. There is no workaround except looking at your variable some other way (static JSON, or by triggering a lamp as you did).

Service IDs can be any string. They are URNs only by convention to protect people from picking colliding namespaces.