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

How does this: DeviceID = {10, 12, 24} work?


Question

Guest jschun
Posted

Does anybody have a short and sweet example how to use the {xx, xx, xx} in LUA?

I want to arm multiple DoorSensors, but I don't want to do it like:

Please login or register to see this code.

But I want to do it like:

Please login or register to see this code.

But I do not know the exact syntax to get all three sensors to be armed

Please login or register to see this image.

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

Can anyone help please?

Thanks!!

8 answers to this question

Recommended Posts

  • 0
Posted

jschun,

DoorSensorID[1] give you the first value in the table... [2] the second ...

Regards

  • 0
Guest jschun
  • Inquirer
  • Posted

    Thank you for your quick and clear response Krikroff!

    • 0
    Posted

    two loops possible i is index v is value in table element

    Please login or register to see this code.

    Please login or register to see this code.

    • 0
    Guest jschun
  • Inquirer
  • Posted

    Thanks RobMac! I used the first example in my scripts and it works like a charm! ッ

    I'm not quite sure what to do with the index / value example though. Can you explain a bit more on that?

    Thanks in advance ッ

    • 0
    Posted
    Thanks RobMac! I used the first example in my scripts and it works like a charm! ッ

    I'm not quite sure what to do with the index / value example though. Can you explain a bit more on that?

    Thanks in advance ッ

    The enumerator is just a nice way to get the integer index and the table value in variables to use within a loop rather than creating a counter.

    Also you can index with a string and that is nice as you can use notify function with the device name or just debug without having to look up the device... notice pairs not ipairs when you use string index

    as you can store tables in tables the second part of the code is possible and then you have room and device.

    you could of course get the strings from calls to functions in the first place in the table declaration rather then using strings like "Drawing" (if fibaro API had function)

    Please login or register to see this code.

    you can also store actual functions in tables so lots of uses but I will leave that for another post

    • 0
    Posted

    robmac,

    Thanks a lot for your programming tips in LUA. I like the following piece, however wonder why the results are in such a strange sequence?

    local devices = { ["main"] = 184,

                      ["side"] = 185,

                      ["other"] = 186 }

    for i,v in pairs(devices ) do

     

              fibaro:debug(i)

              fibaro:debug(v)

     end

    results:

    Please login or register to see this code.

    • 0
    Posted

    richo, pairs(table) allow iteration but the order that items are returned is not defined. You must use ipairs, with ipairs(table) the order in which elements are returned is guaranteed to be in the numeric order of the indices, but non-integer keys are simply skipped (your example certainly does not work).

    if robmac wants complete

    Please login or register to see this image.

    /emoticons/default_icon_biggrin.gif" alt=":-D" /> (thank to him for his good advice)

    • 0
    Posted

    from the luascheduler... see the table.sort that makes sure that the catchup events are played in the correct sequence by time

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