Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/snaptec/openWB
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinRinas committed Apr 20, 2021
2 parents ef92635 + 2ad8ed7 commit 59b82af
Show file tree
Hide file tree
Showing 13 changed files with 436 additions and 47 deletions.
21 changes: 18 additions & 3 deletions goecheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ goecheck(){
curl --silent --connect-timeout $goetimeoutlp1 -s http://$goeiplp1/mqtt?payload=alw=0 > /dev/null
fi
fi
fwv=$(echo $output | jq -r '.fwv' | grep -Po "[1-9]\d{1,2}")
oldcurrent=$(echo $output | jq -r '.amp')
current=$(</var/www/html/openWB/ramdisk/llsoll)
if (( oldcurrent != $current )) ; then
curl --silent --connect-timeout $goetimeoutlp1 -s http://$goeiplp1/mqtt?payload=amp=$current > /dev/null
if (($fwv >= 40)) ; then
curl --silent --connect-timeout $goetimeoutlp1 -s http://$goeiplp1/mqtt?payload=amx=$current > /dev/null
else
curl --silent --connect-timeout $goetimeoutlp1 -s http://$goeiplp1/mqtt?payload=amp=$current > /dev/null
fi
fi
fi
fi
Expand All @@ -41,10 +46,15 @@ goecheck(){
curl --silent --connect-timeout $goetimeoutlp2 -s http://$goeiplp2/mqtt?payload=alw=0 > /dev/null
fi
fi
fwv=$(echo $output | jq -r '.fwv' | grep -Po "[1-9]\d{1,2}")
oldcurrent=$(echo $output | jq -r '.amp')
current=$(</var/www/html/openWB/ramdisk/llsolls1)
if (( oldcurrent != $current )) ; then
curl --silent --connect-timeout $goetimeoutlp2 -s http://$goeiplp2/mqtt?payload=amp=$current > /dev/null
if (($fwv >= 40)) ; then
curl --silent --connect-timeout $goetimeoutlp2 -s http://$goeiplp2/mqtt?payload=amx=$current > /dev/null
else
curl --silent --connect-timeout $goetimeoutlp2 -s http://$goeiplp2/mqtt?payload=amp=$current > /dev/null
fi
fi
fi
fi
Expand All @@ -64,10 +74,15 @@ goecheck(){
curl --silent --connect-timeout $goetimeoutlp3 -s http://$goeiplp3/mqtt?payload=alw=0 > /dev/null
fi
fi
fwv=$(echo $output | jq -r '.fwv' | grep -Po "[1-9]\d{1,2}")
oldcurrent=$(echo $output | jq -r '.amp')
current=$(</var/www/html/openWB/ramdisk/llsolls2)
if (( oldcurrent != $current )) ; then
curl --silent --connect-timeout $goetimeoutlp3 -s http://$goeiplp3/mqtt?payload=amp=$current > /dev/null
if (($fwv >= 40)) ; then
curl --silent --connect-timeout $goetimeoutlp3 -s http://$goeiplp3/mqtt?payload=amx=$current > /dev/null
else
curl --silent --connect-timeout $goetimeoutlp3 -s http://$goeiplp3/mqtt?payload=amp=$current > /dev/null
fi
fi
fi
fi
Expand Down
3 changes: 2 additions & 1 deletion modules/bezug_solarwatt/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@



sresponse=$(curl --connect-timeout 3 -s "http://$speichersolarwattip/rest/kiwigrid/wizard/devices")
#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
Expand Down
21 changes: 21 additions & 0 deletions modules/soc_evcc/evcc-license
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 andig

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
101 changes: 101 additions & 0 deletions modules/soc_evcc/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash
OPENWBBASEDIR=$(cd `dirname $0`/../../ && pwd)
RAMDISKDIR="$OPENWBBASEDIR/ramdisk"
MODULEDIR=$(cd `dirname $0` && pwd)
DMOD="EVSOC"
CHARGEPOINT=$1

# check if config file is already in env
if [[ -z "$debug" ]]; then
echo "soc_evcc: Seems like openwb.conf is not loaded. Reading file."
# try to load config
. $OPENWBBASEDIR/loadconfig.sh
# load helperFunctions
. $OPENWBBASEDIR/helperFunctions.sh
fi

case $CHARGEPOINT in
2)
# second charge point
ladeleistung=$(<$RAMDISKDIR/llaktuells1)
soctimerfile="$RAMDISKDIR/soctimer1"
socfile="$RAMDISKDIR/soc1"
fztype=$soc_evcc_type_lp2
username=$soc_evcc_username_lp2
password=$soc_evcc_password_lp2
vin=$soc_evcc_vin_lp2
token=$soc_evcc_token_lp2
intervall=$(( soc2intervall * 6 ))
intervallladen=$(( soc2intervallladen * 6 ))
;;
*)
# defaults to first charge point for backward compatibility
# set CHARGEPOINT in case it is empty (needed for logging)
CHARGEPOINT=1
ladeleistung=$(<$RAMDISKDIR/llaktuell)
soctimerfile="$RAMDISKDIR/soctimer"
socfile="$RAMDISKDIR/soc"
fztype=$soc_evcc_type_lp1
username=$soc_evcc_username_lp1
password=$soc_evcc_password_lp1
vin=$soc_evcc_vin_lp1
token=$soc_evcc_token_lp1
intervall=$(( soc_evcc_intervall * 6 ))
intervallladen=$(( soc_evcc_intervallladen * 6 ))
;;
esac

incrementTimer(){
case $dspeed in
1)
# Regelgeschwindigkeit 10 Sekunden
ticksize=1
;;
2)
# Regelgeschwindigkeit 20 Sekunden
ticksize=2
;;
3)
# Regelgeschwindigkeit 60 Sekunden
ticksize=6
;;
*)
# Regelgeschwindigkeit unbekannt
ticksize=1
;;
esac
soctimer=$((soctimer+$ticksize))
echo $soctimer > $soctimerfile
}

getAndWriteSoc(){
openwbDebugLog ${DMOD} 0 "Lp$CHARGEPOINT: Requesting SoC"
echo 0 > $soctimerfile
answer=$($MODULEDIR/../soc_evcc/soc $fztype --user "$username" --password "$password" --vin "$vin" --token "$token" 2>&1)
if [ $? -eq 0 ]; then
# we got a valid answer
echo $answer > $socfile
openwbDebugLog ${DMOD} 0 "Lp$CHARGEPOINT: SoC: $answer"
else
# we have a problem
openwbDebugLog ${DMOD} 0 "Lp$CHARGEPOINT: Error from EVCC: $answer"
fi
}

soctimer=$(<$soctimerfile)
if (( ladeleistung > 500 )); then
if (( soctimer < intervallladen )); then
openwbDebugLog ${DMOD} 0 "Lp$CHARGEPOINT: Charging, but nothing to do yet. Incrementing timer."
incrementTimer
else
getAndWriteSoc
fi
else
if (( soctimer < intervall )); then
openwbDebugLog ${DMOD} 0 "Lp$CHARGEPOINT: Nothing to do yet. Incrementing timer."
incrementTimer

else
getAndWriteSoc
fi
fi
Binary file added modules/soc_evcc/soc
Binary file not shown.
8 changes: 8 additions & 0 deletions modules/soc_evcclp2/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

OPENWBBASEDIR=$(cd `dirname $0`/../../ && pwd)

# for backward compatibility only
# functionality is in soc_evcc
$OPENWBBASEDIR/modules/soc_evcc/main.sh 2
exit 0
14 changes: 12 additions & 2 deletions modules/speicher_solarwatt/main.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/bin/bash
#!/bin/bash

sresponse=$(curl --connect-timeout 3 -s "http://$speichersolarwattip/rest/kiwigrid/wizard/devices")
DMOD="MAIN"
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')
Expand All @@ -16,12 +21,17 @@ sresponse=$(curl --connect-timeout 3 -s "http://$speichersolarwattip/rest/kiwigr
#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}"
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"
echo $speichersoc > /var/www/html/openWB/ramdisk/speichersoc
55 changes: 27 additions & 28 deletions modules/wr2_solaredge/solaredge.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,37 @@
from pymodbus.client.sync import ModbusTcpClient
client = ModbusTcpClient(ipaddress, port=502)
#batterie auslesen und pv leistung korrigieren
resp= client.read_holding_registers(40084,2,unit=slave1id)
multipli = resp.registers[0]
multiplint = format(multipli, '04x')
fmultiplint = int(struct.unpack('>h', multiplint.decode('hex'))[0])

respw= client.read_holding_registers(40083,2,unit=slave1id)
value1w = respw.registers[0]
allw = format(value1w, '04x')
rawprodw = finalw = int(struct.unpack('>h', allw.decode('hex'))[0]) * -1
resp= client.read_holding_registers(40084,2,unit=slave1id)
mult2ipli = resp.registers[0]
mult2iplint = format(mult2ipli, '04x')
fmult2iplint = int(struct.unpack('>h', mult2iplint.decode('hex'))[0])

if fmultiplint == fmult2iplint:
if fmultiplint == 0:
rawprodw = rawprodw
if fmultiplint == -1:
rawprodw = rawprodw / 10
if fmultiplint == -2:
rawprodw = rawprodw / 100
if fmultiplint == -3:
rawprodw = rawprodw / 1000
if fmultiplint == -4:
rawprodw = rawprodw / 10000
if fmultiplint == -5:
rawprodw = rawprodw / 100000

resp= client.read_holding_registers(40083,2,unit=slave1id)
#read watt
watt=format(resp.registers[0], '04x')
wr1watt=int(struct.unpack('>h', watt.decode('hex'))[0]) * -1
#read multiplier
multiplier=format(resp.registers[1], '04x')
fmultiplier=int(struct.unpack('>h', multiplier.decode('hex'))[0])
if fmultiplier == 2:
fwr1watt = wr1watt * 100
if fmultiplier == 1:
fwr1watt = wr1watt * 10
if fmultiplier == 0:
fwr1watt = wr1watt
if fmultiplier == -1:
fwr1watt = wr1watt / 10
if fmultiplier == -2:
fwr1watt = wr1watt / 100
if fmultiplier == -3:
fwr1watt = wr1watt / 1000
if fmultiplier == -4:
fwr1watt = wr1watt / 10000
if fmultiplier == -5:
fwr1watt = wr1watt / 10000
f = open('/var/www/html/openWB/ramdisk/pv2watt', 'w')
f.write(str(rawprodw))
f.write(str(fwr1watt))
f.close()




resp= client.read_holding_registers(40093,2,unit=slave1id)
value1 = resp.registers[0]
value2 = resp.registers[1]
Expand Down
5 changes: 2 additions & 3 deletions modules/wr_solarwatt/main.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash

#!/bin/bash

sresponse=$(curl --connect-timeout 3 -s "http://$speichersolarwattip/rest/kiwigrid/wizard/devices")
#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")

#pvwh=$(echo $sresponse | jq '.result.items | .[] | select(.tagValues.WorkProduced.value != null) | .tagValues.WorkProduced.value' | sed 's/\..*$//')
#echo "PV erzeugt $pvwh"
Expand Down
2 changes: 1 addition & 1 deletion runs/senddebug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ for currentConfig in /etc/mosquitto/conf.d/99-bridge-*; do
done

echo "############################ config ##############" >> $debugFile
grep -F -v -e soc_id_passwort -e leaf -e myopel_clientidlp2 -e soc_eq_client_secret_lp1 -e psa_clientsecretlp1 -e psa_clientsecretlp2 -e tibbertoken -e soc_eq_client_secret_lp2 -e myopel_clientsecretlp2 -e myopel_clientidlp1 -e myopel_clientsecretlp1 -e i3 -e zoeuser -e zoepass -e zoelp2 -e tesla -e socpass -e soc2pass -e passlp1 -e passlp2 -e carnet -e settingspw -e wrsunwayspw -e cloudpw -e wr_piko2_pass -e zerong -e discovergy -e audi -e smartme -e bydhvpass -e lgessv1pass -e myrenault -e bluelink -e soc_vag_passwort -e soc_id_vin -e soc_tronity_client_id_lp1 -e soc_tronity_client_id_lp2 -e soc_tronity_client_secret_lp1 -e soc_tronity_client_secret_lp2 -e soc_tronity_vehicle_id_lp1 -e soc_tronity_vehicle_id_lp2 /var/www/html/openWB/openwb.conf >> $debugFile
grep -F -v -e soc_id_passwort -e leaf -e myopel_clientidlp2 -e soc_eq_client_secret_lp1 -e psa_clientsecretlp1 -e psa_clientsecretlp2 -e tibbertoken -e soc_eq_client_secret_lp2 -e myopel_clientsecretlp2 -e myopel_clientidlp1 -e myopel_clientsecretlp1 -e i3 -e zoeuser -e zoepass -e zoelp2 -e tesla -e socpass -e soc2pass -e passlp1 -e passlp2 -e carnet -e settingspw -e wrsunwayspw -e cloudpw -e wr_piko2_pass -e zerong -e discovergyuser -e discovergypass -e audi -e smartme -e bydhvpass -e lgessv1pass -e myrenault -e bluelink -e soc_vag_passwort -e soc_id_vin -e soc_tronity_client_id_lp1 -e soc_tronity_client_id_lp2 -e soc_tronity_client_secret_lp1 -e soc_tronity_client_secret_lp2 -e soc_tronity_vehicle_id_lp1 -e soc_tronity_vehicle_id_lp2 /var/www/html/openWB/openwb.conf >> $debugFile

timeout 1 mosquitto_sub -v -t openWB/# >> $debugFile
echo "############################ smarthome.log ##############" >> $debugFile
Expand Down
7 changes: 6 additions & 1 deletion runs/set-current.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,18 @@ function setChargingCurrentgoe () {
fi
else
output=$(curl --connect-timeout $goetimeoutlp1 -s http://$goeiplp1/status)
fwv=$(echo $output | jq -r '.fwv' | grep -Po "[1-9]\d{1,2}")
state=$(echo $output | jq -r '.alw')
if ((state == "0")) ; then
curl --silent --connect-timeout $goetimeoutlp1 -s http://$goeiplp1/mqtt?payload=alw=1 > /dev/null
fi
oldgoecurrent=$(echo $output | jq -r '.amp')
if (( oldgoecurrent != $current )) ; then
curl --silent --connect-timeout $goetimeoutlp1 -s http://$goeiplp1/mqtt?payload=amp=$current > /dev/null
if (($fwv >= 40)) ; then
curl --silent --connect-timeout $goetimeoutlp1 -s http://$goeiplp1/mqtt?payload=amx=$current > /dev/null
else
curl --silent --connect-timeout $goetimeoutlp1 -s http://$goeiplp1/mqtt?payload=amp=$current > /dev/null
fi
fi
fi
fi
Expand Down
Loading

0 comments on commit 59b82af

Please sign in to comment.