Created
January 25, 2022 11:45
-
-
Save sameeraakbar/abd140070a3ff0b2e40c874dcf5f5ea7 to your computer and use it in GitHub Desktop.
Memory QuickApp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"name":"Memory QuickAPP","type":"com.fibaro.genericDevice","apiVersion":"1.2","initialProperties":{"viewLayout":{"$jason":{"body":{"header":{"style":{"height":"0"},"title":"quickApp_device_51"},"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"}]}},"head":{"title":"quickApp_device_51"}}},"uiCallbacks":[{"callback":"turnOnActive","eventType":"onReleased","name":"button2_1"},{"callback":"turnOffActive","eventType":"onReleased","name":"button2"}],"quickAppVariables":[{"name":"activedevice","value":"37,38"},{"name":"livingalldevice","value":"37,38"}],"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/\n\nfunction QuickApp:onInit()\n self:debug(\"onInit\")\nend\nfunction string:split( inSplitPattern, outResults )\n if not outResults then\n outResults = { }\n end\n local theStart = 1\n local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )\n while theSplitStart do\n table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )\n theStart = theSplitEnd + 1\n theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )\n end\n table.insert( outResults, string.sub( self, theStart ) )\n return outResults\nend\nfunction QuickApp:turnOnActive()\n--local myString = \"\" IDs of devices that were active when the room was switched off\nlocal myString = self:getVariable(\"activedevice\")\nself:debug(\"this is my string \"..myString)\nif ((myString ~= \"\") ) then -- or (myString != null)\nlocal myTable = myString:split(\",\")\nfor i = 1, #myTable do\n fibaro.call(tonumber(myTable[i]), \"turnOn\")\n self:debug( myTable[i] ) -- This will give your needed output\nend\nend\n\nend\nfunction QuickApp:turnOffActive()\nlocal myString = self:getVariable(\"livingalldevice\")\nself:debug(\"this is my string \"..myString)\nlocal myTable = myString:split(\",\")\nself:setVariable(\"activedevice\",\"\") --- resetting the activeDevice \nlocal tempactive = \"\"\nfor i = 1, #myTable do\n local devicevalue = (fibaro.get(tonumber(myTable[i]), \"value\"))\n --self:debug(value)\n if (devicevalue) then -- if light is ON, turn it off , else do nothing\n self:debug(\"aye\")\n fibaro.call(tonumber(myTable[i]), \"turnOff\")\n tempactive = tempactive..myTable[i]..\",\"\n \n end\n\n --fibaro.call(tonumber(myTable[i]), \"turnOn\")\n --self:debug( myTable[i] ) -- This will give your needed output\nend\nif ((tempactive ~= \"\") )then\n--tempactive = string.sub(tempactive,1,-3)\ntempactive = tempactive:sub(1, -2)\nself:debug(tempactive)\nend\nself:setVariable(\"activedevice\", tempactive) -- set the activedevice variable with the list \n --bar:sub(1, -5)--strip extra comma\nend\n"}]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment