Skip to content

Commit 0bd8fe0

Browse files
committed
PDayTotal vom Modbus Register 30517
1 parent c7a057d commit 0bd8fe0

File tree

2 files changed

+31
-33
lines changed

2 files changed

+31
-33
lines changed

pv/sma/sma.py

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import sys
1010

1111
import jsons
12-
import requests
1312

1413

1514
class SMA:
@@ -51,6 +50,7 @@ def open(self):
5150
registers = [
5251
30001, # 30001 SMA.Modbus.Profile (Versionsnummer SMA Modbus-Profil) 1304
5352
30053, # 30053 Nameplate.Model (Gerätetyp) Unknown Value 19051
53+
30517, # 30517 Metering.DyWhOut
5454
30769, # 30769 DcMs.Amp.MPPT1 (DC Strom Eingang MPPT1) 6.521 A
5555
30771, # 30771 DcMs.Vol.MPPT1 (DC Spannung Eingang MPPT1) 462.00 V
5656
30773, # 30773 DcMs.Watt.MPPT1 (DC Leistung Eingang MPPT1) 3 kW
@@ -66,7 +66,7 @@ def open(self):
6666
for register in registers:
6767
self.wrmodbus.poll_register(register)
6868
print(f"Poll Register: {register}")
69-
69+
7070
# TODO Read self.PwrLastDayCounter from somewhere
7171

7272
def close(self):
@@ -99,41 +99,14 @@ def GetAllData(self):
9999
self.pvdata.DevTime = "{:02}.{:02}.{:02}T{:02}:{:02}:{:02}".format(timenow.day, timenow.month, timenow.year, timenow.hour, timenow.minute, timenow.second)
100100
print(f"Time: {self.pvdata.DevTime}")
101101

102-
# Read Total Power Counter from Webpage
103-
PwrDayTot = 0 # Preset with 0
104-
105-
response = requests.get("https://192.168.15.165/dyn/getDashValues.json", verify=False) # , auth=('user', 'password'))
106-
data = response.json()
107-
counter = data["result"]["01B8-xxxxx731"]["6400_0046C300"]["9"][0]["val"]
108-
109-
if self.PwrLastDayCounter == 0:
110-
# self.PwrLastDayTot was not set after program restart
111-
# Try to estimate it
112-
if timenow.hour < 3:
113-
# It is still night time, so set actual counter to last counter
114-
self.PwrLastDayCounter = counter
115-
else:
116-
# TODO: Read from Databse? Read from config?
117-
# To Test it uncomment next lines
118-
# self.PwrLastDayCounter = 170000
119-
# self.lastday = timenow.day
120-
pass
121-
else:
122-
PwrDayTot = counter - self.PwrLastDayCounter
123-
# Reset PwrDayTot if date changes (Time 00:00)
124-
if timenow.day != self.lastday:
125-
self.lastday = timenow.day
126-
self.PwrLastDayCounter = counter
127-
print(f"Counter: {counter}, PwrLastDayCounter: {self.PwrLastDayCounter}, PwrDayTot: {PwrDayTot}")
128-
129102
self.pvdata.ActiveInvCnt = 2 # Len = 0-Inverter count
130103

131104
self.pvdata.ActiveSensorCardCnt = 1 # Len = 0 - Sensorcard Count
132105

133106
self.pvdata.LocalNetStatus = 0 # 1 byte
134107

135-
self.pvdata.PTotal = 0
136-
self.pvdata.PDayTotal = PwrDayTot
108+
self.pvdata.PTotal = self.wrmodbus.available_registers[30775].value
109+
self.pvdata.PDayTotal = self.wrmodbus.available_registers[30517].value
137110

138111
# Nur wenn mindestens 1 Inverter aktiv ist
139112
if(self.pvdata.ActiveInvCnt > 0):
@@ -187,7 +160,6 @@ def GetAllData(self):
187160
self.pvdata.wr[1].IDC = self.wrmodbus.available_registers[30957].value
188161
self.pvdata.wr[1].FAC = self.wrmodbus.available_registers[30803].value
189162

190-
self.pvdata.PTotal = self.wrmodbus.available_registers[30775].value
191163
self.pvdata.Error = "OK" # everything ok, if we reach this line
192164

193165
except BaseException as e:

solarpy-default.cfg

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,29 @@
33
#logfile=./solarpy.log
44
#logbackupcount=3
55

6-
#How to get PV-Data: restapi, ifcardeasy, simulation
6+
# How to get PV-Data: restapi, ifcardeasy, simulation, sma
77
#datasource=ifcardeasy
88
#datasource=restapi
9+
#datasource=sma
910
datasource=simulation
1011

1112
#Only relevant if [program]datasource=ifcardeasy
1213
[fronius]
1314
comport=COM3
1415
baudrate=19200
1516

17+
#Only relevant if [program]datasource=sma
18+
[sma]
19+
ip=192.168.15.165
20+
port=502
21+
unit=3
22+
# TODO: implement the following Parameter
23+
#dashvaluesurl=https://192.168.15.165/dyn/getDashValues.json
24+
#totalcounterjson=01B8-xxxxx731.6400_0046C300.9.0.val
25+
# Set to 0 if you dont have the counter value handy. correct counting takes up to 24h then.
26+
#pwrdaycounterstart=249593
27+
#pwrdaycounterstartdate=2025-05-18
28+
1629
#Only relevant if [program]datasource=restapi
1730
[restapi]
1831
host=http://127.0.0.1
@@ -38,7 +51,20 @@ database=pvtest
3851
#Intervall for saving data in seconds. Set to 0 to turn off saving in intervalls.
3952
interval=120
4053

54+
[influx2]
55+
#set to False to switch influxdb2 feature off
56+
enabled=True
57+
host=192.168.15.238
58+
port=8086
59+
org=private
60+
token=xxxxxxxxxxxxxxxxxxxxhBZYgSQ9pq54QQcccnOhfdD0MajnULYAZezTys_Zjdbc0ixxxxxxxxxxxxxxxxxxxx==
61+
bucket=PVTest
62+
#Intervall for saving data in seconds. Set to 0 to turn off saving in intervalls.
63+
interval=120
64+
65+
4166
[mysql]
67+
#set to False to switch mysql feature off
4268
enabled = True
4369
host=127.0.0.1
4470
port=3306

0 commit comments

Comments
 (0)