pyFroniusReg/examples/force_charge.py

47 lines
1.4 KiB
Python
Raw Normal View History

2024-10-08 16:32:55 +11:00
#!/usr/bin/env python3
2024-10-14 20:26:50 +11:00
from pyfroniusreg import gen24_registers
2024-10-08 16:32:55 +11:00
from pymodbus.client.tcp import ModbusTcpClient
fronius1 = ModbusTcpClient("172.19.107.211", port=502, timeout=10)
fronius1.connect()
2024-10-16 21:33:28 +11:00
soc = gen24_registers.scaledChaState.get(fronius1)
2024-10-08 16:32:55 +11:00
print(" SOC: %s%%" % soc)
2024-10-14 20:26:50 +11:00
discharge = gen24_registers.scaledOutWRte.get(fronius1)
2024-10-08 16:32:55 +11:00
print("Pre DRate: %d%%" % discharge)
2024-10-14 20:26:50 +11:00
charge = gen24_registers.scaledInWRte.get(fronius1)
2024-10-08 16:32:55 +11:00
print("Pre CRate: %d%%" % charge)
2024-10-16 21:33:28 +11:00
mode = gen24_registers.StorCtl_Mod.get(fronius1)
2024-10-08 16:32:55 +11:00
print("Pre Mode: %d" % mode)
2024-10-25 11:13:33 +11:00
timeout = gen24_registers.InOutWRte_RvrtTms.get(fronius1)
print ("Timer: %d" % timeout)
# Set timer for 2 minutes
err = gen24_registers.InOutWRte_RvrtTms.set(fronius1, 120)
2024-10-08 16:32:55 +11:00
# This should be 'limit discharge' mode
2024-10-11 15:00:51 +11:00
print("Setting control mode to limit discharge")
2024-10-16 21:33:28 +11:00
err = gen24_registers.StorCtl_Mod.set(fronius1, 2)
2024-10-11 15:00:51 +11:00
2024-10-08 16:32:55 +11:00
# Charge battery at a rate from -2% discharge to 100% charge
# as a percentage of the MaxChaRte, which in our case is 25600W
2024-10-11 15:00:51 +11:00
print("Setting discharge rate to -10%")
2024-10-14 20:26:50 +11:00
err = gen24_registers.scaledOutWRte.set(fronius1, int(-10))
2024-10-11 15:00:51 +11:00
print("Setting charge rate to 100%")
2024-10-14 20:26:50 +11:00
err = gen24_registers.scaledInWRte.set(fronius1, int(100))
2024-10-08 16:32:55 +11:00
2024-10-14 20:26:50 +11:00
discharge = gen24_registers.scaledOutWRte.get(fronius1)
2024-10-08 16:32:55 +11:00
print("Post DRate: %d%%" % discharge)
2024-10-14 20:26:50 +11:00
charge = gen24_registers.scaledInWRte.get(fronius1)
2024-10-08 16:32:55 +11:00
print("Post CRate: %d%%" % charge)
2024-10-16 21:33:28 +11:00
mode = gen24_registers.StorCtl_Mod.get(fronius1)
2024-10-08 16:32:55 +11:00
print("Post Mode: %d" % mode)