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

<solved> extracting data from JSON response


Question

Posted (edited)

,maybe someone can help me with the following question:

 

the response i get from a HTTP request on my heating controller is :

 

 {"jsonrpc":"2.0","id":6538,"result":{"objects":[{"id":"211","properties":{"85":{"value":19.5}}}]}}
 

 

And i now need to extract  the value 19.5 out of this and put it into a variable.

 

at this moment I have the following data

{  
   "jsonrpc":"2.0",
   "id":6538,
   "result":{  
      "objects":[  
         {  
            "id":"225",
            "properties":{  
               "85":{  
                  "value":19.8
               }
            }
         }
      ]
   }
}

and i can extract data up to the id= 225  with following code:

  local resultaat = json.decode(response)
 
  figaro:debug(resultaat.jsonrpc)
  fibaro:debug(resultaat.id)
  fibaro:debug(resultaat.result.objects[1].id)
  fibaro:debug(resultaat.result.objects[1].properties)

 

as soon as i put in the next level 85 i get a failure message so i'm really stuck

[ERROR] 19:05:58: line 16: ')' expected near '.85'

 

 

 

 

in reverse I would also like to put a value back into following statement:

 

{"jsonrpc":"2.0","id":11,"method":"write","params":{"objects":[{"id":"211","properties":{"85":{"value":"19.5"}}}]}}

 

so that i can write that to the device.

 

any help will be very much appreciated as i am just learning LUA and documentation is not very available/clear.

Edited 22 minutes ago by WimF 

Please login or register to see this link.

 0
 
  •  
  •  
Edited by WimF

9 answers to this question

Recommended Posts

  • 0
  • Inquirer
  • Posted

    @petergebruers

    from Reading Your replies on other topics you migratie have the answer to my problem.

     

    I really would appreciate of you could have a look.

     

    • 0
    Posted
    17 minutes ago, WimF said:

    (...)  you migratie have the answer to my problem.

     

     

     

    Odd spell checker... I'll have a look!

     

     

     

     

    • 0
    Posted (edited)

    Can you please check if this helps? This is runnable code. The answers are in the code.

     

    Please login or register to see this code.

     

    Edited by petergebruers
    • 0
    Posted

    Or in that way

     

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted

    @petergebruers

    @A.Socha

     

    thanks you very much for your responses.

     

    I will try this evening and let you know the outcome.

    • 0
  • Inquirer
  • Posted (edited)
    2 hours ago, petergebruers said:

    Can you please check if this helps? This is runnable code. The answers are in the code.

     

    Please login or register to see this code.

     

    @petergebruers

     

    This was working at the first go.

     

    Thanks you very much, I can no get the data from my heating controller and also be able to change it with a button in VD and write it back.

     

    The part that doesn't seem to be working is :

     

    for k,v in pairs(resultaat.result.objects[1].properties) do
      fibaro:debug("resultaat.result.objects[1].properties[\""..k.."\"].value:"..v.value)
    end

     

    this would be a very nice option to have to read all the data from the whole house in one go.

     

    I do get following response if there are more values to collect:

     

    {"jsonrpc":"2.0","id":6,"result":{"objects":[{"id":"108","properties":{"85":{"value":129.0}}},{"id":"109","properties":{"85":{"value":"Keuken / Studie"}}},{"id":"148","properties":{"85":{"value":258.0}}},{"id":"149","properties":{"85":{"value":"Badkamer"}}},{"id":"188","properties":{"85":{"value":4.0}}},{"id":"189","properties":{"85":{"value":"Slaapkamer"}}},{"id":"228","properties":{"85":{"value":120.0}}},{"id":"229","properties":{"85":{"value":"Woonkamer"}}}]}}
     

     

    I can now spend the rest of my evening trying to understand what you did.

     

    thanks again.

    Edited by WimF
    • 0
  • Inquirer
  • Posted
    2 hours ago, A.Socha said:

    Or in that way

     

    Please login or register to see this code.

     

    @A.Socha

     

    Thanks for your reply,

     

    retrieving the temperature works your way as well.

     

    Sending back data does not work since the changes need to not to be made in the response but in another string

     

    {"jsonrpc":"2.0","id":11,"method":"write","params":{"objects":[{"id":"211","properties":{"85":{"value":"19.5"}}}]}}.

     

    however its been helpful and it puts me on the right track.

     

    thanks you.

    • 0
    Posted

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted

    @A.Socha

     

    Thanks for your help.

     

    this works fine after a small correction (typo)

    "jsonstring" and "string2" needs to be reversed in the final encoding

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