ich habe einen python Code gefunden über den der Senec Speicher ausgelesen werden kann.
Der Code erstellt im Unterverzeichnis "ausgabe" einzelne Dateien mit den benötigten werden des Speichers.
Wäre doch cool wenn du den Speicher einbinden könntest. Ich würde mich als Testobjekt zur Verfügung stellen
Code: Alles auswählen
#!/usr/bin/python
import struct
import json
import urllib2
import time
ipaddress = "192.168.0.136"
debug = False
def myDecode(stringValue):
# Parameter:
# stringValue: String Wert, im Format Typ_Wert
#
# Rueckgabe:
# result: Floatzahl
splitValue = stringValue.split('_')
if splitValue[0] == 'fl':
#Hex >> Float
result = struct.unpack('f',struct.pack('I',int('0x'+splitValue[1],0)))[0]
elif splitValue[0] == 'u3':
pass #TBD
elif splitValue[0] == 'u8':
pass #TBD
return result
def writeVal(filePath,stringValue,multiplier,decimalpoints):
#Parameter
#filePath: Pfad und Dateiname in der ein Wert geschrieben wird
#stringValue: Wert der nach dem konvertieren in die Datei geschrieben wird
#multiplier: Wert mit dem die Zahl vor der Rundung multipliziert wird
#decimalpoints: Anzahl Kommastellen
#
#Rueckgabe: nichts
val= myDecode(stringValue)
# Format anpassen
if multiplier != 0:
val = val * multiplier
#auf 2 Ziffern runden
if decimalpoints == 0:
val = int(val)
elif decimalpoints != 0:
val = round(val,decimalpoints)
if debug:
print(str(val))
print filePath
else:
f = open(filePath, 'w')
f.write(str(val))
f.close()
#EVU Daten
reqdata='{"PM1OBJ1":{"FREQ":"","U_AC":"","I_AC":"","P_AC":"","P_TOTAL":""}}'
response = urllib2.urlopen('http://'+ ipaddress +'/lala.cgi' ,data=reqdata)
jsondata = json.load(response)
#SENEC: Gesamtleistung (W) Werte -3000 >> 3000
writeVal('ausgabe/wattbezug_senec', jsondata['PM1OBJ1'] ['P_TOTAL'],0,0)
#SENEC: Frequenz(Hz) Werte 49.12 >> 50.34
writeVal ('ausgabe/evuhz',jsondata['PM1OBJ1'] ['FREQ'],0,2)
#SENEC: Spannung (V) Werte 219.12 >> 223.43
writeVal('ausgabe/evuv1', jsondata['PM1OBJ1'] ['U_AC'] [0],0,2)
writeVal('ausgabe/evuv2', jsondata['PM1OBJ1'] ['U_AC'] [1],0,2)
writeVal('ausgabe/evuv3', jsondata['PM1OBJ1'] ['U_AC'] [2],0,2)
#SENEC: Leistung (W) Werte -2345 >> 3000
writeVal('ausgabe/bezugw1', jsondata['PM1OBJ1'] ['P_AC'] [0],0,0)
writeVal('ausgabe/bezugw2', jsondata['PM1OBJ1'] ['P_AC'] [1],0,0)
writeVal('ausgabe/bezugw3', jsondata['PM1OBJ1'] ['P_AC'] [2],0,0)
#SENEC: Strom (A) Werte 0.88 >> 1.67
writeVal('ausgabe/bezuga1_senec', jsondata['PM1OBJ1'] ['I_AC'] [0],0,2)
writeVal('ausgabe/bezuga2_senec', jsondata['PM1OBJ1'] ['I_AC'] [1],0,2)
writeVal('ausgabe/bezug33_senec', jsondata['PM1OBJ1'] ['I_AC'] [2],0,2)
#Batteriedaten:
reqdata='{"ENERGY":{"GUI_BAT_DATA_FUEL_CHARGE":"","GUI_BAT_DATA_POWER":"","GUI_BAT_DATA_VOLTAGE":"","GUI_BAT_DATA_OA_CHARGING":""}}'
response = urllib2.urlopen('http://'+ ipaddress +'/lala.cgi' ,data=reqdata)
jsondata = json.load(response)
#SENEC: Batterieleistung (W) Werte -345 (Entladen) >> 1200 (laden)
writeVal('ausgabe/speicherleistung_senec', jsondata['ENERGY'] ['GUI_BAT_DATA_POWER'],0,0)
#SENEC: Fuellmenge in Prozent Werte 10 >> 55 >> 100
writeVal('ausgabe/speichersoc_senec', jsondata['ENERGY'] ['GUI_BAT_DATA_FUEL_CHARGE'],0,0)
#Statistik
reqdata='{"STATISTIC":{"STAT_BAT_CHARGE":"","STAT_BAT_DISCHARGE":"","STAT_GRID_EXPORT":"","STAT_GRID_IMPORT":"","STAT_HOUSE_CONSUMPTION":"","STAT_PV_GENERATION":""}}'
response = urllib2.urlopen('http://'+ ipaddress +'/lala.cgi' ,data=reqdata)
jsondata = json.load(response)
#SENEC: Gesamtlademenge (Wh) Werte 1692
writeVal('ausgabe/speicherikwh_senec', jsondata['STATISTIC'] ['STAT_BAT_CHARGE'],1000,0)
#SENEC: Gesamtentlademenge (Wh) Werte 1590
writeVal('ausgabe/speicherekwh_senec', jsondata['STATISTIC'] ['STAT_BAT_DISCHARGE'],1000,0)
#SENEC: Gesamtimport (Wh) Werte 1809000
writeVal('ausgabe/bezugkwh_senec', jsondata['STATISTIC'] ['STAT_GRID_IMPORT'],1000,0)
#SENEC: Gesamteinspeisung Werte (Wh) 7085000
writeVal('ausgabe/einspeisungkwh_senec', jsondata['STATISTIC'] ['STAT_GRID_EXPORT'],1000,0)