Skip to content

Commit

Permalink
Alternative EVU+Batterie-Module für Solarwatt/MyReserve-Geräte mit Ga…
Browse files Browse the repository at this point in the history
…teway (snaptec#1362)

* Alternative EVU+Batterie-Module für Solarwatt/MyReserve-Geräte mit Gateway
  • Loading branch information
Flock82 authored May 12, 2021
1 parent 2cd186e commit 77984d5
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 54 deletions.
58 changes: 39 additions & 19 deletions modules/bezug_solarwatt/main.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
#!/bin/bash





#sresponse=$(curl --connect-timeout 3 -s "http://$speichersolarwattip/rest/kiwigrid/wizard/devices")
sresponse=$(curl --connect-timeout 3 -s "http://${speicher1_ip}/rest/kiwigrid/wizard/devices")

#bezugwh=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.WorkConsumedFromGrid.value != null) | .tagValues.WorkConsumedFromGrid.value' | sed 's/\..*$//')
#echo $bezugwh > /var/www/html/openWB/ramdisk/bezugkwh
#einspeisungwh=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.WorkOut.value != null) | .tagValues.WorkOut.value' | sed 's/\..*$//')
#echo $einspeisungwh > /var/www/html/openWB/ramdisk/einspeisungkwh

bezugw=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.PowerConsumedFromGrid.value != null) | .tagValues.PowerConsumedFromGrid.value' | sed 's/\..*$//')

einspeisungw=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.PowerOut.value != null) | .tagValues.PowerOut.value' | head -n 1 | sed 's/\..*$//')
bezugwatt=$(echo "scale=0; $bezugw - $einspeisungw /1" |bc)

echo $bezugwatt > /var/www/html/openWB/ramdisk/wattbezug

OPENWBBASEDIR=$(cd `dirname $0`/../../ && pwd)
RAMDISKDIR="$OPENWBBASEDIR/ramdisk"
MODULE="EVU"
LOGFILE="$RAMDISKDIR/openWB.log"
Debug=$debug
BEZUGFILE="$RAMDISKDIR/wattbezug"

DebugLog(){
if (( Debug > 0 )); then
timestamp=`date +"%Y-%m-%d %H:%M:%S"`
echo "$timestamp: ${MODULE}: $@" >> $LOGFILE
fi
}


if (( $solarwattmethod == 0 )); then #Abruf über Energy Manager
sresponse=$(curl --connect-timeout 3 -s "http://${speicher1_ip}/rest/kiwigrid/wizard/devices")

if ((${#sresponse} < 10)); then
bezugwatt=$(<$BEZUGFILE)
else
bezugw=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.PowerConsumedFromGrid.value != null) | .tagValues.PowerConsumedFromGrid.value' | sed 's/\..*$//')
einspeisungw=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.PowerOut.value != null) | .tagValues.PowerOut.value' | head -n 1 | sed 's/\..*$//')
bezugwatt=$(echo "scale=0; $bezugw - $einspeisungw /1" |bc)
fi
fi
if (( $solarwattmethod == 1 )); then #Abruf über Gateway
sresponse=$(curl --connect-timeout 3 -s "http://${speicher1_ip2}:8080/")

if ((${#sresponse} < 10)); then
bezugwatt=$(<$BEZUGFILE)
else
bezugw=$(echo $sresponse | jq '.FData.PGrid' | sed 's/\..*$//')
bezugwatt=$(echo "scale=0; $bezugw / 1" | bc)
fi
fi

DebugLog "Netzbezug: $bezugwatt W"
echo $bezugwatt > $BEZUGFILE
echo $bezugwatt
74 changes: 43 additions & 31 deletions modules/speicher_solarwatt/main.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
#!/bin/bash

DMOD="MAIN"
OPENWBBASEDIR=$(cd `dirname $0`/../../ && pwd)
RAMDISKDIR="$OPENWBBASEDIR/ramdisk"
MODULE="Speicher"
LOGFILE="$RAMDISKDIR/openWB.log"
Debug=$debug

openwbDebugLog ${DMOD} 1 "URL: ${speicher1_ip}/rest/kiwigrid/wizard/devices"
sresponse=$(curl --connect-timeout 5 -s "http://${speicher1_ip}/rest/kiwigrid/wizard/devices")
#sresponse=$(curl --connect-timeout 5 -s "http://192.168.178.64/rest/kiwigrid/wizard/devices")
openwbDebugLog ${DMOD} 1 "Resp: $?"
#pvwh=$(echo $sresponse | jq '.result.items | .[0].tagValues.WorkProduced.value')
#echo "PV erzeugt $pvwh"
#pvwatt=$(echo $sresponse | jq '.result.items | .[0].tagValues.PowerProduced.value')
#echo "PV Leistung aktuellt $pvwatt"
#bezugwh=$(echo $sresponse | jq '.result.items | .[0].tagValues.WorkConsumedFromGrid.value')
#echo "Vom Netz bezogen Gesamt $bezugwh"
#bezugw=$(echo $sresponse | jq '.result.items | .[0].tagValues.PowerConsumedFromGrid.value')
#einspeisungw=$(echo $sresponse | jq '.result.items | .[0].tagValues.PowerOut.value')
#bezugwatt=$(echo "scale=0; $bezugw - $einspeisungw /1" |bc)
#echo "Bezug/Einspeisung am Übergabepunkt $bezugwatt"
#einspeisungwh=$(echo $sresponse | jq '.result.items | .[0].tagValues.WorkOut.value')
#echo "Ins Netz eingespeist Gesamt $einspeisungwh"

speichere=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.PowerConsumedFromStorage.value != null) | .tagValues.PowerConsumedFromStorage.value' | sed 's/\..*$//')
openwbDebugLog ${DMOD} 1 "Speichere: ${speichere}"
speicherein=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.PowerOutFromStorage.value != null) | .tagValues.PowerOutFromStorage.value' | sed 's/\..*$//')
openwbDebugLog ${DMOD} 1 "Speicherein: ${speicherein}"
speicheri=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.PowerBuffered.value != null) | .tagValues.PowerBuffered.value' | sed 's/\..*$//')
openwbDebugLog ${DMOD} 1 "Speicheri: ${speicheri}"
#speicherleistung=$((speichere + speicherin - speicheri))
speicherleistung=$(echo "scale=0; ($speichere + $speicherin - $speicheri) *-1" | bc)
openwbDebugLog ${DMOD} 1 "Speicherleistung: ${speicherleistung}"
DebugLog(){
if (( Debug > 0 )); then
timestamp=`date +"%Y-%m-%d %H:%M:%S"`
echo "$timestamp: ${MODULE}: $@" >> $LOGFILE
fi
}

if (( $solarwattmethod == 0 )); then #Abruf über Energy Manager
sresponse=$(curl --connect-timeout 5 -s "http://${speicher1_ip}/rest/kiwigrid/wizard/devices")

if ((${#sresponse} < 10)); then
exit 1
fi

speichere=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.PowerConsumedFromStorage.value != null) | .tagValues.PowerConsumedFromStorage.value' | sed 's/\..*$//')
speicherein=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.PowerOutFromStorage.value != null) | .tagValues.PowerOutFromStorage.value' | sed 's/\..*$//')
speicheri=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.PowerBuffered.value != null) | .tagValues.PowerBuffered.value' | sed 's/\..*$//')

speicherleistung=$(echo "scale=0; ($speichere + $speicherin - $speicheri) *-1" | bc)
speichersoc=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.StateOfCharge.value != null) | .tagValues.StateOfCharge.value' | sed 's/\..*$//')
fi

if (( $solarwattmethod == 1 )); then #Abruf über Gateway
sresponse=$(curl --connect-timeout 3 -s "http://${speicher1_ip2}:8080/")

if ((${#sresponse} < 10)); then
exit 1
fi

ibat=$(echo $sresponse | jq '.FData.IBat')
vbat=$(echo $sresponse | jq '.FData.VBat')
speicherleistung=$(echo "($ibat * $vbat)" | bc)
speicherleistung=$(echo "scale=0; ($speicherleistung) / (-1)" | bc)
speichersoc=$(echo $sresponse | jq '.SData.SoC' | sed 's/\..*$//')
fi

DebugLog "Speicherleistung: ${speicherleistung} W"
echo $speicherleistung > /var/www/html/openWB/ramdisk/speicherleistung
#echo "Batterieladung/entladung $speicherleistung"
speichersoc=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.StateOfCharge.value != null) | .tagValues.StateOfCharge.value' | sed 's/\..*$//')
openwbDebugLog ${DMOD} 1 "SpeicherSoC: ${speichersoc}"
#echo "Batterieladezustand $speichersoc"

DebugLog "SpeicherSoC: ${speichersoc} %"
echo $speichersoc > /var/www/html/openWB/ramdisk/speichersoc
19 changes: 15 additions & 4 deletions modules/wr_solarwatt/main.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
#!/bin/bash

#sresponse=$(curl --connect-timeout 3 -s "http://$speichersolarwattip/rest/kiwigrid/wizard/devices")
OPENWBBASEDIR=$(cd `dirname $0`/../../ && pwd)
RAMDISKDIR="$OPENWBBASEDIR/ramdisk"
MODULE="PV"
LOGFILE="$RAMDISKDIR/openWB.log"
Debug=$debug

DebugLog(){
if (( Debug > 0 )); then
timestamp=`date +"%Y-%m-%d %H:%M:%S"`
echo "$timestamp: ${MODULE}: $@" >> $LOGFILE
fi
}

sresponse=$(curl --connect-timeout 3 -s "http://${speicher1_ip}/rest/kiwigrid/wizard/devices")

#pvwh=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.WorkProduced.value != null) | .tagValues.WorkProduced.value' | sed 's/\..*$//')
#echo "PV erzeugt $pvwh"
#echo $pvwh > /var/www/html/openWB/ramdisk/pvkwh
pvwatt=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.PowerProduced.value != null) | .tagValues.PowerProduced.value' | sed 's/\..*$//')
DebugLog "PV-Leistung: ${pvwatt} W"
pvwatt=$((pvwatt * -1))

echo $pvwatt > /var/www/html/openWB/ramdisk/pvwatt
echo $pvwatt
6 changes: 6 additions & 0 deletions runs/updateConfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,9 @@ updateConfig(){
echo "pv1_idd=1" >> $ConfigFile
echo "speicher1_ip=192.168.0.17" >> $ConfigFile
fi
if ! grep -Fq "speicher1_ip2=" $ConfigFile; then
echo "speicher1_ip2=192.168.0.17" >> $ConfigFile
fi
if ! grep -Fq "fsm63a3modbusllsource=" $ConfigFile; then
echo "fsm63a3modbusllsource=/dev/ttyUSB2" >> $ConfigFile
fi
Expand Down Expand Up @@ -2012,6 +2015,9 @@ updateConfig(){
echo "cpunterbrechungmindestlaufzeitaktiv=0" >> $ConfigFile
echo "cpunterbrechungmindestlaufzeit=30" >> $ConfigFile
fi
if ! grep -Fq "solarwattmethod=" $ConfigFile; then
echo "solarwattmethod=0" >> $ConfigFile
fi

echo "Config file Update done."
}
53 changes: 53 additions & 0 deletions web/settings/modulconfigbat.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,43 @@
<span class="text-info">openWB/set/houseBattery/%Soc</span> Ladestand des Speichers, int, 0-100
</div>
</div>

<div id="divspeichersolarwatt" class="hide">
<div class="form-group">
<div class="form-row mb-1">
<label for="solarwattmethod" class="col-md-4 col-form-label">Abrufmethode EVU/Batterie</label>
<div class="col">
<div class="btn-group btn-group-toggle btn-block" data-toggle="buttons">
<label class="btn btn-outline-info<?php if($solarwattmethodold == 0) echo " active" ?>">
<input type="radio" name="solarwattmethod" id="solarwattmethod1" value="0"<?php if($solarwattmethodold == 0) echo " checked=\"checked\"" ?>>Energy Manager
</label>
<label class="btn btn-outline-info<?php if($solarwattmethodold == 1) echo " active" ?>">
<input type="radio" name="solarwattmethod" id="solarwattmethod2" value="1"<?php if($solarwattmethodold == 1) echo " checked=\"checked\"" ?>>Gateway
</label>
</div>
<span class="form-text small">
IP-Adresse 1: Energy Manager (immer angeben)<br>
IP-Adresse 2: Gateway (Zus&auml;tzlich, falls Abrufmethode Gateway)
</span>
</div>
</div>
</div>
<script>
function visibility_solarwatt_ip2() {
if($('#solarwattmethod1').prop("checked")) {
hideSection('#divspeicherip2');
} else {
showSection('#divspeicherip2');
}
}

$(function() {
$('input[type=radio][name=solarwattmethod]').change(function(){
visibility_solarwatt_ip2();
});
});
</script>
</div>

<div id="divspeichervictron" class="hide">
<div class="alert alert-info">
Expand Down Expand Up @@ -204,6 +241,18 @@
</div>
</div>
</div>

<div id="divspeicherip2" class="hide">
<div class="form-group">
<div class="form-row mb-1">
<label for="speicher1_ip2" class="col-md-4 col-form-label">IP Adresse 2</label>
<div class="col">
<input class="form-control" type="text" pattern="^((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$" name="speicher1_ip2" id="speicher1_ip2" value="<?php echo $speicher1_ip2old ?>">
<span class="form-text small">Gültige Werte IP Adresse im Format: 192.168.0.12</span>
</div>
</div>
</div>
</div>

<div id="divspeichersiemens" class="hide">
<div class="alert alert-info">
Expand Down Expand Up @@ -587,6 +636,8 @@ function display_speichermodul() {
hideSection('#divspeicherrct');
hideSection('#divspeichersungrow');
hideSection('#divspeicherjson');
hideSection('#divspeichersolarwatt');
hideSection('#divspeicherip2');

if($('#speichermodul').val() == 'speicher_fems') {
showSection('#divspeicherfems');
Expand All @@ -599,7 +650,9 @@ function display_speichermodul() {
showSection('#divspeichersiemens');
}
if($('#speichermodul').val() == 'speicher_solarwatt') {
showSection('#divspeichersolarwatt');
showSection('#divspeicherip');
visibility_solarwatt_ip2();
}
if($('#speichermodul').val() == 'speicher_tesvoltsma') {
showSection('#divspeicherip');
Expand Down

0 comments on commit 77984d5

Please sign in to comment.