martin7462 Posté(e) le 15 avril 2022 Signaler Posté(e) le 15 avril 2022 Someone can't help. I'm trying to change my simple VD to QA in HC3 where the countdown starts for a defined time. The countdown works. In HC2 it worked in HC3 I can't set it. But: I can't stop it with another button during the countdown. How to interrupt, stop the countdown in HC3 LUA? Can't you help with LUA adjustment? I was trying it in the lines 12-15 but doesnot work. I can interrupt the function during startup. QA in Attachment. Thanks. LUA: function QuickApp:onInit() timer2 = self:getVariable("timer2") timer = tonumber(self:getVariable("timer")) self.counter = timer*10 if timer == -1 then self:debug("SET TIME") self:updateView("label1", "text", "SET TIME") end while self.counter > 0 do if self:getVariable("timer") == "-1" then self:debug("STOP") self:updateView("label1", "text", "STOP") break else self:updateView("label1", "text", "START") self.counter = self.counter -1; self:debug(self.counter) hub.sleep(1000) self:updateView("label2", "text", "remaining time: " ..self.counter) end end if self.counter ==0 then self:setVariable("timer", "-1") self:updateView("label", "text", "SET TIME: 0s") self:updateView("label1", "text", "STOP") self:updateView("label2", "text", " remaining times: 0 s") end self:debug("QuickApp:onInit") end -- set 10s function QuickApp:Button10s() self:setVariable("timer", "1") self:updateView("label", "text", " SET: 10s") self:updateView("label1", "text", "Waiting") end -- button STOP function QuickApp:STOP() self:setVariable("timer2", "-1") self:updateView("label5", "text", "SET TIME: 0s") self:updateView("label4", "text", "STOPPED") end Counter (5).fqa
Lazer Posté(e) le 15 avril 2022 Signaler Posté(e) le 15 avril 2022 Sorry I don't have time to understand and rewrite your QuickApp, so I just give you a quick tip : you have to use fibaro.setTimeout() and forget the traditional linear way of programming in HC2's virtual devices, as HC3's QuickApps are now running in an asynchronous way. There are a few examples of proper ways to code a loop on this forum, you can search for the given function as a keyword.
martin7462 Posté(e) le 17 avril 2022 Auteur Signaler Posté(e) le 17 avril 2022 Le 15. 4. 2022 à 21:23, Lazer a dit : Prepáčte, nemám čas pochopiť a prepísať vašu aplikáciu QuickApp, takže vám dám len rýchly tip: musíte použiť fibaro.setTimeout() a zabudnite na tradičný lineárny spôsob programovania vo virtuálnych zariadeniach HC2, pretože rýchle aplikácie HC3 teraz bežia asynchrónnym spôsobom. Na tomto fóre je niekoľko príkladov správnych spôsobov kódovania slučky, danú funkciu môžete vyhľadať ako kľúčové slovo. thank you but i'm not a programmer so i guess I can't do it alone.
Messages recommandés