SENEC Modul

Anfragen zum Erstellen von Modulen, Fragen zu Modulen
bennysweb
Beiträge: 5
Registriert: Mo Dez 19, 2022 5:59 pm

Re: SENEC Modul

Beitrag von bennysweb »

matzeeg3 hat geschrieben: Do Sep 07, 2023 8:46 am Für alle die auf openWB 1.9 sind ich habe mal das script etwas umgeschrieben.
Danke an cjungde:

Code: Alles auswählen

import struct
import json
import urllib.request
import time
import ssl
import paho.mqtt.client as mqtt

ipaddress = "senecip"
broker_address = "openwbip or localhost"
broker_port = 1883
debug = False

#ipaddress = str(sys.argv[1])

client = mqtt.Client()
# Verbinden mit dem Broker
client.connect(broker_address, broker_port)

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(stringValue, multiplier, decimalpoints):

#Parameter
#filePath:              Pfad und Dateiname in der der ein Wert geschrieben wird
#stringValue:   Wert der nach dem knonvertieren 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 val is None:
        val = 0

    return val

#EVU Daten
reqdata = '{"PM1OBJ1":{"FREQ":"","U_AC":"","I_AC":"","P_AC":"","P_TOTAL":""}}'
reqdata = bytes(reqdata, 'utf-8')
response = urllib.request.urlopen('https://' + ipaddress + '/lala.cgi', data=reqdata, context=ssl._create_unverified_context())
jsondata = json.load(response)



#SENEC: Gesamtleistung (W) Werte -3000  >> 3000
if not (jsondata['PM1OBJ1'] ['P_TOTAL'] is None):
    topic = "openWB/set/evu/W"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['P_TOTAL'],0,0))


#SENEC: Frequenz(Hz) Werte 49.00 >> 50.00
if not (jsondata['PM1OBJ1'] ['FREQ'] is None):
    topic = "openWB/set/evu/HzFrequenz"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['FREQ'],0,2))

#SENEC: Spannung (V) Werte 219.12 >> 223.43
if not (jsondata['PM1OBJ1'] ['U_AC'] [0] is None):
    topic = "openWB/set/evu/VPhase1"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['U_AC'] [0],0,2))
if not (jsondata['PM1OBJ1'] ['U_AC'] [1] is None):
    topic = "openWB/set/evu/VPhase2"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['U_AC'] [1],0,2))
if not (jsondata['PM1OBJ1'] ['U_AC'] [2] is None):
    topic = "openWB/set/evu/VPhase3"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['U_AC'] [2],0,2))

#SENEC: Leistung (W) Werte -2345 >> 3000
if not (jsondata['PM1OBJ1'] ['P_AC'] [0] is None):
    topic = "openWB/set/evu/WPhase1"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['P_AC'] [0],0,0))
if not (jsondata['PM1OBJ1'] ['P_AC'] [1] is None):
    topic = "openWB/set/evu/WPhase2"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['P_AC'] [1],0,0))
if not (jsondata['PM1OBJ1'] ['P_AC'] [2] is None):
    topic = "openWB/set/evu/WPhase3"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['P_AC'] [2],0,0))


#SENEC: Strom (A) Werte 0.88 >> 1.67
if not (jsondata['PM1OBJ1'] ['I_AC'] [0] is None):
    topic = "openWB/set/evu/APhase1"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['I_AC'] [2],0,2))
if not (jsondata['PM1OBJ1'] ['I_AC'] [1] is None):
    topic = "openWB/set/evu/APhase2"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['I_AC'] [2],0,2))
if not (jsondata['PM1OBJ1'] ['I_AC'] [2] is None):
    topic = "openWB/set/evu/APhase3"
    client.publish(topic, writeVal(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":"","GUI_INVERTER_POWER":""}}'
reqdata = bytes(reqdata, 'utf-8')
response = urllib.request.urlopen('https://' + ipaddress + '/lala.cgi', data=reqdata, context=ssl._create_unverified_context())
jsondata = json.load(response)

#SENEC: Batterieleistung (W) Werte -345 (Entladen) >> 1200 (laden)
if not (jsondata['ENERGY'] ['GUI_BAT_DATA_POWER'] is None):
    topic = "openWB/set/houseBattery/W"
    client.publish(topic, writeVal(jsondata['ENERGY'] ['GUI_BAT_DATA_POWER'],0,0))

#SENEC: Fuellmenge in Prozent Werte 10 >> 55 >> 100
if not (jsondata['ENERGY'] ['GUI_BAT_DATA_FUEL_CHARGE'] is None):
    topic = "openWB/set/houseBattery/%Soc"
    client.publish(topic, writeVal(jsondata['ENERGY'] ['GUI_BAT_DATA_FUEL_CHARGE'],0,0))

#SENEC: Leistung Wechselrichter in (W) Werte
if not (jsondata['ENERGY'] ['GUI_INVERTER_POWER'] is None):
    topic = "openWB/set/pv/1/W"
    client.publish(topic, writeVal(jsondata['ENERGY'] ['GUI_INVERTER_POWER'],0,0))

# Client beenden
client.disconnect()
so müssen keine daten mehr auf http abfrage gestellt werden sondern das script egal ob auf der openwb ausgeführt oder wo anders sendet die daten via mqtt direkt an die openwb. Damit ist auch keine RAMdisk mehr nötig.
Im nächsten Step werde ich noch die Berechnung der kWh mit einbauen, das dauert aber leide noch ein paar Tage.
@matzeeg3: Kannst du dafür eine kleine Anleitung basteln? Das Script kann auch auf einem Raspi im Heimnetzwerk laufen, korrekt?
VG Benny
Verwendete Box: openWB series2 Standard+
matzeeg3
Beiträge: 40
Registriert: Fr Mai 07, 2021 6:33 am

Re: SENEC Modul

Beitrag von matzeeg3 »

bennysweb hat geschrieben: Fr Sep 08, 2023 7:04 am
matzeeg3 hat geschrieben: Do Sep 07, 2023 8:46 am Für alle die auf openWB 1.9 sind ich habe mal das script etwas umgeschrieben.
Danke an cjungde:

Code: Alles auswählen

import struct
import json
import urllib.request
import time
import ssl
import paho.mqtt.client as mqtt

ipaddress = "senecip"
broker_address = "openwbip or localhost"
broker_port = 1883
debug = False

#ipaddress = str(sys.argv[1])

client = mqtt.Client()
# Verbinden mit dem Broker
client.connect(broker_address, broker_port)

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(stringValue, multiplier, decimalpoints):

#Parameter
#filePath:              Pfad und Dateiname in der der ein Wert geschrieben wird
#stringValue:   Wert der nach dem knonvertieren 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 val is None:
        val = 0

    return val

#EVU Daten
reqdata = '{"PM1OBJ1":{"FREQ":"","U_AC":"","I_AC":"","P_AC":"","P_TOTAL":""}}'
reqdata = bytes(reqdata, 'utf-8')
response = urllib.request.urlopen('https://' + ipaddress + '/lala.cgi', data=reqdata, context=ssl._create_unverified_context())
jsondata = json.load(response)



#SENEC: Gesamtleistung (W) Werte -3000  >> 3000
if not (jsondata['PM1OBJ1'] ['P_TOTAL'] is None):
    topic = "openWB/set/evu/W"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['P_TOTAL'],0,0))


#SENEC: Frequenz(Hz) Werte 49.00 >> 50.00
if not (jsondata['PM1OBJ1'] ['FREQ'] is None):
    topic = "openWB/set/evu/HzFrequenz"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['FREQ'],0,2))

#SENEC: Spannung (V) Werte 219.12 >> 223.43
if not (jsondata['PM1OBJ1'] ['U_AC'] [0] is None):
    topic = "openWB/set/evu/VPhase1"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['U_AC'] [0],0,2))
if not (jsondata['PM1OBJ1'] ['U_AC'] [1] is None):
    topic = "openWB/set/evu/VPhase2"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['U_AC'] [1],0,2))
if not (jsondata['PM1OBJ1'] ['U_AC'] [2] is None):
    topic = "openWB/set/evu/VPhase3"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['U_AC'] [2],0,2))

#SENEC: Leistung (W) Werte -2345 >> 3000
if not (jsondata['PM1OBJ1'] ['P_AC'] [0] is None):
    topic = "openWB/set/evu/WPhase1"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['P_AC'] [0],0,0))
if not (jsondata['PM1OBJ1'] ['P_AC'] [1] is None):
    topic = "openWB/set/evu/WPhase2"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['P_AC'] [1],0,0))
if not (jsondata['PM1OBJ1'] ['P_AC'] [2] is None):
    topic = "openWB/set/evu/WPhase3"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['P_AC'] [2],0,0))


#SENEC: Strom (A) Werte 0.88 >> 1.67
if not (jsondata['PM1OBJ1'] ['I_AC'] [0] is None):
    topic = "openWB/set/evu/APhase1"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['I_AC'] [0],0,2))
if not (jsondata['PM1OBJ1'] ['I_AC'] [1] is None):
    topic = "openWB/set/evu/APhase2"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['I_AC'] [1],0,2))
if not (jsondata['PM1OBJ1'] ['I_AC'] [2] is None):
    topic = "openWB/set/evu/APhase3"
    client.publish(topic, writeVal(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":"","GUI_INVERTER_POWER":""}}'
reqdata = bytes(reqdata, 'utf-8')
response = urllib.request.urlopen('https://' + ipaddress + '/lala.cgi', data=reqdata, context=ssl._create_unverified_context())
jsondata = json.load(response)

#SENEC: Batterieleistung (W) Werte -345 (Entladen) >> 1200 (laden)
if not (jsondata['ENERGY'] ['GUI_BAT_DATA_POWER'] is None):
    topic = "openWB/set/houseBattery/W"
    client.publish(topic, writeVal(jsondata['ENERGY'] ['GUI_BAT_DATA_POWER'],0,0))

#SENEC: Fuellmenge in Prozent Werte 10 >> 55 >> 100
if not (jsondata['ENERGY'] ['GUI_BAT_DATA_FUEL_CHARGE'] is None):
    topic = "openWB/set/houseBattery/%Soc"
    client.publish(topic, writeVal(jsondata['ENERGY'] ['GUI_BAT_DATA_FUEL_CHARGE'],0,0))

#SENEC: Leistung Wechselrichter in (W) Werte
if not (jsondata['ENERGY'] ['GUI_INVERTER_POWER'] is None):
    topic = "openWB/set/pv/1/W"
    client.publish(topic, writeVal(jsondata['ENERGY'] ['GUI_INVERTER_POWER'],0,0))

# Client beenden
client.disconnect()
so müssen keine daten mehr auf http abfrage gestellt werden sondern das script egal ob auf der openwb ausgeführt oder wo anders sendet die daten via mqtt direkt an die openwb. Damit ist auch keine RAMdisk mehr nötig.
Im nächsten Step werde ich noch die Berechnung der kWh mit einbauen, das dauert aber leide noch ein paar Tage.
@matzeeg3: Kannst du dafür eine kleine Anleitung basteln? Das Script kann auch auf einem Raspi im Heimnetzwerk laufen, korrekt?
VG Benny
Moin Benny ja genau das ist erstmal egal wo das Script läuft, bei mir auch auf einem anderen Pi im Netzwerk.
Folgende schritte sind zu tun:
[*]Prüfen der Python Version "python --version" hier sollte 3.9 oder höher stehen.
[*]Installieren des Python Moduls "pip3 install paho-mqtt"
[*]Script auf den PI bringen "nano scriptname.py" und den inhalt hier raus kopieren. Achtung ich hab das Script nochmal angepasst, da ich ein Fehler in den Ampre Werten hatte
[*]Senec IP und Broker IP anpassen (Broker IP wäre dann die openWB)
[*]crontab -e aufrufen und folgendes nach Anpassung des Path ganz unten hineinkopieren:

Code: Alles auswählen

* * * * * python3 /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 5 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 10 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 15 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 20 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 25 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 30 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 35 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 40 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 45 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 50 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 55 && python /path-to-script/senec.py >/dev/null 2>&1
Und das war es dann auch schon, alle Werte werden im 5 Sekunden Takt aktuallisiert. Für den gesamten Prozess wird kein "sudo" benötigt.
In manchen Fällen (wenn mehrere Python Versionen installiert sind muss im crontab "python" durch "python3" ersetzt werden.
Ich hoffe das hilft.
Zuletzt geändert von matzeeg3 am Mo Sep 11, 2023 7:27 am, insgesamt 1-mal geändert.
bennysweb
Beiträge: 5
Registriert: Mo Dez 19, 2022 5:59 pm

Re: SENEC Modul

Beitrag von bennysweb »

Supi, danke! Ich probiere es am Wochenende aus und geb nochmal Bescheid.
Verwendete Box: openWB series2 Standard+
hubecker
Beiträge: 40
Registriert: Di Dez 07, 2021 9:59 pm

Re: SENEC Modul

Beitrag von hubecker »

Kleiner Tip:
Das script sollte noch konfigurierbar gemacht werden ob EVU,PV,BAT Daten übertragen werden.
Manche haben nur BAT konfiguriert und EVU/PV werden über andere module konfiguriert.

Gruß

Hubert
Openwb Series 2
Fronius Symo 8.2-3-M
SENEC.Home V2.1 10 Kwh
Tesla Model 3
matzeeg3
Beiträge: 40
Registriert: Fr Mai 07, 2021 6:33 am

Re: SENEC Modul

Beitrag von matzeeg3 »

Moin, danke für den Hinweis, mache ich die Tage fertig und verlinke dann das git repo dann ist auch immer der Code aktuell.
Mfg
bennysweb
Beiträge: 5
Registriert: Mo Dez 19, 2022 5:59 pm

Re: SENEC Modul

Beitrag von bennysweb »

matzeeg3 hat geschrieben: Fr Sep 08, 2023 7:45 am
bennysweb hat geschrieben: Fr Sep 08, 2023 7:04 am
matzeeg3 hat geschrieben: Do Sep 07, 2023 8:46 am Für alle die auf openWB 1.9 sind ich habe mal das script etwas umgeschrieben.
Danke an cjungde:

Code: Alles auswählen

import struct
import json
import urllib.request
import time
import ssl
import paho.mqtt.client as mqtt

ipaddress = "senecip"
broker_address = "openwbip or localhost"
broker_port = 1883
debug = False

#ipaddress = str(sys.argv[1])

client = mqtt.Client()
# Verbinden mit dem Broker
client.connect(broker_address, broker_port)

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(stringValue, multiplier, decimalpoints):

#Parameter
#filePath:              Pfad und Dateiname in der der ein Wert geschrieben wird
#stringValue:   Wert der nach dem knonvertieren 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 val is None:
        val = 0

    return val

#EVU Daten
reqdata = '{"PM1OBJ1":{"FREQ":"","U_AC":"","I_AC":"","P_AC":"","P_TOTAL":""}}'
reqdata = bytes(reqdata, 'utf-8')
response = urllib.request.urlopen('https://' + ipaddress + '/lala.cgi', data=reqdata, context=ssl._create_unverified_context())
jsondata = json.load(response)



#SENEC: Gesamtleistung (W) Werte -3000  >> 3000
if not (jsondata['PM1OBJ1'] ['P_TOTAL'] is None):
    topic = "openWB/set/evu/W"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['P_TOTAL'],0,0))


#SENEC: Frequenz(Hz) Werte 49.00 >> 50.00
if not (jsondata['PM1OBJ1'] ['FREQ'] is None):
    topic = "openWB/set/evu/HzFrequenz"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['FREQ'],0,2))

#SENEC: Spannung (V) Werte 219.12 >> 223.43
if not (jsondata['PM1OBJ1'] ['U_AC'] [0] is None):
    topic = "openWB/set/evu/VPhase1"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['U_AC'] [0],0,2))
if not (jsondata['PM1OBJ1'] ['U_AC'] [1] is None):
    topic = "openWB/set/evu/VPhase2"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['U_AC'] [1],0,2))
if not (jsondata['PM1OBJ1'] ['U_AC'] [2] is None):
    topic = "openWB/set/evu/VPhase3"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['U_AC'] [2],0,2))

#SENEC: Leistung (W) Werte -2345 >> 3000
if not (jsondata['PM1OBJ1'] ['P_AC'] [0] is None):
    topic = "openWB/set/evu/WPhase1"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['P_AC'] [0],0,0))
if not (jsondata['PM1OBJ1'] ['P_AC'] [1] is None):
    topic = "openWB/set/evu/WPhase2"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['P_AC'] [1],0,0))
if not (jsondata['PM1OBJ1'] ['P_AC'] [2] is None):
    topic = "openWB/set/evu/WPhase3"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['P_AC'] [2],0,0))


#SENEC: Strom (A) Werte 0.88 >> 1.67
if not (jsondata['PM1OBJ1'] ['I_AC'] [0] is None):
    topic = "openWB/set/evu/APhase1"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['I_AC'] [0],0,2))
if not (jsondata['PM1OBJ1'] ['I_AC'] [1] is None):
    topic = "openWB/set/evu/APhase2"
    client.publish(topic, writeVal(jsondata['PM1OBJ1'] ['I_AC'] [1],0,2))
if not (jsondata['PM1OBJ1'] ['I_AC'] [2] is None):
    topic = "openWB/set/evu/APhase3"
    client.publish(topic, writeVal(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":"","GUI_INVERTER_POWER":""}}'
reqdata = bytes(reqdata, 'utf-8')
response = urllib.request.urlopen('https://' + ipaddress + '/lala.cgi', data=reqdata, context=ssl._create_unverified_context())
jsondata = json.load(response)

#SENEC: Batterieleistung (W) Werte -345 (Entladen) >> 1200 (laden)
if not (jsondata['ENERGY'] ['GUI_BAT_DATA_POWER'] is None):
    topic = "openWB/set/houseBattery/W"
    client.publish(topic, writeVal(jsondata['ENERGY'] ['GUI_BAT_DATA_POWER'],0,0))

#SENEC: Fuellmenge in Prozent Werte 10 >> 55 >> 100
if not (jsondata['ENERGY'] ['GUI_BAT_DATA_FUEL_CHARGE'] is None):
    topic = "openWB/set/houseBattery/%Soc"
    client.publish(topic, writeVal(jsondata['ENERGY'] ['GUI_BAT_DATA_FUEL_CHARGE'],0,0))

#SENEC: Leistung Wechselrichter in (W) Werte
if not (jsondata['ENERGY'] ['GUI_INVERTER_POWER'] is None):
    topic = "openWB/set/pv/1/W"
    client.publish(topic, writeVal(jsondata['ENERGY'] ['GUI_INVERTER_POWER'],0,0))

# Client beenden
client.disconnect()
so müssen keine daten mehr auf http abfrage gestellt werden sondern das script egal ob auf der openwb ausgeführt oder wo anders sendet die daten via mqtt direkt an die openwb. Damit ist auch keine RAMdisk mehr nötig.
Im nächsten Step werde ich noch die Berechnung der kWh mit einbauen, das dauert aber leide noch ein paar Tage.
@matzeeg3: Kannst du dafür eine kleine Anleitung basteln? Das Script kann auch auf einem Raspi im Heimnetzwerk laufen, korrekt?
VG Benny
Moin Benny ja genau das ist erstmal egal wo das Script läuft, bei mir auch auf einem anderen Pi im Netzwerk.
Folgende schritte sind zu tun:
[*]Prüfen der Python Version "python --version" hier sollte 3.9 oder höher stehen.
[*]Installieren des Python Moduls "pip3 install paho-mqtt"
[*]Script auf den PI bringen "nano scriptname.py" und den inhalt hier raus kopieren. Achtung ich hab das Script nochmal angepasst, da ich ein Fehler in den Ampre Werten hatte
[*]Senec IP und Broker IP anpassen (Broker IP wäre dann die openWB)
[*]crontab -e aufrufen und folgendes nach Anpassung des Path ganz unten hineinkopieren:

Code: Alles auswählen

* * * * * python3 /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 5 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 1 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 15 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 20 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 25 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 30 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 35 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 40 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 45 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 50 && python /path-to-script/senec.py >/dev/null 2>&1
* * * * * sleep 55 && python /path-to-script/senec.py >/dev/null 2>&1
Und das war es dann auch schon, alle Werte werden im 5 Sekunden Takt aktuallisiert. Für den gesamten Prozess wird kein "sudo" benötigt.
In manchen Fällen (wenn mehrere Python Versionen installiert sind muss im crontab "python" durch "python3" ersetzt werden.
Ich hoffe das hilft.
Habe das Script nach deiner Anleitung zum Laufen bekommen. Danke nochmal :-)
Zwei kleine Hinweise, falls andere Leidensgenossen im Forum deine Anleitung nutzen wollen:
- das Script muss noch über den Befehl "sudo chmod 777 script.py" ausführbar gemacht werden
- der dritte Eintrag für die Crontab ist nicht ganz korrekt, es muss sleep 10 && ... heißen (nicht sleep 1 &&)

Trotzdem tolle Arbeit, danke für deine Mühen!
VG Benny
Verwendete Box: openWB series2 Standard+
matzeeg3
Beiträge: 40
Registriert: Fr Mai 07, 2021 6:33 am

Re: SENEC Modul

Beitrag von matzeeg3 »

Moin danke fürs finden der Flüchtigkeitsfehler. Ich werde das noch in ein git repo gießen und dann dort auch die Anleitung mit rein nehmen.
bennysweb
Beiträge: 5
Registriert: Mo Dez 19, 2022 5:59 pm

Re: SENEC Modul

Beitrag von bennysweb »

Ich benötige doch nochmal Hilfe bei deinem Script @matzeeg3. Leider werden die Werte für PV-Erzeugung (GUI_INVERTER_POWER) nicht korrekt per MQTT übertragen. Habe erst gedacht, die 5 Sekunden-Intervalle sind zu hoch, aber auch bei einem 10 Sekunden-Intervall tritt das Problem auf. Laut MQTT-Log in der OpenWB kommen alle anderen Werte an, nur eben leider nicht die PV-Erzeugung.
Bildschirmfoto 2023-09-10 um 12.39.02.png
Verwendete Box: openWB series2 Standard+
TorstenFranz
Beiträge: 47
Registriert: Do Sep 03, 2020 12:24 pm

Re: SENEC Modul

Beitrag von TorstenFranz »

Hallo Team!

Ich habe leider nicht diese Erfahrung und dieses Wissen im Programmieren wie ihr. Ich habe 2020 einfach nach Anleitung von cjungde, wie sie am Anfang dieses Senec-Modul-Themas beschrieben ist, abgeschrieben. Seither hat alles super funktioniert.
Seit dem UpDate von Senec geht nun nichts mehr.
Ich kann leider nicht zuordnen wo ihr diese ganzen Änderungen getätigt habt.

Es wäre echt super wenn jemand von euch eine "Schritt für Schritt Anleitung" hier reinsetzen könnte, wie man OpenWB mit dem Senec wieder zum Laufen bekommt.

Ich wäre echt Dankbar.
LG
Torsten
matzeeg3
Beiträge: 40
Registriert: Fr Mai 07, 2021 6:33 am

Re: SENEC Modul

Beitrag von matzeeg3 »

bennysweb hat geschrieben: So Sep 10, 2023 10:40 am Ich benötige doch nochmal Hilfe bei deinem Script @matzeeg3. Leider werden die Werte für PV-Erzeugung (GUI_INVERTER_POWER) nicht korrekt per MQTT übertragen. Habe erst gedacht, die 5 Sekunden-Intervalle sind zu hoch, aber auch bei einem 10 Sekunden-Intervall tritt das Problem auf. Laut MQTT-Log in der OpenWB kommen alle anderen Werte an, nur eben leider nicht die PV-Erzeugung.

Bildschirmfoto 2023-09-10 um 12.39.02.png
Fehler gefunden. Am Ende des Scripts müsste vor

Code: Alles auswählen

client.disconnect()
noch folgendes hinzugefügt werden:

Code: Alles auswählen

time.sleep (1)
da der MQTT client sonst schneller beendet als er die daten weg bekommt.

Das Repo ist gerade am entstehen unter:
https://github.com/matzeeg3/openwb_senec/tree/main
Antworten