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

Question
RonS 0
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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.