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


Strange json behaviour in QA


Alex de Bruin
 Share

Recommended Posts

When i use

   local HT = json.decode(fibaro.getGlobalVariable("HomeTable"))

in a QuickApp, i get the following error:

 

[21.08.2022] [18:31:41] [DEBUG] [QUICKAPP24]: /usr/share/lua/5.3/json/util.lua:55: bad argument #1 to 'for iterator' (table expected, got number)[21.08.2022] [18:31:41] [ERROR] [QUICKAPP24]: QuickApp crashed[21.08.2022] [18:31:41] [ERROR] [QUICKAPP24]: Unknown error occurred: handleJsonRpc

 

In a scene this is no problem.

 

When i change it to:

   local jHT = fibaro.getGlobalVariable("HomeTable")
   local HT  = json.decode(HT)

then all goes well.

 

On my HC2 i use the nesting in both scenes and VD's

Link to comment
Share on other sites

Please login or register to see this code.

works.

fibaro.getGlobalVariable("HomeTable") returns 2 values. The value of the global and the modification time.

These two values are then sent to json.decode as two arguments. Unfortunately, json.decode accepts a second argument that are options for the decode, a table. However, modification time is a number so it fails when it tries to iterate over the table with options...

A simple way to convert 2 return values to one return value in Lua is to put parentheses around the call, like (fibaro.getGlobalVariable("HomeTable"))

So, 

Please login or register to see this code.

works.

  • Like 1
Link to comment
Share on other sites

  • Topic Author
  • Thanks, i keep learning.

     

    Still strange that the same function fibaro.getGlobalVariable when used in a scene returns only one value.

    Link to comment
    Share on other sites

    16 minutes ago, Alex de Bruin said:

    Thanks, i keep learning.

     

    Still strange that the same function fibaro.getGlobalVariable when used in a scene returns only one value.

    Yes, for some reason Fibaro has different implementations for the fibaro.* functions when it comes to scenes and QAs. The scene version don't return the modification time...

    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.

     Share

    ×
    ×
    • Create New...