Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

How to start a simple timer with VD on and off


Seraphim

Question

Good evening Community,

 

a beginner question again: How do I start a timer when a VD is turned on and stop/restart it when the VD is turned off?

 

I have created this script:

function QuickApp:turnOn()
    self:debug("binary switch turned on")
    self:updateProperty("value"true)
    self:setVariable("IsRunning""1")
    self:setVariable("Actual"self:getVariable("Time(s)"))
 
    self:updateView("label1""text"'Countdown for ' .. self:getVariable("Time(s)") .. ' seconds'
    self:updateView("label2""text"'Timer gestartet: ' .. self:getVariable("IsRunning")) 
    self:updateView("label3""text"'Countdown: ' .. self:getVariable("Actual"))
 
    local Timer = self:getVariable("Actual")
    while Timer ~= -1 do 
            Timer=Timer-1
            self:setVariable("Actual", Timer)
            fibaro.sleep(1000)
            self:updateView("label3""text"'Countdown: ' .. self:getVariable("Actual"))
    end
end
 
function QuickApp:turnOff()
    self:debug("binary switch turned off")
    self:updateProperty("value"false
    self:setVariable("IsRunning""0")   
 
    self:updateView("label1""text"'Countdown for ' .. self:getVariable("Time(s)") .. ' seconds'
    self:updateView("label2""text"'Timer gestartet: ' .. self:getVariable("IsRunning")) 
 
    self:setVariable("Actual""-1")
 
    self:updateView("label3""text"self:getVariable("Actual"))  
end

 

Well, the problem seems to be the while loop (also tried it with a for loop), Turning the VD off is only done after the while loop stopped. Turning the VD off is not stopping the while loop. How to do something like this?

 

Regards

Andreas

 

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0
1 hour ago, Seraphim said:

Well, the problem seems to be the while loop (also tried it with a for loop), Turning the VD off is only done after the while loop stopped. Turning the VD off is not stopping the while loop. How to do something like this?

 

Regards

Andreas

This is my timer -

Please login or register to see this attachment.

turn it on/off by pressing the "binary switch" button

 

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Dear jgab,

     

    Thank you very much for your support, once more. Your Script works really great, there is only one thing left:

     

    How to react on a defined counter?

     

    I tried:

    if timer == "10" then
        self:debug("Do something")
        self:turnOff()
        time = 0
        update(self)
    end

     

    But nothing happens after 10 seconds.

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Just found the solution it's not about the If code, it was about the position within the whole script.

    • Like 1
    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...