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


Which LUA command to read values imported with api.get?


Alex V

Recommended Posts

I have used the api.get("/profiles/5") command to put data into a variable.

Now I can read out the first level, for example name, but not deeper. I want to be able to reach all the values of the climate zones.

 

Can someone explain to me how I can access these values and write them back in an appropriate way?

 

example code:

local MyVar1 = api.get("/profiles/5")

print (MyVar1.name)

 

The value which I read in MyVar1 see attachment (viewed with swagger)

 

Thank you in advance for your reactions

Please login or register to see this attachment.

Link to comment
Share on other sites

Hi @Alex V ,

 

Here is sample code:

Please login or register to see this code.

 

Hope this helps

 

Link to comment
Share on other sites

Hi @Sankotronic,
You're a very fast coder, but in this case you forgot to add 'do' in your for - next loop :-D

the code shoul'd read:

for z=1,#MyVar1.climateZones do

  print("Climate zone no "..d.." ID: "..MyVar1.climateZones[z].id)

  print("Mode: "..MyVar1.climateZones[z].mode)

  if MyVar1.climateZones[z].mode=="Manual" then

     print("Manual mode: "..MyVar1.climateZones[z].properties.handMode)

     print("Manual setpoint: "..MyVar1.climateZones[z].properties.handSetPointHeating)

  end

end

 

  • Thanks 2
Link to comment
Share on other sites

Today I have very little to do... :-)

 

Please login or register to see this code.

 

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

  • Topic Author
  • On 7/3/2021 at 2:21 PM, Bodyart said:

    print("Climate zone no "..d.." ID: "..MyVar1.climateZones[z].id)

    Thank you guys for your response. I got an error on ..d.. have changed this to ..z.. Now it gives the value of the loop. Was that also your intention?

    Link to comment
    Share on other sites

    16 hours ago, Alex V said:

    Thank you guys for your response. I got an error on ..d.. have changed this to ..z.. Now it gives the value of the loop. Was that also your intention?

     

    Hi @Alex V ,

     

    that was typo. d should be z. @jgab solution is better on the coding side, less typing. My solution is better to understand how to get deeper into the table tree to get desired data. :-) In practice I use mostly ipairs or pairs to loop through table data.

    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
    Reply to this topic...

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