Skip to content

Commit

Permalink
release v1.4.0
Browse files Browse the repository at this point in the history
* feat(init): init release v1.4.0

* feat(fronius::schedule): Net power available is derived from the reserve rather than the actual battery capacity (#55)

* Feat/time reserve battery triggering (#56)

* feat(fronius::schedule): The reserve battery is now charged based on time

* feat(params): tuning parameters

* feat(doc): adding doc

* feat(ha): fixing regexp

* Update DOCS.md

* fix(ha): adding start and end battery reserve hours for export

* feat(fronius::schedule): Adding hysteresis logic when charging (#57)

* feat(fronius::schedule): Adding hysteresis logic when charging

* fix(doc): adding doc

* Update DOCS.md

* fix(test): fix test build script dir

* fix(forecast): if forecast site is unavailable disable forecast charging only (#58)
  • Loading branch information
atbore-phx authored Jan 22, 2025
1 parent 60a76d7 commit 0eb1b0b
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 171 deletions.
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Flags:
-k, --apikey string set APIKEY
-H, --fronius_ip string set FRONIUS_IP
-h, --help help for estimate
-u, --url string Set the URL. For multiple URLs, use a comma (,) to separate them
-u, --url string Set the forecast URL. For multiple URLs, use a comma (,) to separate them
```

## Schedule
Expand All @@ -98,17 +98,19 @@ Usage:
sbam schedule [flags]

Flags:
-k, --apikey string APIKEY
-t, --crontab string CRONTAB (default "0 0 0 0 0")
-d, --defaults DEFAULTS (default true)
-e, --end_hr string END_HR (default "05:55")
-H, --fronius_ip string FRONIUS_IP
-h, --help help for schedule
-m, --max_charge float MAX_CHARGE (default 3500)
-r, --pw_batt_reserve float PW_BATT_RESERVE
-c, --pw_consumption float PW_CONSUMPTION
-s, --start_hr string START_HR (default "00:00")
-u, --url string Set the URL. For multiple URLs, use a comma (,) to separate them
-k, --apikey string APIKEY
-E, --batt_reserve_end_hr string BATT_RESERVE_END_HR (default END_HR)
-S, --batt_reserve_start_hr string BATT_RESERVE_START_HR (default START_HR)
-t, --crontab string CRONTAB (default "0 0 0 0 0")
-d, --defaults DEFAULTS (default true)
-e, --end_hr string END_HR (default "00:55")
-H, --fronius_ip string FRONIUS_IP
-h, --help help for schedule
-m, --max_charge float MAX_CHARGE (default 3500)
-r, --pw_batt_reserve float PW_BATT_RESERVE
-c, --pw_consumption float PW_CONSUMPTION
-s, --start_hr string START_HR (default "00:00")
-u, --url string Set the Forecast URL. For multiple URLs, use a comma (,) to separate them
```

## Debug Logs
Expand Down
19 changes: 11 additions & 8 deletions home-assistant/addons/sbam/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ Do not start yet but configure it:
7. **crontab:** Crontab to run sbam (default: 00 00-05 \* \* \* so At minute 0 past every hour from 0 through 5.); with **two** URLs: **CET**: 10 00,03,05,06 \* \* \* (At minute 10 past hour 0, 3, 5, and 6), **UTC**: Add 1 additional hour per API call (e.g., 10 00,03,05,06,07 \* \* \*). Frequent calls are scheduled near the end time to improve forecast accuracy and allow time for charging
8. **pw_consumption:** Daily electrical consumption in Wh (Default: 11000, means 11kWh)
9. **max_charge:** Maximum amount of power required from the electricity network to charge the battery in W (Default: 3500)
10. **pw_batt_reserve:** Minimum battery capacity to maintain in Wh (Default: 4000, means 4kWh)
11. **defaults:** At the end of the crontab cycle, reconfigure the Fronius inverter to default (automatic management).
12. **reset:** At the add-on boot, reconfigure the Fronius inverter to its default settings.
13. **debug:** Increase the log level to debug, for example, printing Modbus read/write operations.

and save

![chrome_9b0blNNJ0n](https://github.com/user-attachments/assets/6244a7ba-e10c-44c9-8482-f7642ff6f7ee)
10. **pw_lwt:** The hysteresis logic lower threshold **offset** in Wh to stop charging (Default: 0)
11. **pw_upt:** The hysteresis logic upper threshold **offset** in Wh to start charging (Default: 0)
12. **pw_batt_reserve:** Minimum battery capacity to maintain in Wh (Default: 4000, means 4kWh)
13. **batt_reserve_start_hr:** The start time to activate battery reserve charging (if empty default **start_hr**)
14. **batt_reserve_end_hr:** The end time to activate battery reserve charging (if empty default **end_hr**)
15. **defaults:** At the end of the crontab cycle, reconfigure the Fronius inverter to default (automatic management).
16. **reset:** At the add-on boot, reconfigure the Fronius inverter to its default settings.
17. **debug:** Increase the log level to debug, for example, printing Modbus read/write operations.
18. finally click on **save**

![sbam-conf](https://github.com/user-attachments/assets/51df5a4a-d355-4d37-ba62-f86451c6fb08)


Finally Start **sbam**!
Expand Down
10 changes: 9 additions & 1 deletion home-assistant/addons/sbam/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sbam",
"version": "1.3.9",
"version": "1.4.0",
"slug": "sbam",
"init": "false",
"description": "Smart Battery Advanced Manager",
Expand All @@ -16,7 +16,11 @@
"crontab": "00 00-05 * * *",
"pw_consumption": "11000",
"max_charge": "3500",
"pw_lwt": "0",
"pw_upt": "0",
"pw_batt_reserve": "4000",
"batt_reserve_start_hr": "",
"batt_reserve_end_hr": "",
"defaults": true,
"reset": false,
"debug": false
Expand All @@ -30,7 +34,11 @@
"crontab": "match(^((((\\d+,)+\\d+|(\\d+(\/|-|#)\\d+)|\\d+L?|\\*(\/\\d+)?|L(-\\d+)?|\\?|[A-Z]{3}(-[A-Z]{3})?) ?){5,7})|(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|(@every (\\d+(ns|us|µs|ms|s|m|h))+)$)",
"pw_consumption": "float",
"max_charge": "float",
"pw_lwt": "float",
"pw_upt": "float",
"pw_batt_reserve": "float",
"batt_reserve_start_hr": "match(^$|^([01]?[0-9]|2[0-3]):[0-5][0-9]$)",
"batt_reserve_end_hr": "match(^$|^([01]?[0-9]|2[0-3]):[0-5][0-9]$)",
"defaults": "bool",
"reset": "bool",
"debug": "bool"
Expand Down
4 changes: 4 additions & 0 deletions home-assistant/addons/sbam/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ export END_HR=$(bashio::config 'end_hr')
export CRONTAB=$(bashio::config 'crontab')
export PW_CONSUMPTION=$(bashio::config 'pw_consumption')
export MAX_CHARGE=$(bashio::config 'max_charge')
export PW_LWT=$(bashio::config 'pw_lwt')
export PW_UPT=$(bashio::config 'pw_upt')
export PW_BATT_RESERVE=$(bashio::config 'pw_batt_reserve')
export BATT_RESERVE_START_HR=$(bashio::config 'batt_reserve_start_hr')
export BATT_RESERVE_END_HR=$(bashio::config 'batt_reserve_end_hr')
export DEFAULTS=$(bashio::config 'defaults')
export RESET=$(bashio::config 'reset')
export DEBUG=$(bashio::config 'debug')
Expand Down
7 changes: 4 additions & 3 deletions home-assistant/addons/test_local.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/bin/bash
set -euo pipefail

BUILDCONTAINER_DATA_PATH="/data"
PATHTOBUILD="$BUILDCONTAINER_DATA_PATH"
ARCH=amd64


PROJECTDIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/sbam
ROOTDIR=$PROJECTDIR/../../../
cd $PRROOTDIROJECTDIR/../../../
ROOTDIR=${PROJECTDIR}/../../../
cd ${PROJECTDIR}/../../../
make build
cd -

Expand All @@ -21,4 +22,4 @@ echo "build container data path is $BUILDCONTAINER_DATA_PATH"
echo "build container target build path is $PATHTOBUILD"
CMD="docker run --rm -ti --name hassio-builder --privileged -v $PROJECTDIR:$BUILDCONTAINER_DATA_PATH -v /var/run/docker.sock:/var/run/docker.sock:ro homeassistant/amd64-builder --target $PATHTOBUILD --$ARCH --test --docker-hub local"
echo "$CMD"
$CMD
$CMD
30 changes: 8 additions & 22 deletions pkg/cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"errors"
"os"
"sbam/pkg/fronius"
u "sbam/src/utils"
"strings"
Expand All @@ -11,7 +10,6 @@ import (
"github.com/spf13/viper"
)


var c_defaults bool
var force_charge bool
var power int
Expand All @@ -23,22 +21,10 @@ var cfgCmd = &cobra.Command{
Short: "Configure Battery Storage Charge",
Long: `connect via modbus to the fronius inverter and set charging`,
Run: func(cmd *cobra.Command, args []string) {
if len(fronius_ip) == 0 { fronius_ip = viper.GetString("fronius_ip") }
if !c_defaults {
if _, exists := os.LookupEnv("DEFAULTS"); exists {
c_defaults = viper.GetBool("defaults")
}
}
if !force_charge {
if _, exists := os.LookupEnv("FORCE_CHARGE"); exists {
force_charge = viper.GetBool("force_charge")
}
}
if power == const_pw {
if _, exists := os.LookupEnv("POWER"); exists {
power = viper.GetInt("power")
}
}
fronius_ip = viper.GetString("fronius_ip")
c_defaults = viper.GetBool("defaults")
force_charge = viper.GetBool("force_charge")
power = viper.GetInt("power")

err := checkConfigure(fronius_ip)
if err != nil {
Expand All @@ -52,10 +38,10 @@ var cfgCmd = &cobra.Command{
}

func init() {
cfgCmd.Flags().StringVarP(&fronius_ip,"fronius_ip", "H", "", "set FRONIUS_IP")
cfgCmd.Flags().BoolVarP(&c_defaults,"defaults", "d", false, "set DEFAULTS")
cfgCmd.Flags().BoolVarP(&force_charge,"force_charge", "f", false, "set FORCE_CHARGE")
cfgCmd.Flags().IntVarP(&power,"power", "p", const_pw, "set percent of nominal POWER")
cfgCmd.Flags().StringVarP(&fronius_ip, "fronius_ip", "H", "", "set FRONIUS_IP")
cfgCmd.Flags().BoolVarP(&c_defaults, "defaults", "d", false, "set DEFAULTS")
cfgCmd.Flags().BoolVarP(&force_charge, "force_charge", "f", false, "set FORCE_CHARGE")
cfgCmd.Flags().IntVarP(&power, "power", "p", const_pw, "set percent of nominal POWER")
viper.BindPFlag("fronius_ip", cfgCmd.Flags().Lookup("fronius_ip"))
viper.BindPFlag("defaults", scdCmd.Flags().Lookup("defaults"))
viper.BindPFlag("force_charge", cfgCmd.Flags().Lookup("force_charge"))
Expand Down
16 changes: 5 additions & 11 deletions pkg/cmd/estimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@ var estCmd = &cobra.Command{
Short: "Estimate Forecast Solar Power",
Long: `Print the solar forecast and the battery storage power`,
Run: func(cmd *cobra.Command, args []string) {
if len(e_url) == 0 {
e_url = viper.GetString("url")
}
if len(e_apiKey) == 0 {
e_apiKey = viper.GetString("apikey")
}
if len(fronius_ip) == 0 {
fronius_ip = viper.GetString("fronius_ip")
}
e_url = viper.GetString("url")
e_apiKey = viper.GetString("apikey")
fronius_ip = viper.GetString("fronius_ip")

err := CheckEstimate(e_apiKey, e_url, fronius_ip)
if err != nil {
Expand All @@ -40,7 +34,7 @@ var estCmd = &cobra.Command{
}

func init() {
estCmd.Flags().StringVarP(&e_url, "url", "u", "", "Set the URL. For multiple URLs, use a comma (,) to separate them")
estCmd.Flags().StringVarP(&e_url, "url", "u", "", "Set the forecast URL. For multiple URLs, use a comma (,) to separate them")
estCmd.Flags().StringVarP(&e_apiKey, "apikey", "k", "", "set APIKEY")
estCmd.Flags().StringVarP(&fronius_ip, "fronius_ip", "H", "", "set FRONIUS_IP")

Expand All @@ -67,7 +61,7 @@ func CheckEstimate(apiKey string, url string, fronius_ip string) error {

func estimate(apiKey string, url string, fronius_ip string) {
pwr := pw.New()
_, err := pwr.Handler(apiKey, url)
_, _, err := pwr.Handler(apiKey, url)
if err != nil {
u.Log.Error(err)
panic(err)
Expand Down
Loading

0 comments on commit 0eb1b0b

Please sign in to comment.