Page 1 of 1

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

Posted: Monday 02 May 2016 14:46
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

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

Posted: Wednesday 04 May 2016 0:01
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

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

Posted: Wednesday 04 May 2016 13:27
by SoerenBM
Thank you, GD.

Worked perfectly :D

BR Søren