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

Increase/Decrease light value - Virtual Button - LUA?


Question

Posted

Hi,

I want to use a vitual device with two buttons, one button to Increase a specific light value and one button for decrease. Lets say it shall change 5% of the value for each button press.

I was hoping someone with a little knowledge on lua programming could point me in the right direction.

Thank you in advance.

8 answers to this question

Recommended Posts

  • 0
Posted

With my limited knowledge, my concept would be the following (currently @work, so I don't have much time to explain it in detail now):

Create a global variable "Light_value".

In the button-LUA getglobal "Light_value", store that value as a new local variable "New_value" and increase or decrease it by 5 and write the new variable to "Light_value". This code is run everytime you press the button.

Then in the main lua code for that virtual device, call "Light_value" and compare it with the current value, if it deviates, call the "setvalue" for that light. Since the main code will be executed every 3s, it will be changed automatically.

Sorry I can't do it more detailed for now, but this should give you an idea and hopefully get you on your way.

  • 0
  • Inquirer
  • Posted
    With my limited knowledge, my concept would be the following (currently @work, so I don't have much time to explain it in detail now):

    Create a global variable "Light_value".

    In the button-LUA getglobal "Light_value", store that value as a new local variable "New_value" and increase or decrease it by 5 and write the new variable to "Light_value". This code is run everytime you press the button.

    Then in the main lua code for that virtual device, call "Light_value" and compare it with the current value, if it deviates, call the "setvalue" for that light. Since the main code will be executed every 3s, it will be changed automatically.

    Sorry I can't do it more detailed for now, but this should give you an idea and hopefully get you on your way.

    Thank you for your help. Im at work too but will test when I get home. But if you can provide some code for me I would be really gratefull. Im not familiar with LUA at all.

    Thanks again.

    • 0
    Posted

    In the variables panel, make a new global variable with the name of your choosing. In this example I've used "Light_value". Add a label and 2 buttons, make sure that you keep the name of the label according to the script below (Label1) or adjust it accordingly.

    For the - button and label do the following:

    Please login or register to see this code.

    Same goes for the + button, but the - in the script above should then of course be changed into +.

    And the main code should be:

    Please login or register to see this code.

    Haven't tested it, so it could be that I've made a slight mistake in there somewhere, but I think this should do the job. Let me know if you have any questions.

    • 0
    Posted
    Hi,

    I want to use a vitual device with two buttons, one button to Increase a specific light value and one button for decrease. Lets say it shall change 5% of the value for each button press.

    I was hoping someone with a little knowledge on lua programming could point me in the right direction.

    Thank you in advance.

    you can do this with a slider if you want or you really prefer two buttons ?

    • 0
  • Inquirer
  • Posted

    Thank you all. I tried the code yesterday but Im not sure if I implement it correctly. It looks like the main code only turn of the lights. As it sense the global variable value which is 0 and turn of the lights. any idea? I was a little confused by all the different ID`s in your code, whenever ID is mentioned it shall only be the dimmer ID or?

    I thought it could be done alot easier. That it just get the current light value as local variable and then use it to set set the "new" light value to +5 or -5. Without the use of main code etc.

    But anyway if you can test your code and see if it works I would be gratefull.

    I dont need the slider option, only a two button virtual device which set the specfic light to + or - 5% of the current light value.

    • 0
    Posted

    In the code there is a little problem with this line -> local light_new = light_lowered - "5", the type of the variable light_lowered is number, you must do : local light_new = light_lowered - 5;

    • 0
    Posted

    But with a slider it would become a normal dimmer again, there's no fun in that.

    Please login or register to see this image.

    /emoticons/default_wink.png" alt=";)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    I've looked at how to use the slider, but didn't figure it out yet. How could one use it in the example above?

    • 0
  • Inquirer
  • Posted

    I managed to get it to work with a lot simpler code and without the need for Main loop. But thanks a lot for your help. I would have not been able to create it without the code you provided.

    See code below (- button):

    Please login or register to see this code.

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