Possible to create 'user variable' within lua using "devicename" and openurl?

Moderator: leecollings

Post Reply
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

Possible to create 'user variable' within lua using "devicename" and openurl?

Post by SoerenBM »

Hi everyone,

I have a lot of virtual devices that I need to create a user variable for (for use with this script http://domoticz.com/forum/viewtopic.php?f=23&t=7512), but I would like to avoid to create them manually so I'm trying via LUA but am not able to get it to work:

Code: Select all

commandArray = {}

Domoticz_Devicename = 'Test Switch'

(devicechanged[''..Domoticz_Devicename..''] == 'On') then
    if(uservariables[''..Domoticz_Devicename..''] == nil) then
    commandArray['OpenURL'] = 'http://192.168.10.11:8080/json.htm?type=command&param=saveuservariable&vname='..Domoticz_Devicename..'&vtype=2&vvalue=1'

If I change vname='..Domoticz_Devicename..' to a hardcode vname like vname=TestSwitch it is working fine.


Just figured out the issue is because of the 'blank' in Domoticz_Devicename

Are there a way to work around this - as it is possible to create user variables manually with 'blanks' in the name.


Thanks.
BR Søren
georgesattali
Posts: 84
Joined: Saturday 05 March 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Possible to create 'user variable' within lua using "devicename" and openurl?

Post by georgesattali »

Yes, it is possible if you replace the blank by a "+" to conform to url encoding :

Code: Select all

...
Domoticz_Devicename = 'Test Switch'
noBlankDomoticz_Devicename = string.gsub(Domoticz_Devicename, " ", "+")
...
commandArray['OpenURL'] = 'http://192.168.10.11:8080/json.htm?type=command&param=saveuservariable&vname='..noBlankDomoticz_Devicename..'&vtype=2&vvalue=1'
...
See you,
GD
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

Re: Possible to create 'user variable' within lua using "devicename" and openurl?

Post by SoerenBM »

Thank you, GD.

Worked perfectly :D

BR Søren
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest