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

Handling response body from API


Question

Posted

I want to store my or a group of my device_id's and a logical name in a table and store that table in a global var. That works fine via the API.

To retrieve the global var I use the Get request that gives me a response body in JSON. The values stored can be found in response.value which gives me these values:
[DEBUG] 09:50:21: [{"id":"103","device":"Vloerlamp"},{"id":"215","device":"LampOpStatief"},{"id":"101","device":"TuinLinks"},{"id":"55","device":"TuinRechts"},{"id":"116","device":"Schuur"},{"id":"61","device":"Boedha"},{"id":"105","device":"Eiland"},{"id":"213","device":"Heklicht"},{"id":"48","device":"LedBoekenkast"},{"id":"154","device":"Yielde"},{"id":"177","device":"Kerstboom"},{"id":"178","device":"Kerstverlichting"},{"id":"194","device":"Buddha"},{"id":"217","device":"Leeslamp"}]

I would expect a table = json:decode(response.value); would give me the table I need to build a loop and do something with the devices like turnoff or turnon.

But I get this error on the decode: 

[DEBUG] 10:14:05: 2019-08-11 10:14:05.372820 [ fatal] Unknown exception: /usr/share/lua/5.2/json/util.lua:55: bad argument #1 to 'pairs' (table expected, got string)

If I use the GetGlobal() statement and passes that reponse to the decode the it works without an issue and I can process the table.

 

I have read a lot of topics on this but until now I am still clueless. Any help appreciated.

I am also a bit confused with how LUA handles strings, tables and JSON.

1 answer to this question

Recommended Posts

  • 0
Posted

Why not using @AutoFrank solution? This works out of the box and really easy to use in LUA scenes

 

 

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