forked from snaptec/openWB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnurpv.sh
executable file
·360 lines (346 loc) · 15 KB
/
nurpv.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#!/bin/bash
# NUR PV Uberschussregelung Lademodus 2
nurpvlademodus(){
maxll=($llalt $llalts1 $llalts2 $llaltlp4 $llaltlp5 $llaltlp6 $llaltlp7 $llaltlp8)
maxllvar=0
for v in "${maxll[@]}"; do
if (( v > maxllvar )); then maxllvar=$v; fi;
done
llalt=$maxllvar
if (( llalt > minimalapv )); then
if (( llaltlp1 == minimalapv )); then
llalt=$minimalapv
fi
fi
if [[ $schieflastaktiv == "1" ]]; then
if [[ $u1p3paktiv == "1" ]]; then
u1p3pstat=$(<ramdisk/u1p3pstat)
if [[ $u1p3pstat == "1" ]]; then
if (( schieflastmaxa < maximalstromstaerke )); then
maximalstromstaerke=$schieflastmaxa
openwbDebugLog "PV" 0 "Maximalstromstärke begrenzt auf $schieflastmaxa da Schieflastbegrenzung konfiguriert"
fi
fi
fi
fi
if (( stopchargeafterdisclp1 == 0 )); then
if [[ $stopchargepvatpercentlp1 == "1" ]]; then
if (( soc > stopchargepvpercentagelp1 )); then
if [[ $lp1enabled == "1" ]]; then
mosquitto_pub -r -t "openWB/set/lp/1/ChargePointEnabled" -m "0"
openwbDebugLog "CHARGESTAT" 0 "LP1, Lademodus NurPV. Schalte Ladepunkt auf gesperrt da $soc % SoC erreicht, Ziel $stopchargepvpercentagelp1 %"
openwbDebugLog "PV" 0 "LP1, Lademodus NurPV. Schalte Ladepunkt auf gesperrt da $soc % SoC erreicht, Ziel $stopchargepvpercentagelp1 %"
echo "SoC PV Begrenzung (Limit: $stopchargepvpercentagelp1%) LP1 aktiv, LP gesperrt" > ramdisk/lastregelungaktiv
fi
fi
if (( soc < stopchargepvpercentagelp1 )); then
if [[ $lp1enabled == "0" ]]; then
mosquitto_pub -r -t "openWB/set/lp/1/ChargePointEnabled" -m "1"
openwbDebugLog "CHARGESTAT" 0 "LP1, Lademodus NurPV. Schalte Ladepunkt frei da $soc % SoC noch nicht erreicht, Ziel $stopchargepvpercentagelp1 %"
openwbDebugLog "PV" 0 "LP1, Lademodus NurPV. Schalte Ladepunkt frei da $soc % SoC noch nicht erreicht, Ziel $stopchargepvpercentagelp1 %"
echo "SoC PV Begrenzung LP1 (Limit: $stopchargepvpercentagelp1%) unterschritten, LP entsperrt" > ramdisk/lastregelungaktiv
fi
fi
fi
fi
if (( stopchargeafterdisclp2 == 0 )); then
if [[ $stopchargepvatpercentlp2 == "1" ]]; then
if (( soc1 > stopchargepvpercentagelp2 )); then
if [[ $lp2enabled == "1" ]]; then
mosquitto_pub -r -t "openWB/set/lp/2/ChargePointEnabled" -m "0"
openwbDebugLog "CHARGESTAT" 0 "LP2, Lademodus NurPV. Schalte Ladepunkt auf gesperrt da $soc1 % SoC erreicht, Ziel $stopchargepvpercentagelp2 %"
openwbDebugLog "PV" 0 "LP2, Lademodus NurPV. Schalte Ladepunkt auf gesperrt da $soc1 % SoC erreicht, Ziel $stopchargepvpercentagelp2 %"
echo "SoC PV Begrenzung LP2 (Limit: $stopchargepvpercentagelp2%) aktiv, LP gesperrt" > ramdisk/lastregelungaktiv
fi
fi
if (( soc1 < stopchargepvpercentagelp2 )); then
if [[ $lp2enabled == "0" ]]; then
mosquitto_pub -r -t "openWB/set/lp/2/ChargePointEnabled" -m "1"
openwbDebugLog "CHARGESTAT" 0 "LP2, Lademodus NurPV. Schalte Ladepunkt frei da $soc % SoC noch nicht erreicht, Ziel $stopchargepvpercentagelp2 %"
openwbDebugLog "PV" 0 "LP2, Lademodus NurPV. Schalte Ladepunkt frei da $soc % SoC noch nicht erreicht, Ziel $stopchargepvpercentagelp2 %"
echo "SoC PV Begrenzung LP2 (Limit: $stopchargepvpercentagelp2%) unterschritten, LP entsperrt" > ramdisk/lastregelungaktiv
fi
fi
fi
fi
if [[ $lastmanagement == "0" ]]; then
if [[ $socmodul != "none" ]]; then
if (( soc < minnurpvsoclp1 )); then
if grep -q 0 "/var/www/html/openWB/ramdisk/ladestatus"; then
runs/set-current.sh $minnurpvsocll all
openwbDebugLog "CHARGESTAT" 0 "LP1, Lademodus NurPV. Ladung mit $minnurpvsocll Ampere, $soc % SoC noch nicht erreicht"
openwbDebugLog "MAIN" 1 "Starte PV Laden da $sofortsoclp1 % zu gering"
else
if (( llalt != minnurpvsocll )); then
runs/set-current.sh $minnurpvsocll all
openwbDebugLog "CHARGESTAT" 0 "LP1, Lademodus NurPV. Ladung geändert auf $minnurpvsocll Ampere, $soc % SoC noch nicht erreicht"
fi
fi
echo "Ladung mit $minnurpvsocll Ampere, da $minnurpvsoclp1 % SoC noch nicht erreicht" > ramdisk/lastregelungaktiv
exit 0
fi
if (( soc > maxnurpvsoclp1 )); then
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatus"; then
runs/set-current.sh 0 all
openwbDebugLog "CHARGESTAT" 0 "LP1, Lademodus NurPV. Ladung gestoppt, $soc % SoC erreicht"
openwbDebugLog "MAIN" 1 "Beende PV Laden da $sofortsoclp1 % erreicht"
fi
exit 0
fi
fi
fi
if grep -q 0 "/var/www/html/openWB/ramdisk/ladestatus"; then
if (( ladestatuss1 == 1 )) || (( ladestatuss2 == 1 )); then
runs/set-current.sh 0 all
openwbDebugLog "CHARGESTAT" 0 "alle Ladepunkte, Lademodus NurPV. Ladung gestoppt"
fi
openwbDebugLog "MAIN" 1 "Überschuss $uberschuss; mindestens $mindestuberschussphasen"
if (( mindestuberschussphasen <= uberschuss )); then
openwbDebugLog "PV" 0 "Überschuss $uberschuss ist größer als nötiger Überschuss, Wert: $mindestuberschussphasen"
pvecounter=$(cat /var/www/html/openWB/ramdisk/pvecounter)
if (( pvecounter < einschaltverzoegerung )); then
openwbDebugLog "PV" 0 "Einschaltverzögerung aktiv, Aktuell: $pvecounter, Ziel: $einschaltverzoegerung"
pvecounter=$((pvecounter + 10))
echo $pvecounter > /var/www/html/openWB/ramdisk/pvecounter
openwbDebugLog "MAIN" 1 "PV Einschaltverzögerung auf $pvecounter erhöht, Ziel $einschaltverzoegerung"
exit 0
else
openwbDebugLog "MAIN" 1 "nur pv ladung auf $minimalapv starten"
openwbDebugLog "PV" 0 "Einschaltverzögerung erreicht, Aktuell: $pvecounter, Ziel: $einschaltverzoegerung"
if (( minimalapv == minimalalp2pv )); then
runs/set-current.sh $minimalapv all
openwbDebugLog "PV" 0 "starte Ladung"
openwbDebugLog "CHARGESTAT" 0 "alle Ladepunkte, Lademodus NurPV. Ladung gestartet mit $minimalapv Ampere"
else
openwbDebugLog "PV" 0 "starte Ladung LP1 mit $minimalapv"
runs/set-current.sh $minimalapv m
openwbDebugLog "CHARGESTAT" 0 "LP1, Lademodus NurPV. Ladung gestartet mit $minimalapv Ampere"
openwbDebugLog "PV" 0 "starte Ladung LP2 mit $minimalalp2pv"
runs/set-current.sh $minimalalp2pv s1
openwbDebugLog "CHARGESTAT" 0 "LP2, Lademodus NurPV. Ladung gestartet mit $minimalalp2pv Ampere"
fi
echo 0 > /var/www/html/openWB/ramdisk/pvcounter
echo 0 > /var/www/html/openWB/ramdisk/pvecounter
openwbDebugLog "PV" 0 "setzte Soctimer hoch zum Abfragen des aktuellen SoC"
echo 20000 > /var/www/html/openWB/ramdisk/soctimer
exit 0
fi
else
echo 0 > /var/www/html/openWB/ramdisk/pvecounter
exit 0
fi
fi
if (( ladeleistung < 300 )); then
openwbDebugLog "PV" 0 "Keine Ladung aktiv"
if (( llalt > minimalapv )); then
llneu=$minimalapv
if (( minimalapv == minimalalp2pv )); then
runs/set-current.sh $llneu all
openwbDebugLog "CHARGESTAT" 0 "alle Ladepunkte, Lademodus NurPV. Ladung geändert auf $llneu Ampere"
else
runs/set-current.sh $minimalapv m
openwbDebugLog "CHARGESTAT" 0 "LP1, Lademodus NurPV. Ladung geändert auf $minimalapv Ampere"
runs/set-current.sh $minimalalp2pv s1
openwbDebugLog "CHARGESTAT" 0 "LP2, Lademodus NurPV. Ladung geändert auf $minimalalp2pv Ampere"
fi
echo 0 > /var/www/html/openWB/ramdisk/pvcounter
exit 0
fi
if (( llalt < minimalapv )); then
llneu=$minimalapv
if (( minimalapv == minimalalp2pv )); then
runs/set-current.sh $llneu all
openwbDebugLog "CHARGESTAT" 0 "alle Ladepunkte, Lademodus NurPV. Ladung geändert auf $llneu Ampere"
else
runs/set-current.sh $minimalapv m
openwbDebugLog "CHARGESTAT" 0 "LP1, Lademodus NurPV. Ladung geändert auf $minimalapv Ampere"
runs/set-current.sh $minimalalp2pv s1
openwbDebugLog "CHARGESTAT" 0 "LP2, Lademodus NurPV. Ladung geändert auf $minimalalp2pv Ampere"
fi
echo 0 > /var/www/html/openWB/ramdisk/pvcounter
exit 0
fi
if (( llalt == minimalapv )); then
if (( uberschuss < mindestuberschussphasen )); then
#pvcounter=$(cat /var/www/html/openWB/ramdisk/pvcounter)
#if (( pvcounter < abschaltverzoegerung )); then
# pvcounter=$((pvcounter + 10))
# echo $pvcounter > /var/www/html/openWB/ramdisk/pvcounter
# openwbDebugLog "MAIN" 1 "Nur PV auf Minimalstromstaerke, PV Counter auf $pvcounter erhöht"
#else
if [ -e ramdisk/nurpvoff ]; then
runs/set-current.sh 0 all
openwbDebugLog "CHARGESTAT" 0 "alle Ladepunkte, Lademodus NurPV. Ladefreigabe aufgehoben, Überschuss unterschritten"
openwbDebugLog "MAIN" 1 "pv ladung beendet"
rm ramdisk/nurpvoff
else
touch ramdisk/nurpvoff
fi
openwbDebugLog "PV" 0 "Ladefreigabe aufgehoben da zu wenig Uberschuss vorhanden"
#fi
fi
fi
else
if [[ $speichervorhanden == "1" ]]; then
if (( speicherleistung < 10 )); then
if (( speichersoc > speichersocnurpv )); then
uberschuss=$((uberschuss + speicherleistung + speicherwattnurpv))
openwbDebugLog "PV" 0 "SpeicherSoc ($speichersoc) über konfiguriertem Wert ($speichersocnurpv), neuer Überschusswert: $uberschuss"
else
uberschuss=$((uberschuss + speicherleistung))
openwbDebugLog "PV" 0 "SpeicherSoc ($speichersoc) unter konfiguriertem Wert ($speichersocnurpv), neuer Überschusswert: $uberschuss"
fi
fi
fi
if (( uberschuss > schaltschwelle )); then
if (( llalt == maximalstromstaerke )); then
openwbDebugLog "MAIN" 1 "llalt == maximalstromstaerke"
#exit 0
fi
if [[ $pvbezugeinspeisung == "0" ]]; then
if (( nurpvslowup == 1 )); then
llneu=$(( llalt + 1 ))
else
llneu=$(( llalt + ( uberschuss / 230 / anzahlphasen)))
fi
else
if (( llalt == minimalapv )); then
llneu=$(( llalt + 1 ))
else
if (( nurpvslowup == 1 )); then
llneu=$(( llalt + 1 ))
else
llneu=$(( llalt + ( (uberschuss - schaltschwelle) / 230 / anzahlphasen)))
fi
fi
fi
if (( llneu > maximalstromstaerke )); then
llneu=$maximalstromstaerke
fi
if (( llneu < minimalapv )); then
llneu=$minimalapv
fi
openwbDebugLog "PV" 0 "Überschuss ($uberschuss) ist größer als Schaltschwelle ($schaltschwelle), neuer Ladestromwert: $llneu"
if (( adaptpv == 1 )) && (( soc > 0 )) && (( soc1 > 0 )) && (( (( anzahlphasen == 6 )) || (( anzahlphasen == 2 )) )); then
if (( minimalalp2pv > minimalapv )); then
minimalapv=$minimalalp2pv
fi
socdist=$(echo $((soc1 - soc)) | sed 's/-//')
anzahl=$((socdist / adaptfaktor))
if (( soc1 > soc )); then
higherev=s1
lowerev=m
else
higherev=m
lowerev=s1
fi
llhigher=$llneu
lllower=$llneu
for ((i=1;i<=anzahl;i++)); do
if (( llhigher > minimalapv )) && (( lllower < maximalstromstaerke )); then
llhigher=$((llhigher - 1))
lllower=$((lllower + 1))
fi
done
runs/set-current.sh $llhigher $higherev
openwbDebugLog "CHARGESTAT" 0 "LP$higherev, Lademodus NurPV. Adaptive PV Ladung geändert auf $llhigher Ampere"
runs/set-current.sh $lllower $lowerev
openwbDebugLog "CHARGESTAT" 0 "LP$lowerev, Lademodus NurPV. Adaptive PV Ladung geändert auf $lllower Ampere"
sleep 1
echo $llneu > ramdisk/llsoll
echo $llneu > ramdisk/llsolls1
openwbDebugLog "MAIN" 1 "$llneu erhöht, adaptiert auf $llhigher A für LP $higherev und $lllower A für LP $lowerev"
else
runs/set-current.sh $llneu all
openwbDebugLog "CHARGESTAT" 0 "alle Ladepunkte, Lademodus NurPV. Ladung geändert auf $llneu Ampere"
openwbDebugLog "MAIN" 1 "pv ladung auf $llneu erhoeht"
fi
echo 0 > /var/www/html/openWB/ramdisk/pvcounter
exit 0
fi
if (( uberschuss < pvregelungm )); then
if (( llalt > minimalapv )); then
llneu=$(( llalt - 1 + ( (uberschuss - pvregelungm) / 230 / anzahlphasen)))
if (( llneu < minimalapv )); then
llneu=$minimalapv
fi
if (( adaptpv == 1 )) && (( soc > 0 )) && (( soc1 > 0 )) && (( (( anzahlphasen == 6 )) || (( anzahlphasen == 2 )) )); then
socdist=$(echo $((soc1 - soc)) | sed 's/-//')
anzahl=$((socdist / adaptfaktor))
if (( soc1 > soc )); then
higherev=s1
lowerev=m
else
higherev=m
lowerev=s1
fi
llhigher=$llneu
lllower=$llneu
for ((i=1;i<=anzahl;i++)); do
if (( llhigher > minimalapv )) && (( lllower < maximalstromstaerke )); then
llhigher=$((llhigher - 1))
lllower=$((lllower + 1))
fi
done
runs/set-current.sh $llhigher $higherev
openwbDebugLog "CHARGESTAT" 0 "LP$higherev, Lademodus NurPV. Adaptive PV Ladung geändert auf $llhigher Ampere"
runs/set-current.sh $lllower $lowerev
openwbDebugLog "CHARGESTAT" 0 "LP$lowerev, Lademodus NurPV. Adaptive PV Ladung geändert auf $lllower Ampere"
sleep 1
echo $llneu > ramdisk/llsoll
echo $llneu > ramdisk/llsolls1
openwbDebugLog "MAIN" 1 "$llneu reduziert, adaptiert auf $llhigher A für LP $higherev und $lllower A für LP $lowerev"
else
if (( minimalapv == minimalalp2pv )); then
runs/set-current.sh $llneu all
openwbDebugLog "CHARGESTAT" 0 "alle Ladepunkte, Lademodus NurPV. Ladung geändert auf $llneu Ampere"
openwbDebugLog "MAIN" 1 "pv ladung auf $llneu reduziert"
else
runs/set-current.sh $llneu m
openwbDebugLog "CHARGESTAT" 0 "LP1, Lademodus NurPV. Ladung geändert auf $llneu Ampere"
if (( llneu < minimalalp2pv )); then
llneulp2=$minimalalp2pv
else
llneulp2=$llneu
fi
runs/set-current.sh $llneulp2 s1
openwbDebugLog "CHARGESTAT" 0 "LP2, Lademodus NurPV. Ladung geändert auf $llneulp2 Ampere"
openwbDebugLog "MAIN" 1 "pv ladung auf $llneu bzw. $llneulp2 reduziert"
fi
fi
openwbDebugLog "PV" 0 "Uberschuss ($uberschuss) geringer als herunterschaltschwelle ($pvregelungm), neuer Ladestromwert: $llneu"
echo 0 > /var/www/html/openWB/ramdisk/pvcounter
exit 0
else
if [[ $nurpv70dynact == "1" ]]; then
nurpv70status=$(<ramdisk/nurpv70dynstatus)
if [[ $nurpv70status == "1" ]]; then
abschaltuberschuss=$(( 1500 * anzahlphasen ))
openwbDebugLog "MAIN" 1 "Setze neue Abschwaltschwelle"
fi
fi
openwbDebugLog "MAIN" 1 "Abschaltschwelle: $((-abschaltuberschuss)), Überschuss derzeit: $uberschuss"
if (( uberschuss < -abschaltuberschuss )); then
pvcounter=$(cat /var/www/html/openWB/ramdisk/pvcounter)
if (( pvcounter < abschaltverzoegerung )); then
pvcounter=$((pvcounter + 10))
echo $pvcounter > /var/www/html/openWB/ramdisk/pvcounter
openwbDebugLog "MAIN" 1 "Nur PV auf Minimalstromstaerke, PV Counter auf $pvcounter erhöht"
openwbDebugLog "PV" 0 "Überschuss ($uberschuss) kleiner als Abschwaltschwelle ($abschaltuberschuss), Verzögerung ($pvcounter) kleiner als Ziel $abschaltverzoegerung Sec"
else
openwbDebugLog "PV" 0 "Abschaltverzögerung erreicht, stoppe Ladung"
runs/set-current.sh 0 all
openwbDebugLog "CHARGESTAT" 0 "alle Ladepunkte, Lademodus NurPV. Ladung gestoppt zu wenig PV Leistung: $uberschuss"
openwbDebugLog "MAIN" 1 "pv ladung beendet"
echo 0 > /var/www/html/openWB/ramdisk/pvcounter
fi
exit 0
else
openwbDebugLog "PV" 0 "Minimalstromstärke erreicht, Überschuss größer als Abschaltschwelle"
echo 0 > /var/www/html/openWB/ramdisk/pvcounter
exit 0
fi
fi
fi
fi
}