Skip to content

Commit

Permalink
add support for dynamic tariffs in mindispaly
Browse files Browse the repository at this point in the history
  • Loading branch information
jotpehenn committed May 7, 2023
1 parent 37a163a commit f62657b
Show file tree
Hide file tree
Showing 15 changed files with 1,018 additions and 141 deletions.
12 changes: 12 additions & 0 deletions loadvars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,14 @@ loadvars(){
mqttconfvar["config/get/sofort/lp/6/etBasedCharging"]=lp6etbasedcharging
mqttconfvar["config/get/sofort/lp/7/etBasedCharging"]=lp7etbasedcharging
mqttconfvar["config/get/sofort/lp/8/etBasedCharging"]=lp8etbasedcharging
mqttconfvar["config/get/sofort/lp/1/etChargeMaxPrice"]=lp1etchargemaxprice
mqttconfvar["config/get/sofort/lp/2/etChargeMaxPrice"]=lp2etchargemaxprice
mqttconfvar["config/get/sofort/lp/3/etChargeMaxPrice"]=lp3etchargemaxprice
mqttconfvar["config/get/sofort/lp/4/etChargeMaxPrice"]=lp4etchargemaxprice
mqttconfvar["config/get/sofort/lp/5/etChargeMaxPrice"]=lp5etchargemaxprice
mqttconfvar["config/get/sofort/lp/6/etChargeMaxPrice"]=lp6etchargemaxprice
mqttconfvar["config/get/sofort/lp/7/etChargeMaxPrice"]=lp7etchargemaxprice
mqttconfvar["config/get/sofort/lp/8/etChargeMaxPrice"]=lp8etchargemaxprice
mqttconfvar["config/get/pv/lp/1/socLimitation"]=stopchargepvatpercentlp1
mqttconfvar["config/get/pv/lp/2/socLimitation"]=stopchargepvatpercentlp2
mqttconfvar["config/get/pv/lp/1/maxSoc"]=stopchargepvpercentagelp1
Expand All @@ -1850,6 +1858,10 @@ loadvars(){
mqttconfvar["config/get/display/chartBatteryMinMax"]=displayspeichermax
mqttconfvar["config/get/display/chartPvMax"]=displaypvmax
mqttconfvar["config/get/display/showHouseConsumption"]=displayhausanzeigen
mqttconfvar["config/get/display/showPrice"]=displayshowprice
mqttconfvar["config/get/display/showRfidPad"]=displayshowrfidpad
mqttconfvar["config/get/display/pinRequired"]=displaypinaktiv
mqttconfvar["config/get/display/allowSetMaxPrice"]=displayallowsetmaxprice
mqttconfvar["config/get/display/chartHouseConsumptionMax"]=displayhausmax
mqttconfvar["config/get/display/chartLp/1/max"]=displaylp1max
mqttconfvar["config/get/display/chartLp/2/max"]=displaylp2max
Expand Down
19 changes: 19 additions & 0 deletions modules/extopenwb/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ if [[ $(wc -l <"$outputname") -ge 5 ]]; then
echo "$boolPlugStat" > "$RAMDISKDIR/plugstat"
echo "$boolChargeStat" > "$RAMDISKDIR/chargestat"
soc=$(<"$RAMDISKDIR/soc")
socEnabled=$(<"$RAMDISKDIR/socvorhanden")
mosquitto_pub -h "$ip" -r -t "openWB/set/lp/$chargepcp/%Soc" -m "$soc"
mosquitto_pub -h "$ip" -r -t "openWB/set/lp/$chargepcp/boolSocConfigured" -m "$socEnabled"
fi
if (( chargep == "2" ));then
echo "$VPhase1" > "$RAMDISKDIR/llvs11"
Expand All @@ -49,7 +51,9 @@ if [[ $(wc -l <"$outputname") -ge 5 ]]; then
echo "$boolPlugStat" > "$RAMDISKDIR/plugstats1"
echo "$boolChargeStat" > "$RAMDISKDIR/chargestats1"
soc=$(<"$RAMDISKDIR/soc1")
socEnabled=$(<"$RAMDISKDIR/soc1vorhanden")
mosquitto_pub -h "$ip" -r -t "openWB/set/lp/$chargepcp/%Soc" -m "$soc"
mosquitto_pub -h "$ip" -r -t "openWB/set/lp/$chargepcp/boolSocConfigured" -m "$socEnabled"
fi
if (( chargep == "3" ));then
echo "$VPhase1" > "$RAMDISKDIR/llvs21"
Expand Down Expand Up @@ -80,6 +84,21 @@ if [[ $(wc -l <"$outputname") -ge 5 ]]; then
mosquitto_pub -h "$ip" -r -t "openWB/set/isss/ClearRfid" -m "1"
fi

cpEnabled=$(<"$RAMDISKDIR/lp${chargep}enabled")
etEnabled=$(<"$RAMDISKDIR/mqttetprovideraktiv")
etPriceList=$(<"$RAMDISKDIR/etprovidergraphlist")
etGlobalPrice=$(<"$RAMDISKDIR/etprovidermaxprice")
etCurrentPrice=$(<"$RAMDISKDIR/etproviderprice")
etMode=$(<"$RAMDISKDIR/mqttlp${chargep}etbasedcharging")
etLocalPrice=$(<"$RAMDISKDIR/mqttlp${chargep}etchargemaxprice")
mosquitto_pub -h "$ip" -r -t openWB/set/lp/$chargepcp/ChargePointEnabled -m "$cpEnabled"
mosquitto_pub -h "$ip" -r -t openWB/set/awattar/boolAwattarEnabled -m "$etEnabled"
mosquitto_pub -h "$ip" -r -t openWB/set/awattar/pricelist -m "$etPriceList"
mosquitto_pub -h "$ip" -r -t openWB/set/awattar/MaxPriceForCharging -m "$etGlobalPrice"
mosquitto_pub -h "$ip" -r -t openWB/set/awattar/ActualPriceForCharging -m "$etCurrentPrice"
mosquitto_pub -h "$ip" -r -t openWB/config/set/sofort/lp/$chargepcp/etBasedCharging -m "$etMode"
mosquitto_pub -h "$ip" -r -t openWB/config/set/sofort/lp/$chargepcp/etChargeMaxPrice -m "$etLocalPrice"

mosquitto_pub -h "$ip" -r -t "openWB/set/isss/parentWB" -m "$myipaddress"
if (( chargepcp == "1" )); then
mosquitto_pub -h "$ip" -r -t "openWB/set/isss/parentCPlp1" -m "$chargep"
Expand Down
8 changes: 8 additions & 0 deletions runs/initRamdisk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,14 @@ initRamdisk(){
"mqttlp6etbasedcharging:-1" \
"mqttlp7etbasedcharging:-1" \
"mqttlp8etbasedcharging:-1" \
"mqttlp1etchargemaxprice:-1" \
"mqttlp2etchargemaxprice:-1" \
"mqttlp3etchargemaxprice:-1" \
"mqttlp4etchargemaxprice:-1" \
"mqttlp5etchargemaxprice:-1" \
"mqttlp6etchargemaxprice:-1" \
"mqttlp7etchargemaxprice:-1" \
"mqttlp8etchargemaxprice:-1" \
"mqttevuglaettungakt:-1" \
"mqtthausverbrauch:-1" \
"mqtthausverbrauchstat:-1" \
Expand Down
41 changes: 39 additions & 2 deletions runs/mqttsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def map_run(message: str, device_number: int, option: str):
"device_speichersocbeforestop": create_topic_handler(int_range_validator(0, 100)),
"device_maxeinschaltdauer": create_topic_handler(int_range_validator(0, 100000)),
"device_mineinschaltdauer": create_topic_handler(int_range_validator(0, 100000)),
"device_mindayeinschaltdauer": create_topic_handler(int_range_validator(0, 100000)),
"device_manual_control": create_topic_handler(int_range_validator(0, 1), (
write_ramdisk_action("smarthome_device_manual_control"), republish_action)),
"mode": create_topic_handler(int_range_validator(0, 1),
Expand Down Expand Up @@ -289,7 +290,7 @@ def on_message(client: mqtt.Client, userdata, msg: mqtt.MQTTMessage):
f.write(msg.payload.decode("utf-8"))
f.close()
client.publish("openWB/config/get/SmartHome/maxBatteryPower",
msg.payload.decode("utf-8"), qos=0, retain=True)
msg.payload.decode("utf-8"), qos=0, retain=True)
RAMDISK_PATH.joinpath("rereadsmarthomedevices").write_text("1")
if (msg.topic == "openWB/config/set/SmartHome/logLevel"):
if (int(msg.payload) >= 0 and int(msg.payload) <= 2):
Expand Down Expand Up @@ -394,12 +395,20 @@ def on_message(client: mqtt.Client, userdata, msg: mqtt.MQTTMessage):
subprocess.run(sendcommand)
if (("openWB/config/set/sofort/lp" in msg.topic) and ("etBasedCharging" in msg.topic)):
devicenumb = re.sub(r'\D', '', msg.topic)
if (1 <= int(devicenumb) <= 8 and 0 <= int(msg.payload) <= 1):
if (1 <= int(devicenumb) <= 8 and 0 <= int(msg.payload) <= 2):
client.publish("openWB/config/get/sofort/lp/"+str(devicenumb)+"/etBasedCharging",
msg.payload.decode("utf-8"), qos=0, retain=True)
sendcommand = ["/var/www/html/openWB/runs/replaceinconfig.sh", "lp" +
str(devicenumb)+"etbasedcharging=", msg.payload.decode("utf-8")]
subprocess.run(sendcommand)
if (("openWB/config/set/sofort/lp" in msg.topic) and ("etChargeMaxPrice" in msg.topic)):
devicenumb = re.sub(r'\D', '', msg.topic)
if (1 <= int(devicenumb) <= 8 and float(msg.payload) >= -50 and float(msg.payload) <= 95):
client.publish("openWB/config/get/sofort/lp/"+str(devicenumb)+"/etChargeMaxPrice",
msg.payload.decode("utf-8"), qos=0, retain=True)
sendcommand = ["/var/www/html/openWB/runs/replaceinconfig.sh", "lp" +
str(devicenumb)+"etchargemaxprice=", msg.payload.decode("utf-8")]
subprocess.run(sendcommand)
if (("openWB/config/set/sofort/lp" in msg.topic) and ("chargeLimitation" in msg.topic)):
devicenumb = re.sub(r'\D', '', msg.topic)
if (3 <= int(devicenumb) <= 8 and 0 <= int(msg.payload) <= 1):
Expand Down Expand Up @@ -1236,11 +1245,27 @@ def on_message(client: mqtt.Client, userdata, msg: mqtt.MQTTMessage):
f = open('/var/www/html/openWB/ramdisk/parentCPlp2', 'w')
f.write(msg.payload.decode("utf-8"))
f.close()
if (msg.topic == "openWB/set/awattar/boolAwattarEnabled"):
client.publish("openWB/global/awattar/boolAwattarEnabled", msg.payload.decode("utf-8"), qos=0, retain=True)
f = open('/var/www/html/openWB/ramdisk/mqttetprovideraktiv', 'w')
f.write(msg.payload.decode("utf-8"))
f.close()
if (msg.topic == "openWB/set/awattar/MaxPriceForCharging"):
if (float(msg.payload) >= -50 and float(msg.payload) <= 95):
client.publish("openWB/global/awattar/MaxPriceForCharging", msg.payload.decode("utf-8"), qos=0, retain=True)
f = open('/var/www/html/openWB/ramdisk/etprovidermaxprice', 'w')
f.write(msg.payload.decode("utf-8"))
f.close()
if (msg.topic == "openWB/set/awattar/ActualPriceForCharging"):
client.publish("openWB/global/awattar/ActualPriceForCharging", msg.payload.decode("utf-8"), qos=0, retain=True)
f = open('/var/www/html/openWB/ramdisk/etproviderprice', 'w')
f.write(msg.payload.decode("utf-8"))
f.close()
if (msg.topic == "openWB/set/awattar/pricelist"):
client.publish("openWB/global/awattar/pricelist", msg.payload.decode("utf-8"), qos=0, retain=True)
f = open('/var/www/html/openWB/ramdisk/etprovidergraphlist', 'w')
f.write(msg.payload.decode("utf-8"))
f.close()
if (msg.topic == "openWB/set/houseBattery/W"):
if (float(msg.payload) >= -30000 and float(msg.payload) <= 30000):
f = open('/var/www/html/openWB/ramdisk/speicherleistung', 'w')
Expand Down Expand Up @@ -1329,14 +1354,26 @@ def on_message(client: mqtt.Client, userdata, msg: mqtt.MQTTMessage):
client.publish("openWB/evu/faultStr", msg.payload.decode("utf-8"), qos=0, retain=True)
if (msg.topic == "openWB/set/lp/1/%Soc"):
if (float(msg.payload) >= 0 and float(msg.payload) <= 100):
client.publish("openWB/lp/1/%Soc", msg.payload.decode("utf-8"), qos=0, retain=True)
f = open('/var/www/html/openWB/ramdisk/soc', 'w')
f.write(msg.payload.decode("utf-8"))
f.close()
if (msg.topic == "openWB/set/lp/2/%Soc"):
if (float(msg.payload) >= 0 and float(msg.payload) <= 100):
client.publish("openWB/lp/2/%Soc", msg.payload.decode("utf-8"), qos=0, retain=True)
f = open('/var/www/html/openWB/ramdisk/soc1', 'w')
f.write(msg.payload.decode("utf-8"))
f.close()
if (msg.topic == "openWB/set/lp/1/boolSocConfigured"):
client.publish("openWB/lp/1/boolSocConfigured", msg.payload.decode("utf-8"), qos=0, retain=True)
f = open('/var/www/html/openWB/ramdisk/mqttsocvorhanden', 'w')
f.write(msg.payload.decode("utf-8"))
f.close()
if (msg.topic == "openWB/set/lp/2/boolSocConfigured"):
client.publish("openWB/lp/2/boolSocConfigured", msg.payload.decode("utf-8"), qos=0, retain=True)
f = open('/var/www/html/openWB/ramdisk/mqttsoc1vorhanden', 'w')
f.write(msg.payload.decode("utf-8"))
f.close()
set_pv_match = re.match(r"^openWB/set/pv/([12])/(.*)$", msg.topic)
if set_pv_match is not None:
pv = files.pv[int(set_pv_match.group(1)) - 1]
Expand Down
14 changes: 14 additions & 0 deletions runs/updateConfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,11 @@ updateConfig(){
echo "lp${i}etbasedcharging=1" >> $ConfigFile
fi
done
for i in $(seq 1 8); do
if ! grep -Fq "lp${i}etchargemaxprice=" $ConfigFile; then
echo "lp${i}etchargemaxprice=0" >> $ConfigFile
fi
done
if ! grep -Fq "plz=" $ConfigFile; then
echo "plz=36124" >> $ConfigFile
fi
Expand Down Expand Up @@ -1506,6 +1511,15 @@ updateConfig(){
if ! grep -Fq "displaylp2max=" $ConfigFile; then
echo "displaylp2max=22000" >> $ConfigFile
fi
if ! grep -Fq "displayshowprice=" $ConfigFile; then
echo "displayshowprice=0" >> $ConfigFile
fi
if ! grep -Fq "displayshowrfidpad=" $ConfigFile; then
echo "displayshowrfidpad=0" >> $ConfigFile
fi
if ! grep -Fq "displayallowsetmaxprice=" $ConfigFile; then
echo "displayallowsetmaxprice=0" >> $ConfigFile
fi
if ! grep -Fq "displaypinaktiv=" $ConfigFile; then
echo "displaypinaktiv=0" >> $ConfigFile
fi
Expand Down
35 changes: 17 additions & 18 deletions sofortlademodus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,27 @@ sofortlademodus(){
fi
if (( etprovideraktiv == 1 )); then
actualprice=$(<ramdisk/etproviderprice)

if (( $(echo "$actualprice <= $etprovidermaxprice" |bc -l) )); then
#price lower than max price, enable charging
for i in $(seq 1 8); do
myenabledvar="lp${i}enabled"
myetbasedvar="lp${i}etbasedcharging"
if (( ${!myenabledvar} == 0 && ${!myetbasedvar} == 1 )); then
openwbDebugLog "MAIN" 1 "Aktiviere Ladung (preisbasiert) für Ladepunkt $i, Preis $actualprice, Max $etprovidermaxprice"
for i in $(seq 1 $ConfiguredChargePoints); do
myenabledvar="lp${i}enabled"
myetbasedvar="lp${i}etbasedcharging"
if ((${!myetbasedvar} == 1)); then
myetpricevar="etprovidermaxprice"
else
myetpricevar="lp${i}etchargemaxprice"
fi
if (( $(echo "$actualprice <= ${!myetpricevar}" |bc -l) )); then
#price lower than max price, enable charging
if (( ${!myenabledvar} == 0 && ${!myetbasedvar} != 0 )); then
openwbDebugLog "MAIN" 1 "Aktiviere Ladung (preisbasiert) für Ladepunkt $i, Preis $actualprice, Max ${!myetpricevar}, Mode ${!myetpricevar}"
mosquitto_pub -r -t openWB/set/lp/${i}/ChargePointEnabled -m "1"
fi
done
else
#price higher than max price, disable charging
for i in $(seq 1 8); do
myenabledvar="lp${i}enabled"
myetbasedvar="lp${i}etbasedcharging"
if (( ${!myenabledvar} == 1 && ${!myetbasedvar} == 1 )); then
openwbDebugLog "MAIN" 1 "Deaktiviere Ladung (preisbasiert) für Ladepunkt $i, Preis $actualprice, Max $etprovidermaxprice"
else
if (( ${!myenabledvar} == 1 && ${!myetbasedvar} != 0 )); then
openwbDebugLog "MAIN" 1 "Deaktiviere Ladung (preisbasiert) für Ladepunkt $i, Preis $actualprice, Max ${!myetpricevar}, Mode ${!myetpricevar}"
mosquitto_pub -r -t openWB/set/lp/${i}/ChargePointEnabled -m "0"
fi
done
fi
fi
done
fi
if (( lastmmaxw < 10 ));then
lastmmaxw=40000
Expand Down
17 changes: 17 additions & 0 deletions web/display/minimal/checklock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
$lines = file($_SERVER['DOCUMENT_ROOT'] . '/openWB/openwb.conf');
foreach($lines as $line) {
list($key, $value) = explode("=", $line, 2);
${$key."old"} = trim( $value, " '\t\n\r\0\x0B" ); // remove all garbage and single quotes
}

if( array_key_exists("pin", $_REQUEST) ){
if( $_REQUEST["pin"] == $displaypincodeold) {
echo "1";
} else {
echo "0";
}
} elseif( array_key_exists("lock", $_REQUEST) ){
echo $displaypinaktivold;
}
?>
Loading

0 comments on commit f62657b

Please sign in to comment.