This repository has been archived by the owner on Mar 31, 2023. It is now read-only.
forked from snaptec/openWB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nachtladen.sh
executable file
·285 lines (268 loc) · 8.01 KB
/
nachtladen.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
#!/bin/bash
lastmnacht(){
if [ $# -eq 2 ]; then
if (( evua1 < lastmaxap1 )) && (( evua2 < lastmaxap2 )) && (( evua3 < lastmaxap3 )); then
evudiff1=$((lastmaxap1 - evua1 ))
evudiff2=$((lastmaxap2 - evua2 ))
evudiff3=$((lastmaxap3 - evua3 ))
evudiffmax=($evudiff1 $evudiff2 $evudiff3)
maxdiff=${evudiffmax[0]}
for v in "${evudiffmax[@]}"; do
if (( v < maxdiff )); then maxdiff=$v; fi;
done
if (( $1 == $2 )); then
llnachtreturn=$2
else
if (( $2 == 0 )); then
llnachtreturn=$2
else
if (( $1 > $2 )); then
llnachtreturn=$(($1 - 1 ))
else
if (( maxdiff > 1 )); then
llnachtreturn=$(($1 + 1 ))
else
llnachtreturn=$1
fi
fi
if (( llnachtreturn > maximalstromstaerke )); then
llnachtreturn=$2
fi
if (( llnachtreturn < minimalstromstaerke )); then
llnachtreturn=$minimalstromstaerke
fi
fi
fi
else
evudiff1=$((evua1 - lastmaxap1 ))
evudiff2=$((evua2 - lastmaxap2 ))
evudiff3=$((evua3 - lastmaxap3 ))
evudiffmax=($evudiff1 $evudiff2 $evudiff3)
maxdiff=0
for vv in "${evudiffmax[@]}"; do
if (( vv > maxdiff )); then maxdiff=$vv; fi;
done
maxdiff=$((maxdiff + 1 ))
llnachtreturn=$(($1 - maxdiff))
if (( llnachtreturn < minimalstromstaerke )); then
llnachtreturn=$minimalstromstaerke
if [[ $debug == "1" ]]; then
echo Differenz groesser als minimalstromstaerke, setze Nachtladen auf minimal A $minimalstromstaerke
fi
fi
echo "Lastmanagement aktiv, Ladeleistung reduziert" > ramdisk/lastregelungaktiv
if [[ $debug == "1" ]]; then
echo "Nachtladen um $maxdiff auf $llnachtreturn reduziert"
fi
fi
fi
}
nachtlademodus(){
if [[ $nachtladen == "1" ]]; then
if (( nachtladenabuhr <= 10#$H && 10#$H <= 24 )) || (( 0 <= 10#$H && 10#$H < nachtladenbisuhr )); then
nachtladenstate=1
dayoftheweek=$(date +%w)
if [ "$dayoftheweek" -ge 0 ] && [ "$dayoftheweek" -le 4 ]; then
diesersoc=$nachtsoc
else
diesersoc=$nachtsoc1
fi
if [[ $socmodul != "none" ]]; then
if [[ $debug == "1" ]]; then
echo nachtladen mit socmodul $socmodul
fi
if (( soc <= diesersoc )); then
if grep -q 0 "/var/www/html/openWB/ramdisk/ladestatus"; then
llnachtneu=$nachtll
#runs/set-current.sh "$nachtll" m
if [[ $debug == "1" ]]; then
echo "soc $soc"
echo "ladeleistung nachtladen bei $nachtll"
fi
fi
if ! grep -q $nachtll "/var/www/html/openWB/ramdisk/llsoll"; then
llnachtneu=$nachtll
#runs/set-current.sh "$nachtll" m
if [[ $debug == "1" ]]; then
echo aendere nacht Ladeleistung auf $nachtll
fi
fi
else
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatus"; then
llnachtneu=0
#runs/set-current.sh 0 m
fi
fi
else
if grep -q 0 "/var/www/html/openWB/ramdisk/ladestatus"; then
llnachtneu=$nachtll
#runs/set-current.sh "$nachtll" m
if [[ $debug == "1" ]]; then
echo "soc $soc"
echo "ladeleistung nachtladen $nachtll A"
fi
else
if ! grep -q $nachtll "/var/www/html/openWB/ramdisk/llsoll"; then
llnachtneu=$nachtll
#runs/set-current.sh "$nachtll" m
if [[ $debug == "1" ]]; then
echo aendere nacht Ladeleistung auf $nachtll
fi
fi
fi
fi
if [ -z "$llnachtneu" ]; then
llnachtneu=$llalt
fi
else
nachtladenstate=0
fi
if (( nachtladen2abuhr <= 10#$H )) && (( 10#$H < nachtladen2bisuhr )); then
nachtladen2state=1
dayoftheweek=$(date +%w)
if grep -q 0 "/var/www/html/openWB/ramdisk/ladestatus"; then
llnachtneu=$nacht2ll
#runs/set-current.sh "$nacht2ll" m
if [[ $debug == "1" ]]; then
echo "soc $soc"
echo "ladeleistung nachtladen $nacht2ll A"
fi
else
if ! grep -q $nacht2ll "/var/www/html/openWB/ramdisk/llsoll"; then
llnachtneu=$nacht2ll
#runs/set-current.sh "$nacht2ll" m
if [[ $debug == "1" ]]; then
echo aendere nacht Ladeleistung auf $nacht2ll
fi
fi
fi
if [ -z "$llnachtneu" ]; then
llnachtneu=$llalt
fi
else
nachtladen2state=0
fi
else
nachtladenstate=0
nachtladen2state=0
fi
#Nachtladen S1
if [[ $nachtladens1 == "1" ]]; then
if (( nachtladenabuhrs1 <= 10#$H && 10#$H <= 24 )) || (( 0 <= 10#$H && 10#$H < nachtladenbisuhrs1 )); then
nachtladenstates1=1
dayoftheweek=$(date +%w)
if [ "$dayoftheweek" -ge 0 ] && [ "$dayoftheweek" -le 4 ]; then
diesersocs1=$nachtsocs1
else
diesersocs1=$nachtsoc1s1
fi
if [[ $socmodul1 != "none" ]]; then
if [[ $debug == "1" ]]; then
echo nachtladen mit socmodul $socmodul1
fi
if (( soc1 <= diesersocs1 )); then
if grep -q 0 "/var/www/html/openWB/ramdisk/ladestatuss1"; then
llnachts1neu=$nachtlls1
#runs/set-current.sh "$nachtlls1" s1
if [[ $debug == "1" ]]; then
echo "soc $soc1"
echo "ladeleistung nachtladen bei $nachtlls1"
fi
fi
if ! grep -q $nachtlls1 "/var/www/html/openWB/ramdisk/llsolls1"; then
llnachts1neu=$nachtlls1
#runs/set-current.sh "$nachtlls1" s1
if [[ $debug == "1" ]]; then
echo aendere nacht Ladeleistung auf $nachtlls1
fi
fi
else
if grep -q 1 "/var/www/html/openWB/ramdisk/ladestatuss1"; then
llnachts1neu=0
#runs/set-current.sh 0 s1
fi
fi
else
if grep -q 0 "/var/www/html/openWB/ramdisk/ladestatuss1"; then
llnachts1neu=$nachtlls1
#runs/set-current.sh "$nachtlls1" s1
if [[ $debug == "1" ]]; then
echo "soc $soc1"
echo "ladeleistung nachtladen $nachtlls1 A"
fi
echo "start Nachtladung mit $nachtlls1 um $date" >> web/lade.log
else
if ! grep -q $nachtlls1 "/var/www/html/openWB/ramdisk/llsolls1"; then
llnachts1neu=$nachtlls1
#runs/set-current.sh "$nachtlls1" s1
if [[ $debug == "1" ]]; then
echo aendere nacht Ladeleistung auf $nachtlls1
fi
fi
fi
fi
if [ -z "$llnachts1neu" ]; then
llnachts1neu=$llalts1
fi
else
nachtladenstates1=0
fi
if (( nachtladen2abuhrs1 <= 10#$H )) && (( 10#$H < nachtladen2bisuhrs1 )); then
nachtladen2states1=1
dayoftheweek=$(date +%w)
if grep -q 0 "/var/www/html/openWB/ramdisk/ladestatuss1"; then
llnachts1neu=$nacht2lls1
#runs/set-current.sh "$nacht2lls1" s1
if [[ $debug == "1" ]]; then
echo "soc $soc1"
echo "ladeleistung nachtladen $nacht2lls1 A"
fi
else
if ! grep -q $nacht2lls1 "/var/www/html/openWB/ramdisk/llsolls1"; then
llnachts1neu=$nacht2lls1
#runs/set-current.sh "$nacht2lls1" m
if [[ $debug == "1" ]]; then
echo aendere nacht Ladeleistung auf $nacht2lls1
fi
fi
fi
if [ -z "$llnachts1neu" ]; then
llnachts1neu=$llalts1
fi
else
nachtladen2states1=0
fi
else
nachtladenstates1=0
nachtladen2states1=0
fi
echo $nachtladenstate > /var/www/html/openWB/ramdisk/nachtladenstate
echo $nachtladenstates1 > /var/www/html/openWB/ramdisk/nachtladenstates1
echo $nachtladen2state > /var/www/html/openWB/ramdisk/nachtladen2state
echo $nachtladen2states1 > /var/www/html/openWB/ramdisk/nachtladen2states1
if (( nachtladenstate == 1 )) || (( nachtladenstates1 == 1 )) || (( nachtladen2state == 1 )) || (( nachtladen2states1 == 1 )); then
if (( nachtladenstate == 1 )) || (( nachtladen2state == 1 )); then
lastmnacht $llalt $llnachtneu
if (( llnachtreturn != llalt )); then
runs/set-current.sh $llnachtreturn m
fi
fi
if (( nachtladenstates1 == 1 )) || (( nachtladen2states1 == 1 )); then
lastmnacht $llalts1 $llnachts1neu
if (( llnachtreturn != llalts1 )); then
runs/set-current.sh $llnachtreturn s1
fi
fi
exit 0
fi
}
prenachtlademodus(){
if { (( lademodus == 0 )) && (( nlakt_sofort == 1 )); } || { (( lademodus == 1 )) && (( nlakt_minpv == 1 )); } || { (( lademodus == 2 )) && (( nlakt_nurpv == 1 )); } || { (( lademodus == 4 )) && (( nlakt_standby == 1 )); } then
nachtlademodus
else
echo 0 > ramdisk/nachtladenstate
echo 0 > ramdisk/nachtladen2state
echo 0 > ramdisk/nachtladenstates1
echo 0 > ramdisk/nachtladen2states1
fi
}