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

Lua code for press button of Virtual device


Question

Posted

Hello!

I have Virtual device with id 83 and button with id btnToggle that toggling power state of virtual device.

I want with pressing button on device with id 107 toggling power state of virtual device.

Code:

Please login or register to see this code.

In debug I see 1 and 2, but Virtual device doesn`t change its power state.

Please login or register to see this attachment.

Please login or register to see this attachment.

8 answers to this question

Recommended Posts

  • 1
Posted

To press button of VD, you need to use the number of the button (not ID).

To find out the number, you just need to count all elements (buttons, labels,sliders) from upper left corner to the right and down.

Please login or register to see this spoiler.

 

For example if your button is number 2 then the command line is:

Please login or register to see this code.

  • 0
Posted

Giving IDs to buttons feels so useless while you can't use it in lua :(

No way to reorder buttons, add new ones etc. without rewriting all associated code :/

  • 0
Posted (edited)

Yes, you're absolutely correct....but this is the way it works

Edited by cag014
  • 0
Posted (edited)
9 hours ago, pogo said:

Giving IDs to buttons feels so useless while you can't use it in lua :(

No way to reorder buttons, add new ones etc. without rewriting all associated code :/

You could do something like this - a bit expensive but you don't have to rely on order of buttons.... ('api.get', so only for calling from scenes)

Please login or register to see this code.

 

Edited by jgab
  • 0
  • Inquirer
  • Posted
    14 hours ago, cag014 said:

    To press button of VD, you need to use the number of the button (not ID).

    To find out the number, you just need to count all elements (buttons, labels,sliders) from upper left corner to the right and down.

    Please login or register to see this spoiler.

    Thanks a lot! It`s working!

     

    Thanks to all.

    • 0
    Posted

    @jgab I know it and I can write a few more ways to do this, but I would need to copy this code to every scene and VD button/slider. I don't like it. 

    And, as you said, it's expensive... I used to work as game dev, so I hate expensive solutions.

    One day I will find the easy and fast way for this... but for now the Fibaro license agreement limits me with my actual ideas...

    • 0
    Posted
    1 minute ago, pogo said:

    @jgab I know it and I can write a few more ways to do this, but I would need to copy this code to every scene and VD button/slider. I don't like it. 

    And, as you said, it's expensive... I used to work as game dev, so I hate expensive solutions.

    One day I will find the easy and fast way for this... but for now the Fibaro license agreement limits me with my actual ideas...

    Can't copy it to VDs as it uses api.get - but I understand what you mean. 

    Well, what's expensive always depends. Almost all my scene are long running (

    Please login or register to see this link.

    ), and doing the mapping once when the scene starts up is negligible. Otherwise you could cache the id map by patching the scene code with the table (checking date if the VD been updated) - similar to this selfID hack that don't rely on __fibaroSceneId

    ...because the only thing we want to avoid is putting things in fibaro global variables ;)

     

    • 0
    Posted
    42 minutes ago, pogo said:

    @jgab I know it and I can write a few more ways to do this, but I would need to copy this code to every scene and VD button/slider. I don't like it. 

    No, you don't need to copy that....

    I'm doing the same with one scene, which scans and holds all VD buttons (and other stuff) as JSON table in one global variable.

    All other scene and VDs are using this global variable.... working fine, no issues so far

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