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


Question

Posted

Hello,
I wish to use a binary switch as a push button.
So when I press the switch becomes active (green) and after 5 seconds it automatically turns off again (red).
Can someone help me improve this code.

 

A universal binary switch with adjustable shutdown time would be a useful addition as a quickapp.

This code works, but without delay.

 

function QuickApp:turnOn()
    self:debug("binary switch turned on")
    self:updateProperty("value"true)
    print "hello" -- here some time delay code???
    hub.scene('execute', {[1] = 433, })
    self:debug("binary switch turned off")
    self:updateProperty("value"false)
end

 

Thanks.

9 answers to this question

Recommended Posts

  • 0
Posted

You could add some sleepytime

 

fibaro.sleep(30000)

  • Like 1
  • 0
Posted (edited)
1 hour ago, michelds said:

Hello,
I wish to use a binary switch as a push button.
So when I press the switch becomes active (green) and after 5 seconds it automatically turns off again (red).
Can someone help me improve this code.

 

A universal binary switch with adjustable shutdown time would be a useful addition as a quickapp.

This code works, but without delay.

 

function QuickApp:turnOn()
    self:debug("binary switch turned on")
    self:updateProperty("value"true)
    print "hello" -- here some time delay code???
    hub.scene('execute', {[1] = 433, })
    self:debug("binary switch turned off")
    self:updateProperty("value"false)
end

 

Thanks.

If i am not wrong, there are multiple options for this. I suppose you use HC3..

Option 1:

Most of the binary switches allow to set some Auto off functionality in parameteres. If you are using Fibaro double switch it is parameter 155 and 156 for outputs 1 and 2 respectivly. There you can set the Auto off time of the device. Meaning, that after a turn On situation, device waits the given seconds, then automatically turns off.

Please login or register to see this attachment.

Option 2:

Use settimeout in Turn on function.

Please login or register to see this code.

 

Edited by Neo Andersson
  • Like 1
  • 0
  • Inquirer
  • Posted

    Thank you for this info. I go try option 2.

    • 0
  • Inquirer
  • Posted

    This works: 


    function QuickApp:turnOn()
        self:debug("binary switch turned on")
        self:updateProperty("value", true)
     end

     

    function QuickApp:turnOff()
      hub.setTimeout(5000, function()
      self:turnOff()
      end)
        self:debug("binary switch turned off")
        self:updateProperty("value", false)
       
    end
     

    • 0
    Posted
    On 3/14/2023 at 4:32 PM, michelds said:

    This works: 


    function QuickApp:turnOn()
        self:debug("binary switch turned on")
        self:updateProperty("value", true)
     end

     

    function QuickApp:turnOff()
      hub.setTimeout(5000, function()
      self:turnOff()
      end)
        self:debug("binary switch turned off")
        self:updateProperty("value", false)
       
    end
     

    Just a little side note....lines self:debug("binary switch turned off") and self:updateProperty("value", false) should be placed inside the settimeout function like below.

     

    Please login or register to see this code.

     

     

    • Thanks 1
    • 0
  • Inquirer
  • Posted

    Hello,
    Thanks for the info. I've only recently started testing out Lua, and small scripts like this are always welcome.

    I still haven't understood the mechanism of quickapps, and the explanation on Fibaro's site is rather vague for a non-IT person.

    🙂

    • 0
    Posted (edited)
    18 hours ago, michelds said:

    I still haven't understood the mechanism of quickapps, and the explanation on Fibaro's site is rather vague for a non-IT person

    Try:

    Please login or register to see this link.

    ;)

    And if you want basic stuff explained please send me what in a PM. Maybe I'll write an article for it to help you and others. (or post your questions here on the forum).

    Edited by Joep
    • 0
  • Inquirer
  • Posted

    Bedankt Joep !!!

    • Like 1

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