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

loop through table


Jay Ess

Question

I have a variable with the following:

light{253,508,470}

curtains{250,80,36}

 

at the moment i have a script which controls the lights dependent on variables

 

how can i loop through the above table to get each light value and the corresponding curtain value?

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0
  • Inquirer
  • in my script i would like to have the list of the lights in a local variable so that i can switch them on or off

    when i have a simple table with just the device numbers,

    i did

    local GroupOnEndSecondGroup = json.decode(fibaro.getGlobalVariable("shabbosLightGroup"))
    which would give me the device list, however as my table has changed how do i list the lights in to a local?

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I am having problems in making the table too 

    table.insert(tb,sld)
    just gives me a table with out any key value
    how do i make a table to reflect the above?
    {light{12,32},{c{523,532}}
    which would then allow me to iterate through the table to get the corresponding values?
    Link to comment
    Share on other sites

    • 0

    I dont reall understand your problem..

    What Eddy wrote, is the way you loop through a table..

    To find the coresponding value in curtain table, just use the key of Light table, while you looping

    Please login or register to see this code.

     

    On 9/4/2022 at 12:18 PM, Jay Ess said:

    I am having problems in making the table too 

    table.insert(tb,sld)
    just gives me a table with out any key value
    how do i make a table to reflect the above?
    {light{12,32},{c{523,532}}
    which would then allow me to iterate through the table to get the corresponding values?

    or if you want to have everything in one variable, than use the same principle just check odd and even values...like use table {12,523,32,532} and every ODD number will be light, and every EVEN number will be curtain..this is what just came to me as the easiest way..

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