Pulling Json Attributes into Sensor Attributes

Hi All, bit of a N00b here but I’m not completely useless.

I am attempting to bring in some data from a cloud monitoring service for my solar energy production. I can see through other posts and documentation that the mechanisms for retrieving the data form either the on-prem devices or the cloud service have changed a bit over the last 5 or so years, so I have found that most other posts about this service are not so relevant.

I have followed the general API documentation provided by the provider and the Home Assistant best practice, resulting in me being able to query for individual json attributes using a rest/get query, but this is limiting in the fact that there are a multitude of json attributes available and that the provider now limits the number of calls per day. Here is what the individual json queries look like in the sensor.yaml file:

  • platform: rest
    resource: https://www.solaxcloud.com/proxyApp/proxy/api/getRealtimeInfo.do?tokenId=XXXXX&sn=
    method: GET
    headers:
    Authorization: !secret solax_auth
    Content-Type: application/json
    params:
    tokenId: !secret solax_token
    inverterSN: !secret solax_inverter_serial
    sn: !secret solax_device_serial
    name: “Solax - Solar Array 2”
    value_template: ‘{{ (value_json[“result”].powerdc2 | int) }}’
    device_class: POWER
    unit_of_measurement: W
    state_class: measurement
    scan_interval: 300

I am attempting to build a single query that brings in all the attributes (using the above attributes I can pull all the attributes in one hit via postman, as below). This will significantly reduce the number of API queries per day to 1 per 300s rather than 11 per 600s:

{
“success”: true,
“exception”: “Query success!”,
“result”: {
“inverterSN”: “XXXX”,
“sn”: “XXXX”,
“acpower”: 0.0,
“yieldtoday”: 45.4,
“yieldtotal”: 11972.3,
“feedinpower”: 0.0,
“feedinenergy”: 0.0,
“consumeenergy”: 0.0,
“feedinpowerM2”: null,
“soc”: null,
“peps1”: null,
“peps2”: null,
“peps3”: null,
“inverterType”: “16”,
“inverterStatus”: “100”,
“uploadTime”: “2023-11-29 22:17:12”,
“batPower”: null,
“powerdc1”: 0.0,
“powerdc2”: 0.0,
“powerdc3”: 0.0,
“powerdc4”: null,
“batStatus”: null
},
“code”: 0
}

For the life of me I can’t get the json_attributes to show up as attributes against the sensor. I can get any of the individual values it returns to show up under the state (ie. replace the ‘OK’ state value, meaning that it is pulling back relevant data… It’s just not writing them to the attributes).
NOTE: It was night when the above sample data was collected, so most values are “0” or “null”, but this has been tested during daylight hours too.

Here is the query I have built:

  • platform: rest
    resource: https://www.solaxcloud.com/proxyApp/proxy/api/getRealtimeInfo.do?tokenId=XXXX&sn=
    method: GET
    headers:
    Authorization: !secret solax_auth
    Content-Type: application/json
    params:
    tokenId: !secret solax_token
    inverterSN: !secret solax_inverter_serial
    sn: !secret solax_device_serial
    scan_interval: 300
    name: All Solax Data
    json_attributes:
    • “acpower”
    • “yieldtoday”
    • “yieldtotal”
    • “feedinpower”
    • “feedinenergy”
    • “consumeenergy”
    • “inverterStatus”
    • “uploadTime”
    • “powerdc1”
    • “powerdc2”
    • “powerdc3”
    • “powerdc4”
      json_attributes_path: “$response.values”
      value_template: ’ OK ’

HELP!

I believe the json_attributes_path you seek is: $.result

PLEASE format your code correctly.

1 Like