-
-
Notifications
You must be signed in to change notification settings - Fork 24
Examples to use LUA to change setting on the fly.
Smanar edited this page Dec 16, 2019
·
8 revisions
In this example, you can change the sensor sensibility according to time.
-- demo setting update on the fly
--Special fonction
function os.capture(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if raw then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
function SendJsonWithReturn(url,json)
local curl = "/usr/bin/curl"
local cmd = curl .. ' -X PUT -d '..json..' '..url
local vac = os.capture(cmd, true)
return vac
end
function SendJson(url,json)
local curl = "/usr/bin/curl"
local cmd = curl .. ' -X PUT -d '..json..' '..url
local vac = os.execute(cmd)
if vac ~= true then
print('Send JSON Error')
end
end
-- Script here
commandArray={}
local heure = os.date("%H:%M")
if (heure == '13:43') then
print('Setting sensor sensitivity to 5')
SendJson('http://192.168.1.1:80/api/787EE274E/sensors/15/config','\'{"sensitivity":5}\'')
end
We can too use DZ-Event with domoticz.openURL() but I haven't see an advantage in this situation.