I have defined a sensor like this:
- platform: rest
name: inverterarchive
resource: http://192.168.1.129/solar_api/v1/GetArchiveData.cgi?Scope=System&StartDate={{ (as_timestamp(now())-300)|timestamp_custom("%Y-%d-%mT%H:%M:%S") }}+2:00&EndDate={{ as_timestamp(now())|timestamp_custom("%Y-%d-%mT%H:%M:%S") }}+2:00&Channel=Voltage_DC_String_1&Channel=Voltage_DC_String_2
json_attributes:
- Body
value_template: '{{ value_json.value }}'
headers:
Content-Type: application/json
scan_interval: 120
- platform: template
sensors:
voltage_dc_string_1:
friendly_name: 'Voltage_DC_String_1'
value_template: "{{state_attr('sensor.inverterarchive','Body')['Data']['inverter/1']['Data']['Voltage_DC_String_2']['Values']['130']}}"
unit_of_measurement: 'V'
- platform: template
sensors:
voltage_dc_string_2:
friendly_name: 'Voltage_DC_String_2'
value_template: "{{state_attr('sensor.inverterarchive','Body')['Data']['inverter/1']['Data']['Voltage_DC_String_2']['Values']['130']}}"
unit_of_measurement: 'V'
Now when checking the resource in the developer template i get the correct path , something like:
http://192.168.3.129/solar_api/v1/GetArchiveData.cgi?Scope=System&StartDate=2020-12-12T10:20:58+2:00&EndDate=2020-12-12T10:25:58+2:00&Channel=Voltage_DC_String_1&Channel=Voltage_DC_String_2
Which in turn gives a response like:
{
"Body" :
{
"Data" :
{
"inverter/1" :
{
"Data" :
{
"Voltage_DC_String_1" :
{
"Unit" : "V",
"Values" :
{
"130" : 588.89999999999998
},
"_comment" : "channelId=66049"
},
"Voltage_DC_String_2" :
{
"Unit" : "V",
"Values" :
{
"130" : 151.20000000000002
},
"_comment" : "channelId=131585"
}
},
"DeviceType" : 232,
"End" : "2020-12-12T09:37:49+02:00",
"NodeType" : 97,
"Start" : "2020-12-12T09:32:50+02:00"
}
}
},
"Head" :
{
"RequestArguments" :
{
"Channel" :
[
"Voltage_DC_String_1",
"Voltage_DC_String_2"
],
"EndDate" : "2020-12-13T09:37:49+02:00",
"HumanReadable" : "True",
"Scope" : "System",
"SeriesType" : "Detail",
"StartDate" : "2020-12-12T09:32:50+02:00"
},
"Status" :
{
"Code" : 0,
"ErrorDetail" :
{
"Nodes" : []
},
"Reason" : "",
"UserMessage" : ""
},
"Timestamp" : "2020-12-12T09:38:03+02:00"
}
}
The problem is that whatever i do i can not get the Voltage_DC_String_1 and Voltage_DC_String_2 values stored under the “130”, so the 588 and 151 Volts in the above example.
The error that comes first is “UndefinedError: ‘dict object’ has no attribute ‘inverter/1’”
Also the 130 under which the Volt value is stored changes at each request and i have no ideea how to template that ![:frowning: :frowning:]()
Can someone please help me to make some progress ?
Thank you !
1 post - 1 participant
Read full topic