Spikes im Graphen / Invalide Log-Daten

Fragen zur Nutzung, Features, usw..
Antworten
Benutzeravatar
Thomas aus W
Beiträge: 845
Registriert: Mi Apr 01, 2020 4:00 pm
Been thanked: 2 times

Spikes im Graphen / Invalide Log-Daten

Beitrag von Thomas aus W »

Bei mir kommt es hin und wieder vor, dass der Raspi die Mod-Bus-verbindung zum Zähler verliert. Das heilt sich nach einer Weile von selbst, aber im Log wir dann in der Zeit der Zählerstand '0' eingetragen.

Bei der Auswertung (für den Graphen) wird am Ende '0' Einträge im Log der im nächsten Eintrag stehende aktuelle Zählerstand als "geladene Energie in den letzten 5 Minuten" angesehen. Da meine OWB schon 4½ Jahre alt ist stehen in meinem Zähler 12MWh, was zu einer Ladeleistung von 144GW umgerechnet wird...

Ich habe ein Python-Script geschrieben, dass eine Datei im daily-log berichtigt in dem es die Lücken sucht, und die 0-en durch interpolierte Werte ersetzt. Es passt auch die Summe der Ladepunkte an Das passt bei PV-Laden natürlich nur so mittel, aber bei allen anderen Lademodi verzerrt es die Ladeleistung nur, wenn der Fehler länger auf trat als die Ladung dauerte.

Probleme über den Tageswechsel berücksichtigt das Script aktuell nicht.

Es legt eine Sicherheitskopie der bearbeiteten Datei an.

Code: Alles auswählen

#!/usr/bin/env python3

### 
## fix charge point data in daily log of OWB software 2.x
## call: python3 fix-log.py [log-file]
## 
## background:
##   in rare cases the OWB losed ModBus connection to the power meter
##   in that case it logs 0 as the current meter value
##   in turn when OWB reestablishes the connection the current meter value
##   is theaded as charged energy in the last 5 minuts by OWBs calculation 
##   routines leading to spikes in the log graphs and most likely wrong 
##   calculated statistics
##
## function:
##   updates entries with missing chargepoint counter value (cpX:imported=0)
##   and the value of the cp:all:imported of the same log entry with 
##   interpolated values
## 
## limitations:
##   missing Values in the first and/or the last log entry are not expected
##   the calculation will be wrong and an exception may occur!
##
## TODO:
##   add logging support

import json
import sys
file_name=sys.argv[1]

# Read the JSON file
with open(file_name, 'r') as file:
    content = json.load(file)
    data = content["entries"]

with open(file_name+'.safe', 'w') as file:
    json.dump(content, file)#, indent=4)

range_to_fix = {};

for i in range(1, len(data)-2):
   for cp in data[i]['cp']:
      if data[i]['cp'][cp]['imported'] == 0:
         range_to_fix.setdefault(cp,[])
         if 0 <  data[i-1]['cp'][cp]['imported']:
            range_to_fix[cp].append({
               "from":{"index":i,"value": data[i-1]['cp'][cp]['imported']},
               "to":{}
            })
         if 0 <  data[i+1]['cp'][cp]['imported']:
            five_min_average = data[i+1]['cp'][cp]['imported'] - range_to_fix[cp][-1]["from"]['value']
            five_min_average /= (1+i-range_to_fix[cp][-1]["from"]['index'])
            range_to_fix[cp][-1]["to"].update({
               "index":i,"value": five_min_average, "target":data[i+1]['cp'][cp]['imported']
            })

for cp in range_to_fix:
  for fix_range in range_to_fix[cp]:
    print(f"fixing log for {cp} entries {fix_range['from']['index']} to {fix_range['to']['index']}")


for cp in range_to_fix:
  for fix_range in range_to_fix[cp]:
     for i in range(fix_range["from"]["index"],1+fix_range["to"]["index"] ):
        new_val = fix_range['from']['value']+ fix_range['to']['value']*(1+i-fix_range["from"]["index"])
        print(
             f"updating {cp} at {data[i]['date']}"
           + f" from {data[i]['cp'][cp]['imported']}"
           + f" to {new_val} "
           + f" "
        )
        data[i]['cp'][cp]['imported'] = new_val
        data[i]['cp']['all']['imported']+=new_val

# Write the updated JSON back to the file
with open(file_name, 'w') as file:
    json.dump(content, file)#, indent=4)
bye
TW
Benutzeravatar
Thomas aus W
Beiträge: 845
Registriert: Mi Apr 01, 2020 4:00 pm
Been thanked: 2 times

Re: Spikes im Graphen / Invalide Log-Daten

Beitrag von Thomas aus W »

Ich habe noch ein Script geschrieben, dass auch die HomeConsumption im Log anpassen soll, denn nachdem mein Script lief bleibt die gefixte Ladeenergie dem Hausverbrauch zugeordnet.

Das Script macht was es soll, aber die OWB schreibt den nächsten Eintrag auf Basis des alten - nun veralteten - Wertes fort, so das ich nun einen Spike bei der HomeConsuption bekomme. Wie kann ich den verhindern?

Ich habe schon mal im MQTT geschaut, aber nichts passendes gefunden, um den aktuellen HC-Wert zu ändern.

Ich habe auch schon direkt nach der Korrektur einen reboot gemacht, auch das hatte keinen Erfolg.

Wie schaffe ich es, dass die OWB den HC-Wert auf Basis des letzten Werts im Daily-Log weiter führt?

bye
TW
Antworten