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

JSON with variables


Question

Posted

Is it possible to reference a JSON table using a variable e.g. 

Please login or register to see this code.

can this be referred to with a variable for monday, e.g. day_of_week?

 

Please login or register to see this code.

I get that the code above doesn't actually work, but is it possible somehow?

 

4 answers to this question

Recommended Posts

  • 0
Posted

Please login or register to see this code.

as they say text is beautiful.

  • 0
  • Inquirer
  • Posted (edited)

    Glad I'm not the only one playing around with my HC2 on a Sunday night! :-D

     

    I either didn't get what you wrote or I didn't explain myself very well.

     

    I am retrieving tables from the HC2 api for heating and instead of having to hardcode in my code each value that I want to write back e.g. 

     

    Please login or register to see this code.

    i want to be able to use variables e.g. day_of_week = "monday", so I can write my code with this effect: 

     

    Please login or register to see this code.

    I get that by inserting "day_of_week" in the example above I am just writing to the value "properties.day_of_week.morning.temperature", but what I really want to write to is this value ""properties.monday.morning.temperature"

     

    Does that make sense now?

     

    Conversely, is it possible to reference a position in a JSON table e.g. if the table has 10 values, can you specify value number 3 to read from and write to? This would be a compromise, but better than having to hardcode all possible combinations in my code to be able to write to any point in a table.

    Edited by amilanov
    • 0
    Posted (edited)

    Please login or register to see this code.

    Ahh  OK did not understand. This would probably work for you.

    Please login or register to see this code.

    Would not normally be playing with HC2 but The Apprentice drove me to the far end of the house.

    Edited by robmac
    • 0
  • Inquirer
  • Posted (edited)

    Nice one! 

     

    Can't believe how long I spent searching for that, but couldn't find it.  

     

    --------------------

    EDIT: Just saw your updated post. Figured out the nesting of the brackets [x][y], but thanks for clarifying!

    Edited by amilanov

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