Start of peak check script

This commit is contained in:
Paul Warren 2024-10-16 16:50:16 +11:00
parent 6c426b2422
commit 8ddab6f2b2

33
examples/check_peak.py Executable file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env python3
import statistics
from pyfroniusreg import gen24_registers
from pyfroniusreg.froniusreg import RegisterReadError
from datetime import datetime
from pymodbus.client.tcp import ModbusTcpClient
fronius1 = ModbusTcpClient("172.19.107.211", port=502, timeout=10)
fronius1.connect()
current_time = datetime.now()
soc = gen24_registers.scaledStateOfCharge.get(fronius1)
charge_data = []
discharge_data = []
print("Gathering 20 second average of battery Charge")
while( (datetime.now() - current_time).seconds < 20):
charge_data.append(gen24_registers.scaledToBattery.get(fronius1))
discharge_data.append(gen24_registers.scaledFromBattery.get(fronius1))
avg_charge = statistics.mean(charge_data)
avg_discharge = statistics.mean(discharge_data)
print(" Charge: %.2f" % avg_charge)
print("DisCharge: %.2f" % avg_discharge)
print(" SOC: %.2f" % soc)