diff --git a/scripts/controller.sh b/scripts/controller.sh index b3f3927..c661845 100644 --- a/scripts/controller.sh +++ b/scripts/controller.sh @@ -1,6 +1,6 @@ #!/bin/bash -VERSION="2.4.1-DEV" +VERSION="2.4.3-DEV" set -e @@ -29,7 +29,6 @@ else ["shellyuser"]="string" ["shellypasswd"]="string" ["use_victron_charger"]="0|1" - ["disable_inverting_while_only_switching"]="0|1" ["limit_inverter_power_after_enabling"]="^(-1|[0-9]{2,5})$" ["energy_loss_percent"]="[0-9]+(\.[0-9]+)?" ["battery_lifecycle_costs_cent_per_kwh"]="[0-9]+(\.[0-9]+)?" @@ -636,6 +635,11 @@ check_abort_condition() { # Function to manage fritz sockets and log a message manage_fritz_sockets() { local action=$1 + + if [ "$execute_switchablesockets_on" -eq 0 ]; then + log_message "I: execute_switchablesockets_on is 0. Exiting manage_fritz_sockets." + return + fi [ "$action" != "off" ] && action=$([ "$execute_switchablesockets_on" == "1" ] && echo "on" || echo "off") @@ -689,6 +693,11 @@ fritz_login() { manage_shelly_sockets() { local action=$1 + if [ "$execute_switchablesockets_on" -eq 0 ]; then + log_message "I: execute_switchablesockets_on is 0. Exiting manage_shelly_sockets." + return + fi + [ "$action" != "off" ] && action=$([ "$execute_switchablesockets_on" == "1" ] && echo "on" || echo "off") log_message "I: Turning $action Shelly sockets." @@ -798,26 +807,39 @@ fi if [ -f "$DIR/$CONFIG" ]; then source "$DIR/$CONFIG" -for ((i=1; i<=24; i++)); do - hour=$i - row=(${config_matrix24[$i]}) - charge_value="${row[0]}" - discharge_value="${row[1]}" - switchable_sockets_value="${row[2]}" - hour_var_name="${hour//[^a-zA-Z0-9]/_}" - - charge_var_name="charge_at_${hour_var_name}" - discharge_var_name="discharge_at_${hour_var_name}" - switchable_sockets_var_name="switchablesockets_at_${hour_var_name}" - - declare "$charge_var_name=$charge_value" - declare "$discharge_var_name=$discharge_value" - declare "$switchable_sockets_var_name=$switchable_sockets_value" - echo "$charge_var_name=$charge_value" - echo "$discharge_var_name=$discharge_value" - echo "$switchable_sockets_var_name=$switchable_sockets_value" -done + # Separate arrays for each column + config_matrix24_charge=() + config_matrix24_discharge=() + config_matrix24_switchablesockets=() + + # Populate separate arrays + for ((i=0; i<25; i++)); do + row=(${config_matrix24_price[$i]}) + config_matrix24_charge+=("${row[0]}") + config_matrix24_discharge+=("${row[1]}") + config_matrix24_switchablesockets+=("${row[2]}") + done + # Use the separate arrays + for ((i=1; i<=24; i++)); do + hour=$i + charge_value="${config_matrix24_charge[$i]}" + discharge_value="${config_matrix24_discharge[$i]}" + switchable_sockets_value="${config_matrix24_switchablesockets[$i]}" + hour_var_name="${hour//[^a-zA-Z0-9]/_}" + + charge_var_name="charge_at_${hour_var_name}" + discharge_var_name="discharge_at_${hour_var_name}" + switchable_sockets_var_name="switchablesockets_at_${hour_var_name}" + + declare "$charge_var_name=$charge_value" + declare "$discharge_var_name=$discharge_value" + declare "$switchable_sockets_var_name=$switchable_sockets_value" + + echo "$charge_var_name=$charge_value" + echo "$discharge_var_name=$discharge_value" + echo "$switchable_sockets_var_name=$switchable_sockets_value" + done else log_message "E: The file $DIR/$CONFIG was not found! Configure the existing sample.config.txt file and then save it as config.txt in the same directory." false exit 127 @@ -1076,6 +1098,7 @@ else fi charging_condition_met="" +discharging_condition_met="" switchablesockets_condition_met="" execute_charging=0 execute_discharging=0 diff --git a/scripts/sample.config.txt b/scripts/sample.config.txt index 15c3734..e96c45c 100644 --- a/scripts/sample.config.txt +++ b/scripts/sample.config.txt @@ -39,36 +39,36 @@ switchablesockets_at_solar_breakeven_logic=0 # [5]="0 0 0" Charging and switching and ESS is disabled at 5th lowest price. # [24]="0 1 0" ESS discharging is disabled at highest price (dont use second day data). -declare -A config_matrix24=( - ["Price"]="Charge Discharge Switch" - [1]="1 0 1" - [2]="1 0 1" - [3]="0 0 0" - [4]="0 0 0" - [5]="0 0 0" - [6]="0 0 0" - [7]="0 0 0" - [8]="0 0 0" - [9]="0 0 0" - [10]="0 0 0" - [11]="0 0 0" - [12]="0 0 0" - [13]="0 0 0" - [14]="0 0 0" - [15]="0 0 0" - [16]="0 0 0" - [17]="0 0 0" - [18]="0 0 0" - [19]="0 0 0" - [20]="0 1 0" - [21]="0 1 0" - [22]="0 1 0" - [23]="0 1 0" - [24]="0 1 0" +config_matrix24_price=( + "Charge Discharge Switch" # [0] Header + "1 0 1" # [1] Price 1 + "1 0 1" # [2] Price 2 + "0 0 0" # [3] Price 3 + "0 0 0" # [4] Price 4 + "0 0 0" # [5] Price 5 + "0 0 0" # [6] Price 6 + "0 0 0" # [7] Price 7 + "0 0 0" # [8] Price 8 + "0 0 0" # [9] Price 9 + "0 0 0" # [10] Price 10 + "0 0 0" # [11] Price 11 + "0 0 0" # [12] Price 12 + "0 0 0" # [13] Price 13 + "0 0 0" # [14] Price 14 + "0 0 0" # [15] Price 15 + "0 0 0" # [16] Price 16 + "0 0 0" # [17] Price 17 + "0 0 0" # [18] Price 18 + "0 0 0" # [19] Price 19 + "0 1 0" # [20] Price 20 + "0 1 0" # [21] Price 21 + "0 1 0" # [22] Price 22 + "0 1 0" # [23] Price 23 + "0 1 0" # [24] Price 24 ) TZ='Europe/Amsterdam' # Set Correct Timezone -select_pricing_api=3 # Set to +select_pricing_api=1 # Set to # 1 for aWATTar or # 2 for entsoe or # 3 for Tibber