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


How to create a countdown timer on button face (maybe with Jgab's extra)


Neo Andersson

Recommended Posts

I am trying to update a button face of a QA every second for a certain given time.

I have tried it by using JGab's Fibaro extra's functions or just with simple settimeout but couldn't find a proper solution.

 

Question for Jgab:

Can't we somehow utilize Fibaroextra's Sequence function waiting part ? ex:

Please login or register to see this code.

 

While the  60s is passing, let's every 1 sec update another button's label - self:updateView ("btn_1", "text", "running for "..x.." sec)

 

Or what can be the proper way to achieve this?

 

 

Thanks

Edited by Neo Andersson
Link to comment
Share on other sites

Well, sometimes it can be an issue with the updateView refreshing the UI.

The sequence could be used but it's not necessary - as the real issue is to update the label every second.


 

Please login or register to see this code.

 

and then call it like below. This way you could also  start multiple updates of different buttons in parallell...

Please login or register to see this code.

 

Edited by jgab
Link to comment
Share on other sites

  • Topic Author
  • Thanks, but i can't see where you define btn object?

    btn.ref, btn.counter,btn.lbl and btn.fmt are created just by using them?

    btn object doesn't need to be defined separately? In your example btn is an object containing properties ref,lbl,counter and fmt.

    then when you call the sequence you just define an object btn1 with only two properties lbl and fmt ?

    Link to comment
    Share on other sites

    Please login or register to see this code.

    and it's important to define it once as both startButtonUpdate and stopButtonUpdate needs the same btn reference (counter and ref is stored there)

    Link to comment
    Share on other sites

  • Topic Author
  • sorry for my bothering, but i still can't get, where you define forexample the btn.ref property?

    it is used just inside the startUpdateButton function, so it will be lost outside of the function, am i right?

    so when you refer to it in local stopUpdateButton(btn) if btn.ref then clearTimeout(btn.ref); btn.ref=nil end end then it is not storing any value, cause it is a local variable of startUpdateButton 

    function.

    Sorry, i must be really annoying..my wife is probably right :-)

    Link to comment
    Share on other sites

    Why do you change it to 'btn_start' and 'btn_stop' ?

    Please login or register to see this code.

    it should be

    Please login or register to see this code.

    that is declared on the previous line. Needs to be the same btn. Lua tables are passed by reference so stopUpdateButton and stopUpdateButton will get the same table and it's used to pass common values like .ref 

     

    Link to comment
    Share on other sites

  • Topic Author
  • okay, i changed it back, but the code still needs some brackets..I dont know what you meant by this part:

    Please login or register to see this code.

    i mean, local loop() is supposed to be a function definition (and you just missed the function keyword) inside another function or it was supposed to be a variable definition??

    i am totally confused

    Please login or register to see this attachment.

    Edited by Neo Andersson
    Link to comment
    Share on other sites

    1 hour ago, Neo Andersson said:

    okay, i changed it back, but the code still needs some brackets..I dont know what you meant by this part:

    Please login or register to see this code.

    i mean, local loop() is supposed to be a function definition (and you just missed the function keyword) inside another function or it was supposed to be a variable definition??

    i am totally confused

     

     

    Sorry, you are right.

    It should be

    Please login or register to see this code.

     

    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
    Reply to this topic...

    ×   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...