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


How to check table data stored in global variable in easy readable JSON format


Sankotronic

Recommended Posts

Hello everyone!

 

LUA is great with handling data organized in tables. Home automation is all about data. Weather, various measurements, actions can all be nicely stored and organized if data tables are used. Also using tables can greatly reduce number of global variables needed.

 

More about LUA tables and table functions you can find here:

Please login or register to see this link.

Or from here:

Please login or register to see this link.

 

During development of VD's, QA's and scenes and testing it might be necessary to check tables stored in global variables in a nice easy readable format.

 

Here is a way how to do it on HC2:

NOTE: I recommend using Firefox since it has ability to show JSON data

 

1) Go in your Firefox browser to API documentation of your HC: http://<YOUR_HC_IP>/docs/#!/globalVariables/getGVariables_0

Please login or register to see this spoiler.

 

It is also possible to copy JSON table and paste it to your LUA editor for further action.

 

Enjoy coding! :-)

 

 

  • Like 1
Link to comment
Share on other sites

You could add Chrome extension jsonvue (or jsonFormatter) and you don't need to copy&paste to another json decoder...

Please login or register to see this link.

 

 

Edited by jgab
  • Like 1
Link to comment
Share on other sites

  • Topic Author
  • Hi @jgab ,

     

    I did what you suggested, but still didn't get nice JSON tree as you can see it on the last screenshot in the right box.

    Is there something else needs to be done or this is final result of this extension:

    Please login or register to see this spoiler.

     

    My goal is to get global variable value only that contains table and then get easy readable JSON tree with nice syntax coloring showing string, number and boolean values in different colors. Can JSONVue and Chrome do that?

    Link to comment
    Share on other sites

    Ok, I was a bit fast - only used this to look at device structures. Your data is json encoded inside another structure (the global resource structure) so that complicates things.

    I may be possible to add som JS to make jsonVue look inside the value...

     

    but another approach is to have a QA with one line of code (assume it has deviceId 844) - it becomes a 2-step process.

    Please login or register to see this code.

    Then one url to update what variable to look at ex. global variable "A"

    Please login or register to see this code.

    and another to look at the actual data (need to be reloaded)

    Please login or register to see this code.

     

    Alternatively, create a dedicated QA that regularly updates a given global variable  (or triggers on that global changing value) - that way you only need to update the first url.
    Edited by jgab
    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...