I would like to read data from my solar inverter and post it to pvoutput.org. The inverter answers this xml:
<Device Name="StecaGrid 4200" Type="Inverter" Serial="********************" BusAddress="1" NetBiosName="***************" IpAddress="***.***.****.***" DateTime="2020-01-18T16:31:31">
<Measurements>
<Measurement Value="225.492" Unit="V" Type="AC_Voltage"/>
<Measurement Value="0.442" Unit="A" Type="AC_Current"/>
<Measurement Value="83.860" Unit="W" Type="AC_Power"/>
<Measurement Value="49.983" Unit="Hz" Type="AC_Frequency"/>
<Measurement Value="470.400" Unit="V" Type="DC_Voltage"/>
<Measurement Value="0.182" Unit="A" Type="DC_Current"/>
<Measurement Value="85.840" Unit="W" Type="DC_Power"/>
<Measurement Value="20.000" Unit="°C" Type="Temp"/>
</Measurements>
</Device>
</root>
I use the following code to read the data:
import urllib.request, urllib.parse, urllib.error
import xml.etree.ElementTree as ET
url = 'http://***.***.***.***/measurements.xml'
uh = urllib.request.urlopen(url)
data = uh.read()
tree = ET.fromstring(data)
lst = tree.findall('Measurements')
counts = tree.findall('.//Measurement')
print(tree.findall('.//Measurement').find('AC_Voltage'))
for each in counts:
print(each.attrib['Type'], each.attrib['Value'], each.attrib['Unit'])
If there is sunshine, the results look like this:
C_Voltage 226.632 V
AC_Current 0.259 A
AC_Power 41.920 W
AC_Frequency 49.980 Hz
DC_Voltage 451.896 V
DC_Current 0.100 A
DC_Power 45.270 W
Temp 18.100 °C
But when a value is 0, the attribute is omitted.
Only if AC_Power >0, I want to upload the data. How can I store these attributes in variables or arrays in order to create a POST url?