Quel emmerdeur que je suis
-- Generic device type have no default actions to handle
-- To update controls you can use method self:updateView(<component ID>, <component property>, <desired value>). Eg:
-- self:updateView("slider", "value", "55")
-- self:updateView("button1", "text", "MUTE")
-- self:updateView("label", "text", "TURNED ON")
-- This is QuickApp inital method. It is called right after your QuickApp starts (after each save or on gateway startup).
-- Here you can set some default values, setup http connection or get QuickApp variables.
-- To learn more, please visit:
-- * https://manuals.fibaro.com/home-center-3/
-- * https://manuals.fibaro.com/home-center-3-quick-apps/
function QuickApp:send(dataToSend, waitForResponse)
self.sock:close()
self:connect(function()
local dataConverted = self:parseData(dataToSend) -- replace string starting with '0x' to hex value
self.sock:write(dataConverted, {
success = function()
if waitForResponse then
self:waitForResponseFunction()
else
self.sock:close()
end
end,
error = function(err)
self.sock:close()
end
})
end)
end
function QuickApp:parseData(str)
while true do
if string.find(str, '0x') then
i,j = string.find(str, '0x')
str = string.sub(str, 1, i - 1) .. self:fromhex(string.sub(str, i + 2, j +2)) .. string.sub(str, j + 3)
else
return str
end
end
end
function QuickApp:fromhex(str)
return (str:gsub('..', function(cc)
return string.char(tonumber(cc, 16))
end))
end
function QuickApp:waitForResponseFunction()
self.sock:read({
success = function(data)
self:debug("response data:", data)
self.sock:close()
end,
error = function()
self:debug("response error")
self.sock:close()
end
})
end
function QuickApp:connect(successCallback)
print("connecting:", self.ip, self.port)
self.sock:connect(self.ip, self.port, {
success = function()
self:debug("connected")
successCallback()
end,
error = function(err)
self.sock:close()
self:debug("connection error")
end,
})
end
function QuickApp:onInit()
self:debug("onInit")
self.ip = self:getVariable("ip")
self.port = tonumber(self:getVariable("port"))
self.sock = net.TCPSocket()
end
--------------------------------------------------------
function Essai()
toto = toto + 1
print(toto)
setTimeout(Essai, 4*1000)
end
function QuickApp:onInit()
self:debug("onInit")
idclim = 353
idclim2 = 93
timeoutClim1 = 0
timeoutClim2 = 0
duration = 0
toto = 0
Essai()
end
function QuickApp:Raf1()
self:updateView("power1", "text", "Climatiseur N°1 - "..fibaro.getValue(idclim, "power").." W")
self:updateView("power2", "text", "Climatiseur N°2 - "..fibaro.getValue(idclim2, "power").." W")
end
--2H
function QuickApp:buttonClim2()
self:debug("BOUTON 2H")
duration = 30*1000
test1(self)
test2(self)
end
--4H
function QuickApp:buttonClim4()
self:debug("BOUTON 4H")
duration = 60*1000
test1(self)
test2(self)
end
function QuickApp:buttonReset()
duration = 0
test1(self)
end
function QuickApp:ON24_S1_C1()
fibaro.call(353, "turnOn")
self:debug("onInit")
end
function QuickApp:OFF_S1_C1()
fibaro.call(353, "turnOff")
self:debug("onInit")
end
function QuickApp:ON24_S1_C2()
fibaro.call(93, "turnOn")
end
function QuickApp:OFF_S1_C2()
fibaro.call(93, "turnOff")
end
function test1(self)
---self:ON24_S1_C1()
if timeoutClim1 > 0 then clearTimeout(timeoutClim1) timeoutClim1 = 0 end
timeoutClim1 = setTimeout(function() self:OFF_S1_C1() end, duration)
end
function test2(self)
---self:ON24_S1_C2()
if timeoutClim2 > 0 then clearTimeout(timeoutClim2) timeoutClim2 = 0 end
timeoutClim2 = setTimeout(function() self:OFF_S1_C2() end, duration)
end
--[[
---------------- CODE IR CLIM N°1 -----------------
function QuickApp:ON22_S1_C1()
---fibaro.call(89, "turnOn")
self:send("sendir,1:3,1,36656,1,1,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,366,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,48,16,48,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,46920x0D0x0A",true)
end
function QuickApp:ON24_S1_C1()
--- fibaro.call(89, "turnOn")
self:send("sendir,1:3,1,36656,1,1,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,366,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,48,16,48,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,46920x0D0x0A",true)
end
function QuickApp:OFF_S1_C1()
---- fibaro.call(89, "turnOff")
self:send("sendir,1:3,1,36656,1,1,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,366,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,48,16,48,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,46920x0D0x0A",true)
end
---------------- CODE IR CLIM N°2 -----------------
function QuickApp:ON22_S1_C2()
self:send("sendir,1:3,1,36656,1,1,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,366,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,48,16,48,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,46920x0D0x0A",true)
end
function QuickApp:ON24_S1_C2()
--- fibaro.call(89, "turnOn")
self:send("sendir,1:3,1,36656,1,1,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,366,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,48,16,48,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,46920x0D0x0A",true)
end
function QuickApp:OFF_S1_C2()
self:send("sendir,1:3,1,36656,1,1,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,366,129,63,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,48,16,16,16,48,16,48,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,48,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,16,16,48,16,16,16,16,16,16,16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,48,16,16,16,48,16,16,16,16,16,48,16,46920x0D0x0A",true)
end
--]]