Hi!
Is it possible to create a new user variable from within a LUA script, e.g. checking if a variable exists and if not, creating it?
LUA: create user variable from within LUA script?
Moderator: leecollings
- blitzkneisser
- Posts: 43
- Joined: Tuesday 01 December 2015 8:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version: stable
- Location: Villach, Austria
- Contact:
-
- Posts: 192
- Joined: Monday 12 January 2015 23:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.1
- Location: FRANCE
- Contact:
Re: LUA: create user variable from within LUA script?
Yes,
Check with this :
and create with the API; look here :
https://www.domoticz.com/wiki/Domoticz_ ... w_variable
Check with this :
Code: Select all
if not uservariables['name'] then
print('User Variable doesnt exist.')
end
https://www.domoticz.com/wiki/Domoticz_ ... w_variable
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de maison de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de maison de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
- papoo
- Posts: 126
- Joined: Friday 22 January 2016 22:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10
- Location: France
- Contact:
Re: LUA: create user variable from within LUA script?
Code: Select all
if(uservariables['variable_name'] == nil) then
commandArray['OpenURL']=url..'/json.htm?type=command¶m=saveuservariable&vname='..url_encode('variable_name')..'&vtype=2&vvalue=1'
else
...
- blitzkneisser
- Posts: 43
- Joined: Tuesday 01 December 2015 8:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version: stable
- Location: Villach, Austria
- Contact:
Re: LUA: create user variable from within LUA script?
Ah, yes, of course!
Thanks!
Thanks!
-
- Posts: 192
- Joined: Monday 12 January 2015 23:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.1
- Location: FRANCE
- Contact:
Re: LUA: create user variable from within LUA script?
Interesting. I didn't know url_encode. I found the code here : http://lua-users.org/wiki/StringRecipes if you need.
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de maison de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de maison de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
- papoo
- Posts: 126
- Joined: Friday 22 January 2016 22:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10
- Location: France
- Contact:
Re: LUA: create user variable from within LUA script?
Code: Select all
function url_encode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w %-%_%.%~])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
Who is online
Users browsing this forum: No registered users and 0 guests