Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #194

Closed
wants to merge 8 commits into from
Closed

Dev #194

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Supported systems are currently:
- Shelly products (such as [Shelly Plug S](https://shellyparts.de/products/shelly-plus-plug-s) or [Shelly Plus](https://shellyparts.de/products/shelly-plus-1pm))
- [AVMFritz!DECT200](https://avm.de/produkte/smart-home/fritzdect-200/) and [210](https://avm.de/produkte/smart-home/fritzdect-210/) switchable sockets
- [Victron](https://www.victronenergy.com/) Venus OS Energy Storage Systems like the [MultiPlus-II series](https://www.victronenergy.com/inverters-chargers) (Dbus at localhost and MQTT by LAN is supported)
- [sonnen](https://www.sonnen.de/) AC-AC systems like [sonnen Batterie 10](https://sonnen.de/stromspeicher/sonnenbatterie-10/). Tested with software version 1.15.6 over LAN at a standalone system without SonnenCommunity or sonnenVPP.
- [other MQTT charger](http://www.steves-internet-guide.com/mosquitto_pub-sub-clients/) (chargers that are controlable by mosquitto MQTT commands)

Getting Started:
Expand Down
110 changes: 72 additions & 38 deletions scripts/controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,22 @@ checkAndClean() {
fi
}

fetch_prices() {
if [ "$select_pricing_api" -eq 1 ]; then
Unit="Cent/kWh $price_unit price"
get_awattar_prices
get_awattar_prices_integer
elif [ "$select_pricing_api" -eq 2 ]; then
Unit="EUR/MWh net"
get_entsoe_prices
get_prices_integer_entsoe
elif [ "$select_pricing_api" -eq 3 ]; then
Unit="EUR/kWh $price_unit price"
get_tibber_prices
get_tibber_prices_integer
fi
}

####################################
### Begin of the script... ###
####################################
Expand Down Expand Up @@ -1174,41 +1190,40 @@ fi

if [ "$use_charger" == "4" ]; then

SOC_percent=$(curl --max-time 5 --header "Auth-Token: $sonnen_API_KEY" "$sonnen_API_URL/latestdata" | awk -F'[,{}:]' '{for(i=1;i<=NF;i++) if ($i ~ /"USOC"/) print $(i+1)}')
SOC_percent=$(curl --max-time 5 --header "Auth-Token: $sonnen_API_KEY" "$sonnen_API_URL/latestdata" | awk -F'[,{}:]' '{for(i=1;i<=NF;i++) if ($i ~ /"USOC"/) print $(i+1)}')

if [ -z "$SOC_percent" ]; then
log_message >&2 "E: Timeout while trying to read RSOC from the charger."
exit 1
fi

charger_command_charge() {
log_message >&2 "I: Executing curl -X PUT -d EM_USOC="$target_soc" --header "Auth-Token: $sonnen_API_KEY" "$sonnen_API_URL/configurations""
curl -X PUT -d EM_USOC="$target_soc" --header "Auth-Token: $sonnen_API_KEY" "$sonnen_API_URL/configurations"
}

charger_command_stop_charging() {
log_message >&2 "I: Executing curl -X PUT -d EM_USOC=0 --header "Auth-Token: $sonnen_API_KEY" "$sonnen_API_URL/configurations""
curl -X PUT -d EM_USOC=0 --header "Auth-Token: $sonnen_API_KEY" "$sonnen_API_URL/configurations"
}
charger_command_charge() {
log_message >&2 "I: Executing curl -X PUT -d EM_USOC=$target_soc --header \"Auth-Token: $sonnen_API_KEY\" $sonnen_API_URL/configurations"
curl -X PUT -d "EM_USOC=$target_soc" --header "Auth-Token: $sonnen_API_KEY" "$sonnen_API_URL/configurations"
}

charger_command_set_SOC_target() {
echo Nothing to do at sonnen charger. >nul
}
charger_command_stop_charging() {
log_message >&2 "I: Executing curl -X PUT -d EM_USOC=0 --header \"Auth-Token: $sonnen_API_KEY\" $sonnen_API_URL/configurations"
curl -X PUT -d "EM_USOC=0" --header "Auth-Token: $sonnen_API_KEY" "$sonnen_API_URL/configurations"
}

charger_disable_inverter() {
if ((charging == 0)); then
log_message >&2 "I: Executing curl -X PUT -d EM_USOC="$SOC_percent" --header "Auth-Token: $sonnen_API_KEY" "$sonnen_API_URL/configurations""
curl -X PUT -d EM_USOC="$SOC_percent" --header "Auth-Token: $sonnen_API_KEY" "$sonnen_API_URL/configurations"
fi
}
charger_command_set_SOC_target() {
echo "Nothing to do at sonnen charger." >/dev/null
}

charger_enable_inverter() {
if ((charging == 0)); then
log_message >&2 "I: Executing curl -X PUT -d EM_USOC=0 --header "Auth-Token: $sonnen_API_KEY" "$sonnen_API_URL/configurations""
curl -X PUT -d EM_USOC=0 --header "Auth-Token: $sonnen_API_KEY" "$sonnen_API_URL/configurations"
fi
}
charger_disable_inverter() {
if ((charging == 0)); then
log_message >&2 "I: Executing curl -X PUT -d EM_USOC=$SOC_percent --header \"Auth-Token: $sonnen_API_KEY\" $sonnen_API_URL/configurations"
curl -X PUT -d "EM_USOC=$SOC_percent" --header "Auth-Token: $sonnen_API_KEY" "$sonnen_API_URL/configurations"
fi
}

charger_enable_inverter() {
if ((charging == 0)); then
log_message >&2 "I: Executing curl -X PUT -d EM_USOC=0 --header \"Auth-Token: $sonnen_API_KEY\" $sonnen_API_URL/configurations"
curl -X PUT -d "EM_USOC=0" --header "Auth-Token: $sonnen_API_KEY" "$sonnen_API_URL/configurations"
fi
}
fi

for tool in $tools; do
Expand Down Expand Up @@ -1372,19 +1387,7 @@ if [ "$include_second_day" = 1 ]; then

fi

if ((select_pricing_api == 1)); then
Unit="Cent/kWh $price_unit price"
get_awattar_prices
get_awattar_prices_integer
elif ((select_pricing_api == 2)); then
Unit="EUR/MWh net"
get_entsoe_prices
get_prices_integer_entsoe
elif ((select_pricing_api == 3)); then
Unit="EUR/kWh $price_unit price"
get_tibber_prices
get_tibber_prices_integer
fi
fetch_prices

if ((use_solarweather_api_to_abort == 1)); then
download_solarenergy
Expand Down Expand Up @@ -1415,6 +1418,37 @@ for i in $(seq 1 $loop_hours); do
fi
done
log_message >&2 "I: Sorted prices: $price_table"
if [ "$include_second_day" -eq 1 ]; then
price_count=$(echo "$price_table" | grep -oE '[0-9]+:[0-9]+\.[0-9]+' | wc -l)
log_message >&2 "D: number of prices: $price_count"

if [ "$price_count" -le 24 ]; then
current_hour=$(date +%H)
if [ "$current_hour" -eq 13 ]; then
log_message >&2 "I: time is > 13:00 and price data delayed. Extra checking and waiting for new prices every 5 minutes..."
while [ "$current_hour" -eq 13 ]; do
fetch_prices
price_table=""
for i in $(seq 1 $loop_hours); do
eval price=\$P$i
price_table+="$i:$price "

if [ $((i % 12)) -eq 0 ]; then
price_table+="\n "
fi
done
log_message >&2 "I: Sorted prices: $price_table"
price_count=$(echo "$price_table" | tr ' ' '\n' | wc -l)
if [ "$price_count" -gt 24 ]; then
break
else
sleep 300
fi
current_hour=$(date +%H)
done
fi
fi
fi

if [ "$loop_hours" = 24 ]; then

Expand Down
Loading