{"name":"Кондиционер","type":"com.fibaro.binarySwitch","apiVersion":"1.2","initialProperties":{"viewLayout":{"$jason":{"body":{"header":{"style":{"height":"0"},"title":"quickApp_device_93"},"sections":{"items":[{"components":[{"name":"mode","style":{"weight":"1.2"},"text":"Режим","type":"label"},{"style":{"weight":"0.5"},"type":"space"}],"style":{"weight":"1.2"},"type":"vertical"},{"components":[{"components":[{"name":"buttonOff","style":{"weight":"0.25"},"text":"ВЫКЛ","type":"button"},{"name":"buttonCool","style":{"weight":"0.25"},"text":"ОХЛ","type":"button"},{"name":"buttonHeat","style":{"weight":"0.25"},"text":"НАГР","type":"button"},{"name":"buttonFan","style":{"weight":"0.25"},"text":"ВЕНТ","type":"button"}],"style":{"weight":"1.2"},"type":"horizontal"},{"style":{"weight":"0.5"},"type":"space"}],"style":{"weight":"1.2"},"type":"vertical"},{"components":[{"name":"temp","style":{"weight":"1.2"},"text":"Температура","type":"label"},{"style":{"weight":"0.5"},"type":"space"}],"style":{"weight":"1.2"},"type":"vertical"},{"components":[{"max":"100","min":"0","name":"slider","style":{"weight":"1.2"},"text":"","type":"slider"},{"style":{"weight":"0.5"},"type":"space"}],"style":{"weight":"1.2"},"type":"vertical"},{"components":[{"name":"speed","style":{"weight":"1.2"},"text":"Скорость вентилятора","type":"label"},{"style":{"weight":"0.5"},"type":"space"}],"style":{"weight":"1.2"},"type":"vertical"},{"components":[{"components":[{"name":"buttonSpeedAuto","style":{"weight":"0.25"},"text":"АВТО","type":"button"},{"name":"buttonSpeedMin","style":{"weight":"0.25"},"text":"МИН","type":"button"},{"name":"buttonSpeedMed","style":{"weight":"0.25"},"text":"СРЕД","type":"button"},{"name":"buttonSpeedMax","style":{"weight":"0.25"},"text":"ВЫС","type":"button"}],"style":{"weight":"1.2"},"type":"horizontal"},{"style":{"weight":"0.5"},"type":"space"}],"style":{"weight":"1.2"},"type":"vertical"},{"components":[{"name":"swing","style":{"weight":"1.2"},"text":"Угол поворота ламелей","type":"label"},{"style":{"weight":"0.5"},"type":"space"}],"style":{"weight":"1.2"},"type":"vertical"},{"components":[{"components":[{"name":"buttonSwingAuto","style":{"weight":"0.20"},"text":"АВТ","type":"button"},{"name":"buttonSwingMin","style":{"weight":"0.20"},"text":"МИН","type":"button"},{"name":"buttonSwingMed","style":{"weight":"0.20"},"text":"СРЕД","type":"button"},{"name":"buttonSwingMax","style":{"weight":"0.20"},"text":"ВЫС","type":"button"},{"name":"buttonSwingOff","style":{"weight":"0.20"},"text":"ВЫК","type":"button"}],"style":{"weight":"1.2"},"type":"horizontal"},{"style":{"weight":"0.5"},"type":"space"}],"style":{"weight":"1.2"},"type":"vertical"}]}},"head":{"title":"quickApp_device_93"}}},"uiCallbacks":[{"callback":"setMode","eventType":"onReleased","name":"buttonOff"},{"callback":"setMode","eventType":"onReleased","name":"buttonCool"},{"callback":"setMode","eventType":"onReleased","name":"buttonHeat"},{"callback":"setMode","eventType":"onReleased","name":"buttonFan"},{"callback":"onTempChanged","eventType":"onChanged","name":"slider"},{"callback":"setSpeed","eventType":"onReleased","name":"buttonSpeedAuto"},{"callback":"setSpeed","eventType":"onReleased","name":"buttonSpeedMin"},{"callback":"setSpeed","eventType":"onReleased","name":"buttonSpeedMed"},{"callback":"setSpeed","eventType":"onReleased","name":"buttonSpeedMax"},{"callback":"setSwing","eventType":"onReleased","name":"buttonSwingAuto"},{"callback":"setSwing","eventType":"onReleased","name":"buttonSwingMin"},{"callback":"setSwing","eventType":"onReleased","name":"buttonSwingMed"},{"callback":"setSwing","eventType":"onReleased","name":"buttonSwingMax"},{"callback":"setSwing","eventType":"onReleased","name":"buttonSwingOff"}],"quickAppVariables":[{"name":"login","value":"admin"},{"name":"pass","value":"W1u98)^h"},{"name":"ip","value":"192.168.88.201"},{"name":"port","value":"80"},{"name":"model","value":"1"},{"name":"vendor","value":"MITSUBISHI_HEAVY_88"}],"typeTemplateInitialized":true},"files":[{"name":"main","isMain":true,"isOpen":true,"content":"-- Binary switch type should handle actions turnOn, turnOff\n-- To update binary switch state, update property \"value\" with boolean\n\nfunction QuickApp:turnOn()\n self.mode = \"heat\";\n self:loadParams();\n self:updateProperty(\"value\", true);\nend\n\nfunction QuickApp:turnOff()\n self.mode = \"off\";\n self:loadParams();\n self:updateProperty(\"value\", false); \nend\n\n-- To update controls you can use method self:updateView(, , ). 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/\n\nfunction QuickApp:onInit()\n self:debug(\"onInit\");\n\n self.http = net.HTTPClient({timeout=3000});\n\n self.ip = self:getVariable(\"ip\");\n self.port = self:getVariable(\"port\");\n self.login = self:getVariable(\"login\");\n self.pass = self:getVariable(\"pass\");\n self.model = self:getVariable(\"model\");\n self.vendor = self:getVariable(\"vendor\");\n\n self.mode = \"off\";\n self.temp = 22;\n self.speed = \"auto\";\n self.swing = \"auto\";\n\n --self:loadParams();\nend\n\nfunction QuickApp:setMode(param)\n if(param.elementName == \"buttonOff\") then self.mode = \"off\" end\n if(param.elementName == \"buttonCool\") then self.mode = \"cool\" end\n if(param.elementName == \"buttonHeat\") then self.mode = \"heat\" end\n if(param.elementName == \"buttonFan\") then self.mode = \"fan\" end\n self:loadParams();\nend\n\nfunction QuickApp:setSpeed(param)\n if(param.elementName == \"buttonSpeedAuto\") then self.speed = \"auto\" end\n if(param.elementName == \"buttonSpeedMin\") then self.speed = \"low\" end\n if(param.elementName == \"buttonSpeedMed\") then self.speed = \"med\" end\n if(param.elementName == \"buttonSpeedMax\") then self.speed = \"max\" end\n self:loadParams();\nend\n\nfunction QuickApp:setSwing(param)\n if(param.elementName == \"buttonSwingAuto\") then self.swing = \"auto\" end\n if(param.elementName == \"buttonSwingMin\") then self.swing = \"lowest\" end\n if(param.elementName == \"buttonSwingMed\") then self.swing = \"middle\" end\n if(param.elementName == \"buttonSwingMax\") then self.swing = \"high\" end\n if(param.elementName == \"buttonSwingOff\") then self.swing = \"off\" end\n self:loadParams();\nend\n\nfunction QuickApp:onTempChanged(event)\n local value = event.values[1];\n if(value > 30) then value = 30; end;\n self.temp = value;\n self:loadParams();\nend\n\nfunction QuickApp:loadParams()\n self:debug(\"Mode: \" .. self.mode);\n self:debug(\"Temp: \" .. self.temp);\n self:debug(\"Speed: \" .. self.speed);\n self:debug(\"Swing: \" .. self.swing);\n\n local params\t= {};\n params.Vendor\t= self.vendor;\n params.Model\t= self.model;\n params.Temp\t\t= self.temp;\n\n self:updateView(\"temp\", \"text\", \"Температура: \" .. self.temp .. \"C\");\n\n if (self.mode == \"off\")\n then\n params.Power = \"off\";\n params.Mode = \"off\";\n self:updateView(\"mode\", \"text\", \"Выключено\");\n self:updateProperty('value', false);\n elseif (self.mode == \"cool\")\n then\n params.Power = \"on\";\n params.Mode = \"cool\";\n self:updateView(\"mode\", \"text\", \"Охлаждение\");\n self:updateProperty('value', true);\n elseif (self.mode == \"heat\")\n then\n params.Power = \"on\";\n params.Mode = \"heat\";\n self:updateView(\"mode\", \"text\", \"Нагрев\");\n self:updateProperty('value', true);\n elseif (self.mode == \"fan\")\n then\n params.Power = \"on\";\n params.Mode = \"fan\";\n self:updateView(\"mode\", \"text\", \"Вентиляция\");\n self:updateProperty('value', true);\n end\n\n if (self.speed == \"auto\")\n then\n params.FanSpeed = \"auto\";\n self:updateView(\"speed\", \"text\", \"Скорость авто\");\n elseif (self.speed == \"low\")\n then\n params.FanSpeed = \"LOW\";\n self:updateView(\"speed\", \"text\", \"Скорость минимальная\");\n elseif (self.speed == \"med\")\n then\n params.FanSpeed = \"MED\";\n self:updateView(\"speed\", \"text\", \"Скорость средняя\");\n elseif (self.speed == \"max\")\n then\n params.FanSpeed = \"MAX\";\n self:updateView(\"speed\", \"text\", \"Скорость максимальная\");\n end\n\n if (self.swing == \"auto\")\n then\n params.SwingV = \"auto\";\n self:updateView(\"swing\", \"text\", \"Ламели авто\");\n elseif (self.swing == \"lowest\")\n then\n params.SwingV = \"lowest\";\n self:updateView(\"swing\", \"text\", \"Ламели вниз\");\n elseif (self.swing == \"middle\")\n then\n params.SwingV = \"middle\";\n self:updateView(\"swing\", \"text\", \"Ламели середина\");\n elseif (self.swing == \"high\")\n then\n params.SwingV = \"highest\";\n self:updateView(\"swing\", \"text\", \"Ламели вверх\");\n elseif (self.swing == \"off\")\n then\n params.SwingV = \"off\";\n self:updateView(\"swing\", \"text\", \"Ламели отключены\");\n end\n\n local s\t\t\t= json.encode(params);\n local address = \"http://\" .. self.ip .. \":\" .. self.port .. \"/cm?user=\" .. self.login .. \"&password=\" .. self.pass .. \"&cmnd=irhvac%20\" .. s;\n self:debug(address);\n\n self.http:request(address, {\n options={\n headers = { Accept = \"application/json\"},\n method = 'GET'\n },\n success = function(response)\n --fibaro:debug(response);\n end,\n error = function(error)\n --fibaro:debug(error);\n end\n }) \n \nend"}]}