Skip to content

Commit e4b372b

Browse files
authored
Merge pull request #2761 from okaegi/smart192
pv Leistung und chargestatus
2 parents 641fb9b + 44c405a commit e4b372b

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

packages/smarthome/smartbase.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self) -> None:
3737
# 30 = gestartet um fertig bis zu erreichen
3838
# default 10
3939
self._first_run = 1
40+
self.chargestatus = False
4041
self.device_nummer = 0
4142
self.temp0 = '300'
4243
self.temp1 = '300'
@@ -541,18 +542,6 @@ def conditions(self, speichersoc: int) -> None:
541542
if ((self.device_canswitch == 0) or
542543
(self.device_manual == 1)):
543544
return
544-
file_charge = '/var/www/html/openWB/ramdisk/llkombiniert'
545-
testcharge = 0.0
546-
try:
547-
if os.path.isfile(file_charge):
548-
with open(file_charge, 'r') as f:
549-
testcharge = float(f.read())
550-
except Exception:
551-
pass
552-
if testcharge <= 1000:
553-
chargestatus = 0
554-
else:
555-
chargestatus = 1
556545
work_ausschaltschwelle = self._device_ausschaltschwelle
557546
work_ausschaltverzoegerung = self._device_ausschaltverzoegerung
558547
local_time = datetime.now(timezone.utc).astimezone()
@@ -777,8 +766,8 @@ def conditions(self, speichersoc: int) -> None:
777766
log.info("(" + str(self.device_nummer) + ") " +
778767
self.device_name +
779768
" Soll reduziert/abgeschaltet werden" +
780-
" bei Ladung, pruefe " + str(testcharge))
781-
if chargestatus == 1:
769+
" bei Ladung, pruefe " + str(self.chargestatus))
770+
if self.chargestatus:
782771
log.info("(" + str(self.device_nummer) + ") " +
783772
self.device_name +
784773
" Ladung läuft, pruefe Mindestlaufzeit")
@@ -850,8 +839,8 @@ def conditions(self, speichersoc: int) -> None:
850839
log.info("(" + str(self.device_nummer) + ") " +
851840
self.device_name +
852841
" Soll nicht eingeschaltet werden bei" +
853-
" Ladung, pruefe " + str(testcharge))
854-
if chargestatus == 1:
842+
" Ladung, pruefe " + str(self.chargestatus))
843+
if self.chargestatus:
855844
log.info("(" + str(self.device_nummer) + ") "
856845
+ self.device_name + " Ladung läuft, " +
857846
"wird nicht eingeschaltet")

packages/smarthome/smartcommon.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def on_message(client, userdata, msg) -> None:
110110
log.warning(" Skipped msg " + msg.topic + " Value " + value)
111111

112112

113-
def getdevicevalues(uberschuss: int, uberschussoffset: int, pvwatt: int) -> None:
113+
def getdevicevalues(uberschuss: int, uberschussoffset: int, pvwatt: int, chargestatus: bool) -> None:
114114
global mydevices
115115
totalwatt = 0
116116
totalwattot = 0
@@ -122,6 +122,7 @@ def getdevicevalues(uberschuss: int, uberschussoffset: int, pvwatt: int) -> None
122122
mqtt_all = {}
123123
for mydevice in mydevices:
124124
mydevice.pvwatt = pvwatt
125+
mydevice.chargestatus = chargestatus
125126
mydevice.getwatt(uberschuss, uberschussoffset)
126127
watt = mydevice.newwatt
127128
wattk = mydevice.newwattk
@@ -390,7 +391,8 @@ def resetmaxeinschaltdauerfunc() -> None:
390391
resetmaxeinschaltdauer = 0
391392

392393

393-
def loadregelvars(wattbezug: int, speicherleistung: int, speichersoc: int, pvwatt: int) -> Tuple[int, int]:
394+
def loadregelvars(wattbezug: int, speicherleistung: int, speichersoc: int,
395+
pvwatt: int, chargestatus: bool) -> Tuple[int, int]:
394396
global maxspeicher
395397
global mydevices
396398
uberschuss = wattbezug + speicherleistung
@@ -400,7 +402,7 @@ def loadregelvars(wattbezug: int, speicherleistung: int, speichersoc: int, pvwat
400402
log.info("Uberschuss: " + str(uberschuss) +
401403
" Uberschuss mit Offset: " + str(uberschussoffset) + " Pv: " + str(pvwatt))
402404
log.info("Speicher Entladung(-)/Ladung(+): " +
403-
str(speicherleistung) + " SpeicherSoC: " + str(speichersoc))
405+
str(speicherleistung) + " SpeicherSoC: " + str(speichersoc) + " Ladung: " + str(chargestatus))
404406
reread = 0
405407
try:
406408
with open(bp+'/ramdisk/rereadsmarthomedevices', 'r') as value:
@@ -449,16 +451,17 @@ def initparam(inpcg: str, inpcs: str, inpsdevstat: str, inpsglobstat: str, inpto
449451
mqttport = inpport
450452

451453

452-
def mainloop(wattbezug: int, speicherleistung: int, speichersoc: int, pvwatt: int = 0) -> None:
454+
def mainloop(wattbezug: int, speicherleistung: int, speichersoc: int, pvwatt: int = 0,
455+
chargestatus: bool = False) -> None:
453456
global firststart
454457
if firststart:
455458
readmq()
456459
firststart = False
457460
mqtt_man = {}
458461
sendmess = 0
459-
uberschuss, uberschussoffset = loadregelvars(wattbezug, speicherleistung, speichersoc, pvwatt)
462+
uberschuss, uberschussoffset = loadregelvars(wattbezug, speicherleistung, speichersoc, pvwatt, chargestatus)
460463
resetmaxeinschaltdauerfunc()
461-
getdevicevalues(uberschuss, uberschussoffset, pvwatt)
464+
getdevicevalues(uberschuss, uberschussoffset, pvwatt, chargestatus)
462465
conditions(speichersoc)
463466
# do the manual stuff
464467
for i in range(1, (numberOfSupportedDevices+1)):

runs/smarthomemq.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from smarthome.smartcommon import mainloop, initparam
33
import time
44
import logging
5+
import os
56
log = logging.getLogger("smarthome")
67
# openwb 1.9 spec
78
mqttcg = 'openWB/config/get/SmartHome/'
@@ -99,5 +100,24 @@ def checkbootdone() -> int:
99100
log.warning("Fehler beim Auslesen der Ramdisk (wattbezug):"
100101
+ str(e))
101102
wattbezug = 0
102-
mainloop(wattbezug, speicherleistung, speichersoc)
103+
try:
104+
with open(bp+'/ramdisk/pvallwatt', 'r') as value:
105+
pvwatt = int(float(value.read())) * -1
106+
except Exception as e:
107+
log.warning("Fehler beim Auslesen der Ramdisk (pvallwatt):"
108+
+ str(e))
109+
pvwatt = 0
110+
file_charge = '/var/www/html/openWB/ramdisk/llkombiniert'
111+
testcharge = 0.0
112+
try:
113+
if os.path.isfile(file_charge):
114+
with open(file_charge, 'r') as f:
115+
testcharge = float(f.read())
116+
except Exception:
117+
pass
118+
if testcharge <= 1000:
119+
chargestatus = False
120+
else:
121+
chargestatus = True
122+
mainloop(wattbezug, speicherleistung, speichersoc, pvwatt, chargestatus)
103123
time.sleep(5)

0 commit comments

Comments
 (0)