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

Trying to update a part of json encoded table in a global variable


AutoFrank

Question

Hi,

I have implemented @cag014 HomeTable to track the device ID's of my HC2

 

the table structure is like this 

 

Please login or register to see this code.

I can update the whole table but was wondering if it was possible to update a specific vale such as "scene.AlarmControl" in the example I posted above.

Any helpful code snippets gratefully accepted :-)

 

thanks

-f

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Yes, you can update any value at any code and then after an update  just restore the global variable - for example

fibaro:setGlobal("GlobalVar",json.encode(jTable) )

Link to comment
Share on other sites

  • 0
  • Inquirer
  • 51 minutes ago, cag014 said:

    Yes, you can update any value at any code and then after an update  just restore the global variable - for example

    fibaro:setGlobal("GlobalVar",json.encode(jTable) )

     

    Thanks @cag014

    I think I didn't present what I'm trying to do very well.

    I just want to update just one value pair like the lux (id) in the kitchen to be 1235 to 5467 and I'm looking to do it through lua.

    I think I can read the whole table but I'm not sure how to find and update the single value before i save the gv again 

     

    If it's possible and you have more info on the lua or approach that would be great 

    Thx

    F

     

    Link to comment
    Share on other sites

    • 0

    It's very simple as an example:

    -- set new ID for Light in office

    office.Light = 55 

    -- now restore the value

    fibaro:setGlobal("GlobalVar",json.encode(HomeTable) )

    Link to comment
    Share on other sites

    • 0

    A bit tangential: do you use the variables panel? If you do... saving data via the panel messes with non-numerical data (like json). If you want to make the code more robust, please check if the json decode succeeds and if the table structure is valid. Just shout if you want me to elaborate.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Thanks @cag014 / @petergebruers

     

    I have to admit I'm feeling a bit stupid with this one.. :cry:

    .. I'll start at the beginning and apologies if I'm repeating myself but I'm not sure what to do next.

     

    I'm using the Hometable idea to manage the device and scene ID's. I'm using a predefined variable for the table. I haven't been using the 'save' button for the reason peter stated .

     

     

     

     

    I have a very simple VD that I use to keep the table up to date. If I need to adjust the "data" I drop the new json into and vd and it updates the table.

    This is end of my VD..

     

    Please login or register to see this code.

    the table gets updated and I use the last 3 lines as a crude way of verifying that the table didn't corrupted in the process.

     

    This method of updating the table (part manual and part programmable) is working very well for me.

     

    I have a new project where I want o keep track of some data for my sonos zones.

    I created a new predefined variable with the following structure

     

    Please login or register to see this code.

    I've been trying to find a way to update parts of the table above through code alone.

     

    I'm assuming that this is possible (it must be ??) and this is my crude attempt to try and understand the syntax.

    Please login or register to see this code.

    I create the table and then try and change one of the parameters and update that within the table and then read it back to see if it has changed.

     

    Again apologies for perhaps not articulating what I'm trying to do and thanks for helping..

    -frank

     

     

     

     

     

     

     

     

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0

    OK.... for example let's change the Sonos TTS_Vol based on your code

    Please login or register to see this code.

    Please login or register to see this code.

    that's all. 

    Please pay attention that the parameter saving done by using jT table

     

     

    Edited by cag014
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 13 minutes ago, cag014 said:

    OK.... for example let's change the Sonos TTS_Vol based on your code

    Please login or register to see this code.

    Please login or register to see this code.

    that's all. 

    Please pay attention that the parameter saving done by using jT table

     

     

     

    Thanks @cag014

    that's exactly what I wanted ... much appreciated

     

    -frank

     

     

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