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]Print variable from json path


Plank

Question

I am trying to get a power reading from my energy monitor but am having lots of trouble trying to work out what code i need to use. I need to get a particular piece of info from this response I get.

I don't have any experience in coding don't have much idea, but a nudge in the right direction would be greatly appreciated.

 

The exact response from the http request is = [{"cid":"PWER","data":[{"1525674668000":746}],"sid":"740893","units":"kWm","age":6}] 

my energy monitor is a efergy monitor.

Please login or register to see this link.

 is where I got the API details from.

 

"746" is the value I am trying to retrieve.

 

When I print (response.data) I get [DEBUG] 16:31:24: [{"cid":"PWER","data":[{"1525674668000":746}],"sid":"740893","units":"kWm","age":6}]

When I print json.decode(response.data) I get [DEBUG] 16:17:02: table: 0x9c41348 -- I don't know what this means

 

 

I tested the path here: 

Please login or register to see this link.

 

and can get the watt reading using this code "..data[0]*" in the json path expression field 

 

Scene code i'm using. I just copied and pasted from another forum post by @Lambik to get the http request, I'l make my own code later if i can get this data out.

Please login or register to see this code.

 

Edited by Plank
Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

 

 

Please login or register to see this code.

 

Please login or register to see this code.

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Thanks for your help, it returns the values in a  table? 

     

    [DEBUG] 21:23:07: { [1] = { ["units"] = kWm,["cid"] = PWER,["age"] = 4,["data"] = { [1] = { ["1525692173000"] = 1186,} ,} ,["sid"] = 740893,} ,}

     

    Edit: now I see that Dump shows the table structure. so I can grab the values of anything in the first table. But can't work out how to get the value from the "data" table because this  ["1525692173000"] is a variable.

     

    If it wasn't a variable i would assume I could get the data with this.

     

    Please login or register to see this code.

     

     

    Any more hints would be great 

     

    Edited by Plank
    Update
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I think I have figured it out.

     

    I can print out the single Watt value with this code.

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I have finally managed to get it all working. Thanks for pointing me in the right direction @10der

    Please login or register to see this code.

     

    • Thanks 1
    Link to comment
    Share on other sites

    • 0

    Hello, can anyone of you help me in using this script to read data from a device from SUPLA. I have a device from ZAMEL MEW-01

    By sending a command:


    GET / direct / 642 / VUNZmkZTGJD / read HTTP / 1.1
    Host: svr24.supla.org:443

     

    I receive data in the JSON format:

     

    { "Connected" True, "support": 65535, "currency", "PLN", "pricePerUnit": 0.3 "TOTALCOST": 75.74, "Phases": [{ "number" 1 "frequency" 50 "voltage": 244.53, "current": 0775, "powerActive": 92.23984, "powerReactive" - 77.4013, "powerApparent": 185.87388, "powerfactor": 0496, "phaseAngle": 141.1, "totalForwardActiveEnergy": 58.17446, "totalReverseActiveEnergy" 0 "totalForwardReactiveEnergy": 0.05954 "totalReverseReactiveEnergy": 30.72214}, { "number" 2 "frequency" 50, "voltage": 242.55, "current": 2282, "powerActive": 444.04796, "powerReactive": 102.90696, "powerApparent": 542.80834, "powerfactor": 0816, "phaseAngle" - 167, "totalForwardActiveEnergy": 99.21702 "totalReverseActiveEnergy": 4.0E-5, "totalForwardReactiveEnergy": 3.96154 "totalReverseReactiveEnergy": 16.33724}, { "number" 3 "frequency" 50, "voltage": 240.18, "current": 10929, "powerActive": 2565.4368 "powerReactive" - 89.58352, "powerApparent": 2573.56152 "powerfactor" : 0998, "phaseAngle": 178.1, "totalForwardActiveEnergy": 95.0771, "totalReverseActiveEnergy": 0, "totalForwardReactiveEnergy ": 1.16234" totalReverseReactiveEnergy ": 52.39652}]}

     

    The point is for the scene to write into the parameters read from the device and then the virtual device to display them in the label. 

    Something like that:

     

    Please login or register to see this image.

    /monthly_2020_01/image.png.9dca408dba0978032a84f423e78c572b.png" />

    Link to comment
    Share on other sites

    • 0

    I have rewritten this script in the way below but an error occurs during debugging.

    Please login or register to see this image.

    /monthly_2020_01/image.png.bac82a3586761cbe3e49eca8d3da63fd.png" />

     

    image.png.a78992c936ae73ae62d0995bf82dfeb4.png

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