Skip to content

Instantly share code, notes, and snippets.

@sameeraakbar
Created February 18, 2021 08:46
Show Gist options
  • Save sameeraakbar/ab21b89e4cf019e443e6ac4932ae93fa to your computer and use it in GitHub Desktop.
Save sameeraakbar/ab21b89e4cf019e443e6ac4932ae93fa to your computer and use it in GitHub Desktop.
Fibaro HC3 Global Cache/Zmote Quick App
{"name":"Camipro AC","type":"com.fibaro.genericDevice","apiVersion":"1.2","initialProperties":{"viewLayout":{"$jason":{"body":{"header":{"style":{"height":"0"},"title":"quickApp_device_87"},"sections":{"items":[{"components":[{"components":[{"name":"button2_1","style":{"weight":"0.50"},"text":"ON","type":"button"},{"name":"button2","style":{"weight":"0.50"},"text":"OFF","type":"button"}],"style":{"weight":"1.2"},"type":"horizontal"},{"style":{"weight":"0.5"},"type":"space"}],"style":{"weight":"1.2"},"type":"vertical"},{"components":[{"components":[{"name":"button5_1_1","style":{"weight":"0.20"},"text":"17","type":"button"},{"name":"button5_2_1","style":{"weight":"0.20"},"text":"18","type":"button"},{"name":"button5_3_1","style":{"weight":"0.20"},"text":"19","type":"button"},{"name":"button5_4_1","style":{"weight":"0.20"},"text":"20","type":"button"},{"name":"button5_5","style":{"weight":"0.20"},"text":"21","type":"button"}],"style":{"weight":"1.2"},"type":"horizontal"},{"style":{"weight":"0.5"},"type":"space"}],"style":{"weight":"1.2"},"type":"vertical"},{"components":[{"components":[{"name":"button5_1","style":{"weight":"0.20"},"text":"22","type":"button"},{"name":"button5_2","style":{"weight":"0.20"},"text":"23","type":"button"},{"name":"button5_3","style":{"weight":"0.20"},"text":"24","type":"button"},{"name":"button5_4","style":{"weight":"0.20"},"text":"25","type":"button"},{"name":"button5","style":{"weight":"0.20"},"text":"26","type":"button"}],"style":{"weight":"1.2"},"type":"horizontal"},{"style":{"weight":"0.5"},"type":"space"}],"style":{"weight":"1.2"},"type":"vertical"},{"components":[{"components":[{"name":"button4_1","style":{"weight":"0.25"},"text":"27","type":"button"},{"name":"button4_2","style":{"weight":"0.25"},"text":"28","type":"button"},{"name":"button4_3","style":{"weight":"0.25"},"text":"29","type":"button"},{"name":"button4","style":{"weight":"0.25"},"text":"30","type":"button"}],"style":{"weight":"1.2"},"type":"horizontal"},{"style":{"weight":"0.5"},"type":"space"}],"style":{"weight":"1.2"},"type":"vertical"}]}},"head":{"title":"quickApp_device_87"}}},"uiCallbacks":[{"callback":"buttonOnReleased","eventType":"onReleased","name":"button2_1"},{"callback":"buttonOffReleased","eventType":"onReleased","name":"button2"},{"callback":"button17Released","eventType":"onReleased","name":"button5_1_1"},{"callback":"button18Released","eventType":"onReleased","name":"button5_2_1"},{"callback":"button19Released","eventType":"onReleased","name":"button5_3_1"},{"callback":"button20Released","eventType":"onReleased","name":"button5_4_1"},{"callback":"button21Released","eventType":"onReleased","name":"button5_5"},{"callback":"button22Released","eventType":"onReleased","name":"button5_1"},{"callback":"button23Released","eventType":"onReleased","name":"button5_2"},{"callback":"button24Released","eventType":"onReleased","name":"button5_3"},{"callback":"button25Released","eventType":"onReleased","name":"button5_4"},{"callback":"button26Released","eventType":"onReleased","name":"button5"},{"callback":"button27Released","eventType":"onReleased","name":"button4_1"},{"callback":"button28Released","eventType":"onReleased","name":"button4_2"},{"callback":"button29Released","eventType":"onReleased","name":"button4_3"},{"callback":"button30Released","eventType":"onReleased","name":"button4"}],"quickAppVariables":[{"name":"ip","value":"192.168.5.168"},{"name":"port","value":"4998"}],"typeTemplateInitialized":true},"files":[{"name":"main","isMain":true,"isOpen":true,"content":"-- Generic device type have no default actions to handle\n\n-- To update controls you can use method self:updateView(<component ID>, <component property>, <desired value>). Eg: \n-- self:updateView(\"slider\", \"value\", \"55\") \n-- self:updateView(\"button1\", \"text\", \"MUTE\") \n-- self:updateView(\"label\", \"text\", \"TURNED ON\") \n\n-- This is QuickApp inital method. It is called right after your QuickApp starts (after each save or on gateway startup). \n-- Here you can set some default values, setup http connection or get QuickApp variables.\n-- To learn more, please visit: \n-- * https://manuals.fibaro.com/home-center-3/\n-- * https://manuals.fibaro.com/home-center-3-quick-apps/\nfunction QuickApp:send(dataToSend, waitForResponse) -- self:send reaches this function\n self.sock:close()\n self:connect(function() \n local dataConverted = self:parseData(dataToSend) -- replace string starting with '0x' to hex value\n self.sock:write(dataConverted, {\n success = function()\n if waitForResponse then\n self:waitForResponseFunction()\n else\n self.sock:close()\n end\n end,\n error = function(err)\n self.sock:close()\n end\n })\n end)\nend\n\nfunction QuickApp:parseData(str)\n while true do \n if string.find(str, '0x') then\n i,j = string.find(str, '0x')\n str = string.sub(str, 1, i - 1) .. self:fromhex(string.sub(str, i + 2, j +2)) .. string.sub(str, j + 3)\n else\n return str\n end\n end\nend\n\nfunction QuickApp:fromhex(str)\n return (str:gsub('..', function(cc)\n return string.char(tonumber(cc, 16))\n end))\nend\n\nfunction QuickApp:waitForResponseFunction()\n self.sock:read({\n success = function(data)\n self:debug(\"response data:\", data)\n self.sock:close()\n end,\n error = function()\n self:debug(\"response error\")\n self.sock:close()\n end\n })\nend\n\nfunction QuickApp:connect(successCallback)\n print(\"connecting:\", self.ip, self.port)\n self.sock:connect(self.ip, self.port, {\n success = function()\n self:debug(\"connected\")\n successCallback()\n end,\n error = function(err)\n self.sock:close()\n self:debug(\"connection error\")\n end,\n })\nend \nfunction QuickApp:onInit()\n self:debug(\"onInit\")\n self.ip = self:getVariable(\"ip\")\n self.port = tonumber(self:getVariable(\"port\"))\n self.sock = net.TCPSocket()\nend\n\nfunction QuickApp:buttonOnReleased(event)\nself:send(\"sendir,1:1,0,37000,1,1,163,162,19,62,18,22,18,63,18,63,18,22,19,22,18,63,18,22,20,20,18,63,18,22,19,22,18,63,19,62,18,22,18,63,20,20,18,22,18,63,19,62,18,63,18,63,18,63,18,63,20,61,18,63,19,22,18,22,18,22,18,22,19,22,18,22,20,20,19,22,19,22,18,22,18,22,18,22,18,22,19,22,20,61,18,63,18,63,18,63,18,63,18,63,18,63,18,63,20,194,163,162,19,62,18,22,19,62,18,63,18,22,18,22,19,62,18,22,20,20,18,63,18,22,19,22,18,63,18,63,18,22,18,63,20,20,18,22,18,63,19,62,18,63,18,63,18,63,19,62,20,61,18,63,18,22,18,22,18,22,18,22,18,22,18,22,20,20,19,22,19,22,18,22,19,22,18,22,18,22,18,22,20,61,18,63,18,63,18,63,18,63,18,63,18,63,18,63,19,37000x0D0x0A\",true)\nend\n\nfunction QuickApp:buttonOffReleased(event)\nself:send(\"sendir,1:2,0,37000,1,1,7,2192,164,163,18,63,19,22,19,62,19,62,19,22,19,22,19,62,19,22,20,20,19,62,19,22,19,22,19,62,19,62,19,22,19,62,20,20,19,62,19,62,19,62,19,62,19,22,19,62,19,62,20,61,19,21,20,22,19,22,19,22,19,62,19,22,19,22,20,61,19,62,19,62,19,22,19,22,19,22,19,22,19,22,20,20,19,22,19,22,19,62,19,62,19,62,19,62,19,62,20,194,163,162,19,62,19,22,19,62,19,62,19,22,19,22,19,62,19,22,20,20,19,62,19,22,19,22,19,62,19,62,19,22,19,62,20,20,19,62,19,62,19,62,19,62,19,22,19,62,19,62,20,61,19,22,19,22,19,22,19,22,19,62,19,22,19,22,20,61,19,62,19,62,19,22,19,22,19,22,19,22,19,22,20,20,19,22,19,22,19,62,19,62,19,62,19,62,18,63,19,37000x0D0x0A\",true)\nend\n\nfunction QuickApp:button17Released(event)\nself:send(\"sendir,1:4,0,37000,1,1,163,164,19,62,19,21,19,62,19,62,19,21,19,21,19,62,19,21,19,21,19,62,19,21,19,21,19,62,19,62,19,21,19,62,19,21,19,21,19,62,19,62,19,62,19,62,19,62,19,62,19,62,19,62,19,21,19,21,19,21,19,21,19,21,19,21,19,21,19,21,19,21,19,21,19,21,19,21,19,21,19,21,19,62,19,62,19,62,19,62,19,62,19,62,19,62,19,62,19,194,162,163,19,62,19,21,19,62,19,62,19,21,19,21,19,62,19,21,20,20,19,62,19,21,19,21,19,62,19,62,19,21,19,62,19,21,19,21,19,62,19,62,19,62,19,62,19,62,19,62,19,61,19,62,19,21,19,21,19,21,19,21,19,21,19,21,19,21,19,21,19,21,19,21,19,21,19,21,19,21,19,21,19,62,19,62,19,62,19,62,19,62,19,62,19,62,19,62,19,37000x0D0x0A\",true)\nend\n\nfunction QuickApp:button18Released(event)\nself:send(\"sendir,1:1,0,37000,1,1,164,163,18,63,18,22,19,62,19,62,18,22,18,22,19,62,19,22,20,20,18,63,19,22,19,22,18,63,18,63,18,22,19,62,20,20,18,22,18,63,19,62,18,63,18,63,19,62,19,62,20,61,19,62,18,22,18,22,18,22,19,22,18,22,19,22,20,20,19,22,18,22,19,62,19,22,19,22,19,22,19,22,20,61,19,62,18,63,19,22,19,62,19,62,18,63,18,63,20,194,163,162,18,63,18,22,18,63,18,63,18,22,19,22,18,63,19,22,20,20,19,62,18,22,19,22,19,62,19,62,19,22,18,63,20,20,19,22,19,62,19,62,18,63,18,63,19,62,18,63,20,61,19,62,18,22,18,22,19,22,18,22,19,22,18,22,20,20,18,22,19,22,19,62,19,22,19,22,18,22,19,22,20,61,19,62,18,63,19,22,19,62,19,62,19,62,19,62,19,37000x0D0x0A\",true)\nend\n\nfunction QuickApp:button19Released(event)\nself:send(\"sendir,1:1,0,37000,1,1,164,163,19,62,19,22,19,62,19,62,19,22,19,22,19,62,19,22,20,20,19,62,19,22,19,22,19,62,19,62,19,22,19,62,20,20,19,22,19,62,19,62,19,62,19,62,19,62,19,62,20,61,19,62,19,22,19,22,19,22,19,22,19,22,19,22,20,20,19,22,19,62,19,62,19,22,19,22,19,22,19,22,20,61,19,62,19,22,19,22,19,62,19,62,19,62,19,62,20,194,163,163,19,62,19,22,19,62,19,62,19,22,19,22,19,62,19,22,20,20,19,62,19,22,19,22,19,62,19,62,19,22,19,62,20,20,18,22,19,62,19,62,19,62,19,62,19,62,19,62,20,61,19,62,19,22,19,22,19,22,19,22,19,22,19,22,20,20,19,22,19,62,19,62,19,22,19,22,19,22,19,22,20,61,19,62,19,22,19,22,19,62,19,62,19,62,19,62,19,37000x0D0x0A\",true)\nend\n\nfunction QuickApp:button20Released(event)\nself:send(\"sendir,1:1,0,37000,1,1,164,162,19,62,19,22,19,62,19,62,19,22,19,21,19,62,19,21,21,20,19,62,20,21,19,22,19,62,19,62,19,21,19,62,20,20,20,21,19,62,19,62,19,62,19,62,20,61,19,62,20,61,19,62,19,21,19,21,19,22,19,22,19,22,19,22,20,20,19,21,19,62,20,21,19,22,19,22,19,22,19,22,20,61,19,62,19,22,20,61,19,62,19,62,19,62,19,61,21,194,163,162,19,62,19,21,19,62,19,62,19,21,19,21,20,61,20,21,20,20,19,62,19,21,19,22,19,62,19,62,19,21,19,62,20,20,19,21,19,62,19,62,19,62,19,62,19,62,19,62,20,61,20,61,19,22,19,21,19,22,19,22,20,21,19,22,20,20,19,21,19,62,20,21,20,21,19,21,19,22,19,22,20,61,19,62,19,21,20,62,19,62,19,62,19,62,20,61,19,37000x0D0x0A\",true)\nend\n\nfunction QuickApp:button21Released(event)\nself:send(\"sendir,1:1,0,37000,1,1,163,162,19,62,18,22,18,63,18,62,19,22,18,22,18,63,18,22,20,20,18,63,18,22,19,22,18,63,18,63,18,22,18,63,20,20,18,22,18,63,18,63,18,63,18,63,19,62,18,63,20,61,18,63,18,22,19,22,19,22,18,22,19,22,18,22,20,20,18,63,18,63,18,22,18,22,18,22,19,22,18,22,20,61,18,22,18,22,18,63,18,63,18,63,18,63,18,63,20,194,164,162,18,63,18,22,19,62,18,63,19,22,18,22,18,62,19,22,21,20,18,63,19,22,19,22,18,63,18,63,18,22,18,63,20,20,18,22,18,63,19,62,19,62,18,63,18,63,18,63,20,61,19,62,18,22,18,22,18,22,19,22,18,22,19,22,20,20,18,63,18,63,18,22,18,22,18,22,18,22,19,22,20,61,19,22,18,22,18,63,18,63,19,62,18,63,18,63,19,37000x0D0x0A\",true)\nend\n\nfunction QuickApp:button22Released(event)\nself:send(\"sendir,1:1,0,37000,1,1,162,164,18,63,18,21,19,63,19,62,19,21,19,21,18,63,18,22,20,20,19,62,18,22,19,22,19,62,18,63,18,22,18,63,20,20,18,22,18,63,18,63,18,63,19,62,19,62,19,62,20,61,18,63,18,22,18,22,18,22,19,22,18,22,18,22,20,20,19,62,19,62,18,63,18,22,19,21,18,22,18,22,20,61,18,22,19,21,18,22,18,63,19,62,18,63,18,63,20,194,163,163,19,62,18,22,19,63,19,62,19,22,18,22,18,63,18,22,20,20,18,62,19,22,18,22,19,62,18,63,19,21,18,63,20,20,18,22,19,62,18,63,19,62,18,63,19,62,18,63,20,61,19,62,19,21,18,22,18,22,18,22,19,21,19,21,20,20,19,62,19,62,18,63,18,22,19,21,18,22,18,22,20,61,18,22,18,22,18,22,18,63,19,62,18,63,18,62,19,37000x0D0x0A\",true)\nend\n\nfunction QuickApp:button23Released(event)\nself:send(\"sendir,1:1,0,37000,1,1,164,162,19,62,18,22,19,62,18,63,18,22,19,21,18,63,18,22,20,20,18,63,19,21,18,22,18,63,18,63,19,21,18,63,20,20,18,22,19,61,20,62,19,62,18,63,19,62,19,62,20,61,19,62,19,21,19,21,19,21,19,21,19,21,19,21,20,20,19,62,18,22,19,62,19,21,19,21,19,21,19,21,20,61,19,21,18,63,19,22,18,63,19,62,19,62,19,62,20,194,163,162,19,62,18,22,19,62,19,62,19,21,19,21,18,63,19,21,20,20,19,62,19,21,19,21,19,62,19,62,19,21,19,62,20,20,19,21,19,62,19,62,18,62,19,62,19,62,19,62,20,61,18,63,19,21,18,22,19,21,19,21,19,21,18,22,20,20,19,62,18,22,19,62,18,22,19,21,18,22,19,21,20,61,19,21,18,63,19,21,19,62,19,62,19,62,20,61,18,37000x0D0x0A\",true)\nend\n\nfunction QuickApp:button24Released(event)\nself:send(\"sendir,1:1,0,37000,1,1,163,163,19,62,19,21,18,63,19,62,19,21,18,22,18,63,19,21,20,20,19,62,18,22,19,21,19,62,19,62,19,21,19,62,20,20,19,21,19,62,18,63,19,62,19,62,19,62,19,62,20,61,19,62,19,21,19,21,19,21,19,21,19,21,18,22,20,20,19,62,19,21,19,21,19,21,18,22,18,22,19,21,20,61,18,22,18,63,19,61,20,62,19,62,19,62,19,62,20,194,163,162,19,62,19,21,19,62,19,62,19,21,18,22,19,62,19,21,20,20,19,62,19,21,19,21,18,63,19,62,19,21,18,63,20,20,18,22,19,62,19,62,18,63,19,62,19,62,18,63,20,61,19,62,19,21,18,22,18,22,18,22,19,21,18,22,20,20,18,63,19,21,18,22,19,21,19,21,18,22,19,22,20,61,19,21,19,62,19,62,19,62,18,63,19,62,19,62,18,37000x0D0x0A\",true)\nend\n\nfunction QuickApp:button25Released(event)\nself:send(\"sendir,1:1,0,37000,1,1,4,82,162,164,18,63,18,22,19,62,19,62,18,22,18,22,18,63,18,22,20,20,18,63,18,22,18,22,18,63,18,63,18,22,18,63,20,20,19,22,18,63,18,63,18,63,19,62,18,63,18,63,22,59,18,63,18,22,18,22,19,22,19,22,19,22,18,22,20,61,19,62,18,22,18,22,18,22,19,22,19,22,18,23,22,18,19,22,18,63,18,63,18,63,19,62,19,62,19,62,20,194,163,163,18,63,18,22,19,62,19,62,18,22,19,22,18,63,18,22,20,20,18,63,18,22,19,22,18,63,18,63,19,22,18,63,20,20,19,22,18,63,18,63,18,63,18,63,18,63,18,63,20,61,19,62,18,22,18,22,19,22,18,22,19,22,19,22,20,61,18,63,19,22,18,22,18,22,18,22,18,22,19,22,20,20,19,22,18,63,18,63,18,63,19,62,19,62,18,63,18,37000x0D0x0A\",true)\nend\n\nfunction QuickApp:button26Released(event)\nself:send(\"sendir,1:1,0,37000,1,1,4,552,4,1397,9,1717,164,162,19,63,19,22,19,62,19,62,19,22,18,22,18,63,19,22,20,20,18,63,18,22,18,22,19,62,18,63,19,22,19,62,20,20,18,22,19,62,18,63,18,63,18,63,19,61,20,62,20,61,18,63,19,22,19,22,19,22,19,22,18,22,19,22,20,60,19,63,19,22,18,63,18,22,18,22,19,22,19,22,20,20,19,22,18,63,19,22,18,62,19,63,18,63,19,62,20,194,163,163,19,62,18,22,19,62,19,62,19,22,18,22,19,62,18,22,20,20,18,63,19,22,19,22,19,62,18,63,19,22,19,62,20,20,19,22,19,62,18,63,18,63,19,62,18,63,19,62,20,61,18,63,18,22,18,22,19,22,18,22,19,22,18,22,20,61,19,62,19,22,18,63,19,22,19,22,18,22,19,22,20,20,19,22,18,63,18,22,19,62,18,62,20,62,19,62,19,37000x0D0x0A\",true)\nend\n\nfunction QuickApp:button27Released(event)\nself:send(\"sendir,1:1,0,37000,1,1,162,164,19,62,19,22,19,62,19,62,19,22,19,22,18,63,19,22,20,20,18,63,19,22,18,22,19,62,18,63,19,22,18,63,20,20,18,22,19,62,19,62,18,62,19,62,19,62,18,63,20,60,20,62,19,22,19,22,19,22,18,22,19,22,19,22,20,61,19,22,19,22,19,62,19,22,19,22,19,22,18,22,20,20,18,63,18,63,19,22,18,63,18,63,18,63,19,62,20,194,163,163,19,62,19,22,19,62,18,63,19,22,19,22,18,63,18,22,20,20,19,62,19,22,19,22,19,62,18,63,19,22,19,62,20,20,19,22,18,63,19,62,18,63,18,63,19,62,19,62,20,61,18,63,19,22,18,22,18,22,19,22,19,22,19,22,20,61,19,22,18,22,19,62,18,22,19,22,19,22,19,22,20,20,18,63,19,62,18,22,19,62,18,63,19,61,19,63,19,37000x0D0x0A\",true)\nend\n\nfunction QuickApp:button28Released(event)\nself:send(\"sendir,1:1,0,37000,1,1,162,164,18,63,18,22,19,62,18,63,18,22,19,21,19,63,18,22,20,20,18,63,19,22,18,22,18,63,19,62,18,22,18,63,20,20,18,22,19,62,19,62,18,63,18,63,18,63,18,63,20,61,19,62,19,22,19,22,19,22,18,22,19,22,18,22,20,61,18,22,18,22,19,22,18,22,19,22,19,22,19,22,20,20,18,63,19,62,19,62,18,63,18,63,18,63,18,63,20,194,163,162,18,63,19,22,18,63,19,62,18,22,18,22,19,62,18,22,20,20,18,63,18,22,18,22,19,62,18,63,19,22,19,62,20,20,18,22,18,63,18,63,19,62,19,62,18,63,18,63,20,61,19,62,19,22,18,22,18,22,18,22,18,22,19,22,20,61,19,22,18,22,19,22,18,22,18,22,19,22,19,22,20,20,18,63,19,62,19,62,18,63,19,62,18,63,19,62,19,37000x0D0x0A\",true)\nend\n\nfunction QuickApp:button29Released(event)\nself:send(\"sendir,1:1,0,37000,1,1,7,1487,164,163,18,63,18,22,18,63,19,62,18,22,19,22,18,63,18,22,20,20,18,63,18,22,18,22,19,62,19,62,18,22,18,63,20,20,18,22,19,62,18,63,19,62,18,63,18,63,18,63,20,61,18,63,19,22,18,22,18,22,18,22,18,22,18,22,20,61,18,22,18,63,19,22,18,22,18,22,19,22,18,22,20,20,18,63,18,22,19,62,19,62,18,63,19,62,18,62,21,194,163,162,18,63,19,22,19,61,19,63,18,22,18,22,19,62,18,22,20,20,18,63,18,22,19,22,18,63,18,62,19,22,18,63,20,20,18,22,18,63,18,63,18,63,18,63,19,62,18,63,20,61,18,63,19,22,18,22,18,22,18,22,19,22,19,22,20,61,18,22,19,62,18,22,19,22,18,22,18,22,18,22,20,20,18,63,18,22,19,62,19,62,18,63,18,63,19,62,18,37000x0D0x0A\",true)\nend\n\nfunction QuickApp:button30Released(event)\nself:send(\"sendir,1:1,0,37000,1,1,4,591,8,1071,164,163,19,62,19,22,19,62,19,62,19,22,19,22,19,62,19,22,20,20,19,61,19,22,19,22,19,62,19,62,19,22,19,62,20,20,19,22,19,62,19,62,19,62,19,62,19,62,19,62,20,61,19,62,19,22,19,22,19,22,19,22,19,22,19,22,20,61,19,22,19,62,19,62,19,22,19,22,19,22,19,22,20,20,19,62,19,22,19,22,19,62,19,62,19,62,19,62,20,194,163,163,19,62,19,22,19,62,19,62,19,22,19,22,19,62,19,22,20,20,19,62,19,22,19,22,19,62,19,62,19,22,19,62,20,20,19,22,19,62,18,63,19,62,19,62,19,61,20,62,20,61,19,62,19,22,19,22,19,22,19,22,19,22,19,22,20,61,19,22,19,62,19,62,19,22,19,22,19,22,19,22,20,20,19,62,19,22,19,22,19,62,19,62,19,62,19,62,19,3700\",true)\nend"}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment