I created a global_data.lua file in the domoticz/scripts/dzVents/scripts directory. I know that Domoticz finds it because it contained a typo which showed up in the log. Fixed the typo to give this result:
Code: Select all
return {
helpers = {
urlEncode = function (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
}
}
Code: Select all
domoticz.helpers.urlEncode("test test")
Code: Select all
Error: EventSystem: in Button1: [string "--..."]:10: attempt to index global 'domoticz' (a nil value)
My full code (device trigger):
Code: Select all
--
-- Button1
--
commandArray = {}
for deviceName,deviceValue in pairs(devicechanged) do
if (deviceName=="Button1" and deviceValue~="Off") then
if (deviceValue=="Click") then
print(domoticz.helpers.urlEncode("test test"))
elseif (deviceValue=="Double Click") then
elseif (deviceValue=="Long Click") then
elseif (deviceValue=="Long Click Release") then
end
-- reset button
commandArray[#commandArray + 1] = {["UpdateDevice"] = "8|Off|0"}
end
end
return commandArray