@@ -104,13 +104,25 @@ def get_battery_current_voltage(self):
104
104
return currentvoltage
105
105
106
106
def get_battery_current_wh (self ):
107
- soc = self .get_soc ()
107
+ soc = self .get_soc () or 0
108
108
full_capacity = (self .get_battery_capacity () / soc ) * 100 if soc > 0 else 0.0
109
109
battery_capacity_wh = full_capacity * 55.20
110
110
battery_current_wh = ((soc or 0 ) / 100 ) * battery_capacity_wh
111
111
self .logger .log .debug (f"{ self ._name } Batterie Current wh: { battery_current_wh } Wh" )
112
112
return battery_current_wh
113
113
114
+ def get_battery_full_wh (self ):
115
+ soc = self .get_soc () or 0
116
+ full_capacity = (self .get_battery_capacity () / soc ) * 100 if soc > 0 else 0.0
117
+ battery_capacity_wh = full_capacity * 55.20
118
+ self .logger .log .debug (f"{ self ._name } Batterie Full wh: { battery_capacity_wh } Wh" )
119
+ return battery_capacity_wh
120
+
121
+ def get_battery_min_wh (self ):
122
+ min_soc_limit = self .get_battery_minimum_soc_limit () or 0
123
+ battery_capacity_wh = self .get_battery_full_wh ()
124
+ return min_soc_limit / 100 * battery_capacity_wh
125
+
114
126
def get_battery_minimum_soc_limit (self ):
115
127
minimumsoclimit = self ._process_result (self .subsribers .get ('Battery' , 'MinimumSocLimit' ))
116
128
self .logger .log .debug (f"{ self ._name } Batterie MinimumSocLimit: { minimumsoclimit } %" )
@@ -128,12 +140,12 @@ def get_battery_installed_capacity(self):
128
140
129
141
def get_soc (self ):
130
142
soc = self ._process_result (self .subsribers .get ('Battery' , 'Soc' ))
131
- self .logger .log .info (f"{ self ._name } SOC: { soc } %" )
143
+ self .logger .log .debug (f"{ self ._name } SOC: { soc } %" )
132
144
return soc
133
145
134
146
def get_active_soc_limit (self ):
135
147
soc = self ._process_result (self .subsribers .get ('Control' , 'ActiveSocLimit' ))
136
- self .logger .log .info (f"{ self ._name } ActiveSocLimit: { soc } %" )
148
+ self .logger .log .debug (f"{ self ._name } ActiveSocLimit: { soc } %" )
137
149
return soc
138
150
139
151
def get_scheduler_soc (self ):
@@ -190,19 +202,15 @@ def get_version(self):
190
202
version = self ._process_result (self .subsribers .get ('Firmware' , 'Version' ))
191
203
return version
192
204
193
- def _gridmeters (self ):
194
- with MqttClient (
195
- self .mqtt_config ) as mqtt : # Hier wird die Verbindung hergestellt und im Anschluss automatisch geschlossen
196
- base_topic = f'N/{ self .unit_id } /grid'
197
- discovery_topic = f"{ base_topic } /#"
198
- mqtt .subscribe (self .gridmeters , discovery_topic )
205
+ def _gridmeters (self , mqtt ):
206
+ base_topic = f'N/{ self .unit_id } /grid'
207
+ discovery_topic = f"{ base_topic } /#"
208
+ mqtt .subscribe (self .gridmeters , discovery_topic )
199
209
200
- def _inverters (self ):
201
- with MqttClient (
202
- self .mqtt_config ) as mqtt : # Hier wird die Verbindung hergestellt und im Anschluss automatisch geschlossen
203
- base_topic = f'N/{ self .unit_id } /pvinverter'
204
- discovery_topic = f"{ base_topic } /#"
205
- mqtt .subscribe (self .inverters , discovery_topic )
210
+ def _inverters (self , mqtt ):
211
+ base_topic = f'N/{ self .unit_id } /pvinverter'
212
+ discovery_topic = f"{ base_topic } /#"
213
+ mqtt .subscribe (self .inverters , discovery_topic )
206
214
207
215
def _get_battery_instance (self , mqtt ):
208
216
try :
@@ -269,10 +277,16 @@ def _get_vrm_broker_url(self):
269
277
return "mqtt{}.victronenergy.com" .format (broker_index )
270
278
271
279
def _get_data (self ):
272
- self ._inverters ()
273
- self ._gridmeters ()
274
280
with MqttClient (
275
- self .mqtt_config ) as mqtt : # Hier wird die Verbindung hergestellt und im Anschluss automatisch geschlossen
281
+ self .mqtt_config ) as mqtt :
282
+ self ._gridmeters (mqtt )
283
+ with MqttClient (
284
+ self .mqtt_config ) as mqtt :
285
+ self ._inverters (mqtt )
286
+
287
+ with MqttClient (
288
+ self .mqtt_config ) as mqtt :
289
+
276
290
instance = self ._get_battery_instance (mqtt )
277
291
topics_to_subscribe = [
278
292
f"Schedule:N/{ self .unit_id } /settings/0/Settings/CGwacs/BatteryLife/Schedule/Charge/0/Day" ,
0 commit comments