Hi all,
Is there any way to create the user variable in domoticz by lua script ?
UserVariables in scrips
Moderator: leecollings
-
- Posts: 12
- Joined: Tuesday 26 July 2016 13:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.4834
- Location: France
- Contact:
UserVariables in scrips
José
Domoticz raspberry pi
Version 3.4834
Domoticz raspberry pi
Version 3.4834
-
- Posts: 84
- Joined: Saturday 05 March 2016 16:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: France
- Contact:
Re: UserVariables in scrips
yes, here an example :
but beware, that using commandArray, the variable will be created only when the script exits.
otherwise, you may use curl with the same kind of http call.
details here : https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s
Bye, GD
but beware, that using commandArray, the variable will be created only when the script exits.
otherwise, you may use curl with the same kind of http call.
details here : https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s
Code: Select all
ip = '127.0.0.1:8080' -- user:pass@ip:port de domoticz
function UrlEncode(str) -- source : http://lua-users.org/wiki/StringRecipes
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
varName = "My Var Name"
if (uservariables[varName] == nil) then
i=1
urlVarName = UrlEncode(varName)
commandArray[i]= { ['OpenURL'] = ip -- create variable
..'/json.htm?type=command¶m=saveuservariable'
..'&vname='..urlVarName
..'&vtype=2'
..'&vvalue='.."0"
end
-
- Posts: 12
- Joined: Tuesday 26 July 2016 13:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.4834
- Location: France
- Contact:
Re: UserVariables in scrips
Hi GD,
Thanks a lot, I will try this asap
Thanks a lot, I will try this asap
José
Domoticz raspberry pi
Version 3.4834
Domoticz raspberry pi
Version 3.4834
-
- Posts: 12
- Joined: Tuesday 26 July 2016 13:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.4834
- Location: France
- Contact:
Re: UserVariables in scrips
Hi all
I have tried this one:
and the result in logs is
If I put the url in a local variable, and print it, I get the same result.
is there any issue for this ?
I have tried this one:
Code: Select all
urlVarName = UrlEncode('MonTest')
commandArray[1]= { ['OpenURL'] = ip -- create variable
..'/json.htm?type=command¶m=saveuservariable'
..'&vname='..urlVarName
..'&vtype=2'
..'&vvalue='..'"0"'}
Code: Select all
2016-08-02 13:58:44.351 Error: Error opening url: X.X.X.X:Y/json.htm?type=command¶m=saveuservariable&vname=MonTest&vtype=2&vvalue="10"
is there any issue for this ?
José
Domoticz raspberry pi
Version 3.4834
Domoticz raspberry pi
Version 3.4834
-
- Posts: 12
- Joined: Tuesday 26 July 2016 13:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.4834
- Location: France
- Contact:
Re: UserVariables in scrips
Hi all
My problem is solved.
I'had made a mistake on my IP.
Thanks a lot GD and all others.
My problem is solved.
I'had made a mistake on my IP.
Thanks a lot GD and all others.
José
Domoticz raspberry pi
Version 3.4834
Domoticz raspberry pi
Version 3.4834
Who is online
Users browsing this forum: No registered users and 1 guest