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

build a simple array and save to global variable


Question

Posted

I am trying to build a simple array, with a list of device id's and then save it to a globalvariable and then fetch this variable to switch on / off as a group?

so afr i have managed to get this to work.

local tb = {}

    if CornerVariable == "true" then

        tb[#tb+1]={name=firstToUpper(CornerVariableName),id=ShabbosLightCorner}

    end

    if DovidVariable == "true" then

        tb[#tb+1]={name=firstToUpper(DovidVariableName),id=ShabbosLightDovid}

    end

    if RifkaVariable == "true" then

        tb[#tb+1]={name=firstToUpper(RifkaVariableName),id=ShabbosLightRifka}

    end 

    if ShanaVariable == "true" then

        tb[#tb+1]={name=firstToUpper(ShanaVariableName),id=ShabbosLightShana}

    end

    setGroupVariable = tb

    fibaro.setGlobalVariable(GroupVariableName, json.encode(setGroupVariable))

 

the problem i am having is when i try to fetch the variable i am struggling to control them as they are coming back as a table correctly so, but when i then run this code it does not work.

 

function TurnOffLights(GroupName)

    for k,i in ipairs(GroupName) do

        if fibaro.getValue(i, "state") == true then

            fibaro.call(i, "turnOff")

        end

    end

end

 

been knocking my head trying to get this working and am climbing the walls LOL from frustration, any help would be gratefully recieved.

 

 

thank you

3 answers to this question

Recommended Posts

  • 0
Posted

If your table looks like

Please login or register to see this code.

then you loop like

Please login or register to see this code.

 

  • Like 1
  • 0
  • Inquirer
  • Posted

    @jgab that is correct but as i am using a runction which assums that i am passing it an array, i need to pass it as an array rather then call it on each iteration, i got around it by changing my array to just have the numbers in them and this way i can use it as a group to be able to use my functions.  thank you for your contribution and help as your past help with arrays helped me get there.

    • 0
    Posted

    Why do  you need to pass it as an array instead of individual calls?

    Is it a fibaro.call(<array>,<action>) call you want to do with multiple deviceIDs?

    Unfortunately, the fibaro.call using an array of deviceIDs just loops over the array and calls the  api for each device. There is no magic api call that takes a list of device IDs... so you may as well loop and call them individually...

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