Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: simcount looses counter values on reboot #2450

Merged
merged 1 commit into from
Oct 17, 2022

Conversation

yankee42
Copy link
Contributor

@okaegi hat mir geschrieben, dass er festgestellt hat, dass in #2449 bei einem Reboot die Zählerstände verloren gehen. Das habe ich mir dann angesehen und dieser PR soll das beheben.

Der ganz alte Code hat bei fehlendem Sim-Zählerstand diesen aus dem Broker geholt:

openWB/loadvars.sh

Lines 1217 to 1222 in f4c822a

importtemp=$(timeout 4 mosquitto_sub -t openWB/housebattery/WHImported_temp)
if ! [[ $importtemp =~ $ra ]] ; then
importtemp="0"
fi
openwbDebugLog "MAIN" 0 "loadvars read openWB/housebattery/WHImported_temp from mosquito $importtemp"
echo $importtemp > /var/www/html/openWB/ramdisk/speicherwatt0pos

Die aktuelle Logik beherrscht das theoretisch auch:

def read_or_restore(name: str) -> float:
# For historic reasons, the SimCount stored state uses Watt-seconds instead of Watt-hours -> / 3600:
try:
return ramdisk_read_float(prefix + name) / 3600
except Exception:
return restore_value(name, prefix) / 3600

Der Code wird allerdings nur dann aufgerufen, wenn die sec0-Datei existiert:

try:
timestamp = ramdisk_read_float(prefix + "sec0")
except FileNotFoundError:
return None

Bei einem kompletten reboot geht die sec0-Datei allerdings ebenso verloren. In dem Fall wird SimCounterStoreRamdisk#initialize aufgerufen und diese Funktion interessiert sich für den Umstand nicht.

Das das ganze System immernoch nicht übetrieben übersichtlich ist habe ich den ganzen Code noch etwas refactored und aufegräumt.

Das ganze ist noch ungetestet.

@okaegi
Copy link
Contributor

okaegi commented Oct 16, 2022

2022-10-16 16:33:24: PID: 3649: soc.modules.common.store._api: Saving BatState(imported=860240282650021.2, soc=87.0, power=165, exported=1654793914027.7444)
2022-10-16 16:33:24: PID: 3649: modules.common.simcount._simcounter_store: read from broker: openWB/housebattery/WHExport_temp=1654793914027.7444
2022-10-16 16:33:24: PID: 3649: modules.common.simcount._simcounter_store: read from broker: openWB/housebattery/WHImported_temp=860240282650021.2
2022-10-16 16:33:24: PID: 3649: modules.common.simcount._simcount: No previous state found. Starting new simulation.

2022-10-16 16:39:15: PID: 3603: modules.e3dc.bat: Ip: 192.168.1.245, read_ext 1 pv_other False
2022-10-16 16:39:15: PID: 3603: modules.e3dc.bat: soc 87 power 720 pv 0 pv_external -3205 c ip 1
2022-10-16 16:39:15: PID: 3603: modules.common.simcount._simcount: No previous state found. Starting new simulation.
2022-10-16 16:39:15: PID: 3603: modules.common.simcount._simcounter_store: read from broker: openWB/housebattery/WHImported_temp=3.0968650175402004e+18
2022-10-16 16:39:15: PID: 3603: modules.common.simcount._simcounter_store: read from broker: openWB/housebattery/WHExport_temp=5957258090499880.0
2022-10-16 16:39:15: PID: 3603: soc.modules.common.store._api: Saving BatState(imported=3.0968650175402004e+18, soc=87.0, exported=5957258090499880.0, power=720)

@okaegi
Copy link
Contributor

okaegi commented Oct 16, 2022

Übernimmt nun Zählerstände vom Broker, bringt die Zählerstände aber um Faktoren durcheinenander
2022-10-16 16:33:24: PID: 3649: soc.modules.common.store._api: Saving BatState(imported=860240282650021.2, soc=87.0, power=165, exported=1654793914027.7444)
2022-10-16 16:33:24: PID: 3649: modules.common.simcount._simcounter_store: read from broker: openWB/housebattery/WHExport_temp=1654793914027.7444
2022-10-16 16:33:24: PID: 3649: modules.common.simcount._simcounter_store: read from broker: openWB/housebattery/WHImported_temp=860240282650021.2
2022-10-16 16:33:24: PID: 3649: modules.common.simcount._simcount: No previous state found. Starting new simulation.

2022-10-16 16:39:15: PID: 3603: modules.e3dc.bat: Ip: 192.168.1.245, read_ext 1 pv_other False
2022-10-16 16:39:15: PID: 3603: modules.e3dc.bat: soc 87 power 720 pv 0 pv_external -3205 c ip 1
2022-10-16 16:39:15: PID: 3603: modules.common.simcount._simcount: No previous state found. Starting new simulation.
2022-10-16 16:39:15: PID: 3603: modules.common.simcount._simcounter_store: read from broker: openWB/housebattery/WHImported_temp=3.0968650175402004e+18
2022-10-16 16:39:15: PID: 3603: modules.common.simcount._simcounter_store: read from broker: openWB/housebattery/WHExport_temp=5957258090499880.0
2022-10-16 16:39:15: PID: 3603: soc.modules.common.store._api: Saving BatState(imported=3.0968650175402004e+18, soc=87.0, exported=5957258090499880.0, power=720)

@yankee42 yankee42 force-pushed the simcount-fix-reboot branch from e3f8db7 to c24546e Compare October 16, 2022 15:26
@yankee42
Copy link
Contributor Author

Potenziell gefixt, versuch jetzt nochmal.

(Übrigens: Auch die Logs sehen in triple-backticks (```) besser aus)

@okaegi
Copy link
Contributor

okaegi commented Oct 16, 2022

Sieht nun besser aus

2022-10-16 17:52:36: PID: 3738: modules.e3dc.counter: Evu counter found, save 40128
2022-10-16 17:52:36: PID: 3738: modules.common.simcount._simcount: No previous state found. Starting new simulation.
2022-10-16 17:52:36: PID: 3738: modules.common.simcount._simcounter_store: read from broker: openWB/evu/WHImported_temp=1129.7325693188338
2022-10-16 17:52:37: PID: 3738: modules.common.simcount._simcounter_store: read from broker: openWB/evu/WHExport_temp=4611.008124095025
2022-10-16 17:52:37: PID: 3738: soc.modules.common.store._api: Saving CounterState(currents=[4.626086956521739, -1.982608695652174, -2.639130434782609], voltages=[230.0, 230.0, 230.0], power_factors=[0.0, 0.0, 0.0], powers=[1064, -456, -607], power=1, imported=0.313814602588565, frequency=50, exported=1.2808355900263957)
2022-10-16 17:52:37: PID: 3738: modules.e3dc.counter: Update completed successfully

nach reboot

2022-10-16 17:57:07: PID: 3636: legacy run server: Completed running command in 0.16s: ["modules.e3dc.device","counter","192.168.1.245","none","1","none","1"]
2022-10-16 17:57:07: PID: 3636: modules.e3dc.counter: Update completed successfully
2022-10-16 17:57:07: PID: 3636: soc.modules.common.store._api: Saving CounterState(voltages=[230.0, 230.0, 230.0], power=-1, imported=0.9688309054190518, exported=1.287082687809858, currents=[4.739130434782608, -2.0434782608695654, -2.7], powers=[1090, -470, -621], frequency=50, power_factors=[0.0, 0.0, 0.0])
2022-10-16 17:57:07: PID: 3636: modules.common.simcount._simcounter_store: read from broker: openWB/evu/WHExport_temp=4633.4976761154885
2022-10-16 17:57:07: PID: 3636: modules.common.simcount._simcounter_store: read from broker: openWB/evu/WHImported_temp=3487.7912595085863
2022-10-16 17:57:07: PID: 3636: modules.common.simcount._simcount: No previous state found. Starting new simulation.
2022-10-16 17:57:07: PID: 3636: modules.e3dc.counter: Evu counter found, save 40128
2022-10-16 17:57:07: PID: 3636: modules.e3dc.counter: register: 40128, powers [1, 1090, -470, -621]
2022-10-16 17:57:07: PID: 3636: modules.e3dc.counter: Beginning EVU update
2022-10-16 17:57:07: PID: 3636: soc.modules.common.component_context: Update Komponente ['e3dc Zähler']
2022-10-16 17:57:07: PID: 3636: modules.e3dc.device: Start device reading {'component0': <modules.e3dc.counter.E3dcCounter object at 0x74e9f090>}
2022-10-16 17:57:07: PID: 3636: modules.e3dc.device: e3dc id: 1
2022-10-16 17:57:07: PID: 3636: modules.e3dc.device: e3dc pvmodul: none
2022-10-16 17:57:07: PID: 3636: modules.e3dc.device: e3dc read_ext: 1
2022-10-16 17:57:07: PID: 3636: modules.e3dc.device: e3dc IP-Adresse2: none
2022-10-16 17:57:07: PID: 3636: modules.e3dc.device: e3dc IP-Adresse1: 192.168.1.245
2022-10-16 17:57:07: PID: 3636: legacy run server: Received command ["modules.e3dc.device","counter","192.168.1.245","none","1","none","1"]
'

@yankee42
Copy link
Contributor Author

Hast du noch zur Sicherheit ein Ausschnitt von einem weiteren Durchlauf, damit wir sehen, dass das ab dem zweiten Durchlauf der in der Ramdisk gespeicherte Status gefunden und korrekt geladen wird?

@okaegi
Copy link
Contributor

okaegi commented Oct 16, 2022

2022-10-16 17:57:33: PID: 3636: legacy run server: Received command ["modules.e3dc.device","counter","192.168.1.245","none","1","none","1"]
2022-10-16 17:57:33: PID: 3636: modules.e3dc.device: e3dc IP-Adresse1: 192.168.1.245
2022-10-16 17:57:33: PID: 3636: modules.e3dc.device: e3dc IP-Adresse2: none
2022-10-16 17:57:33: PID: 3636: modules.e3dc.device: e3dc read_ext: 1
2022-10-16 17:57:33: PID: 3636: modules.e3dc.device: e3dc pvmodul: none
2022-10-16 17:57:33: PID: 3636: modules.e3dc.device: e3dc id: 1
2022-10-16 17:57:33: PID: 3636: modules.e3dc.device: Start device reading {'component0': <modules.e3dc.counter.E3dcCounter object at 0x73cac3d0>}
2022-10-16 17:57:33: PID: 3636: soc.modules.common.component_context: Update Komponente ['e3dc Zähler']
2022-10-16 17:57:33: PID: 3636: modules.e3dc.counter: Beginning EVU update
2022-10-16 17:57:33: PID: 3636: modules.e3dc.counter: foundreg: 40128, powers [1, 1096, -467, -620]
2022-10-16 17:57:33: PID: 3636: modules.common.simcount._simcount: Previous state: SimCounterState(power=-1.0, imported=0.9688309054190518, exported=1.287082687809858, timestamp=1665935827.0652406)
2022-10-16 17:57:33: PID: 3636: modules.common.simcount._calculate: time passed: 0.00745492, power1: -1, power2: 9
2022-10-16 17:57:33: PID: 3636: modules.common.simcount._calculate: power changed sign. Total energy: 0.0298197, exported energy: -0.000372746
2022-10-16 17:57:33: PID: 3636: modules.common.simcount._simcount: imported: 0.0301924 Wh, exported: 0.000372746 Wh, new state: SimCounterState(power=9, imported=0.9990233314747216, exported=1.2874554338105453, timestamp=1665935853.9029527)
2022-10-16 17:57:33: PID: 3636: soc.modules.common.store._api: Saving CounterState(voltages=[230.0, 230.0, 230.0], power=9, imported=0.9990233314747216, exported=1.2874554338105453, currents=[4.765217391304348, -2.0304347826086957, -2.6956521739130435], powers=[1096, -467, -620], frequency=50, power_factors=[0.0, 0.0, 0.0])
2022-10-16 17:57:33: PID: 3636: modules.e3dc.counter: Update completed successfully
2022-10-16 17:57:33: PID: 3636: legacy run server: Completed running command in 0.06s: ["modules.e3dc.device","counter","192.168.1.245","none","1","none","1"]

@yankee42
Copy link
Contributor Author

OK, genau so soll es aussehen :-).

@LKuemmel LKuemmel merged commit 6ea98ab into snaptec:master Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants