[Fronius] [Add-on] sbam: charge solar battery based on weather forecast

Hi guys,

i’ve developped the sbam addons (Smart Battery Advanced Manager) to control your solar battery through a Fronius inverter.
The battery charging is configured based on the weather forecast by utilizing the Solcast weather forecast API.

After installing a Fronius Gen24 plus Solar system including a BYD battery, I wanted during months of low solar production to charge the battery at night when electricity costs are generally lower, in order to use the stored energy during the day.

Fronius through the local web interface reachable from the inverter’s LAN IP provides the Battery Management utility → Time-dependent battery control.

Indeed, it is possible to charge at night, but the process is static. Many times, I found the battery to be either too charged or too discharged the next day. I wanted something more advanced, dynamic, and adaptive that takes into account:

  • weather forecasts
  • daily electricity consumption related to my home
  • the current battery charge
  • the minimum reserve of the battery not to go below
  • the time range when the energy operator offers cheaper electricity to force the charge.

Here sbam is all this and much more :slight_smile:

add-on doc: here

github: here

:warning:
N.B. This post is rarely monitored and is for announcements only. For help, bug reports, or feature requests, please use the GitHub issues.

2 Likes

Is there an easy way to trace what this is doing?

I’ve tried it standalone because I wanted to try it in a controlled manner before I let it loose on my inverter. But although I have compiled the go on my Mac, I’m obviously not understanding the instructions because something simple like

sbam estimate

just results in an error stating I didn’t supply the Fronius IP address (But I did. I tried both --fronius_ip and -H)

It does appear to work when you set them via ENV vars though… So maybe it’s just the docs that aren’t matching reality?

There doesn’t appear to be any objects to put on the dashboard… I admit I don’t like things like that…

hi @hamish2,
Thanks for testing,
yes you have found a bug, i have refactored the cmd line during last version to support HA addons, maybe a i’ve broken the parameters :slight_smile: so i’ll fix next days.

The HA add-on is still working and in meantime if you want test via cli you can also use a config file:

just create outside the directory bin a config.yaml file

|
|_config.yaml
|_bin/
     |_sbam

with this content:

url: 'https://api.solcast.com.au/rooftop_sites/<your_site>/forecasts?format=json'
apikey: '<your_api-key>'
fronius_ip: '<your fronius_ip>'

and execute:

bin/sbam estimate

P.S

  • sbam is an HA addons not a service so it is not visible on the dashboard as a object, but via the addons menu.

P.P.S
the project is opensource and free of any fee so if anyone want make a PR on github do not hesitate ! You will be welcome !

Best

1 Like

Thanks.

It looks very useful. But I think I will need to make some mods…

  • Our cheap night rates start before midnight and go till some time in the morning. Currently the code doesn’t allow that.
  • I need a simulation mode… Mainly for my own testing. I don’t want to accidentally break what my inverter is doing :slight_smile:
  • The user interface. It’s true, I don’t really understand a lot about HA. Up till recently I was running OpenHab, and before that another automation product. So HA is a new one for me

I did also discover someone had been using the modbus plugin with nodejs. So now I have that to look at as well. It’s possible that I might prefer sbam (Because it’ll look after the nitty gritty of updating the inverter for me), with the ability for nodejs to run more complex logic and callout to sbam. We’ll see how much time I can spare

Oh… And this causes an issue too…

This causes…

Luckily I hadn’t yet enabled modbus in the inverter, because if I had, I’d be chewing power from the grid trying to charge the battery at peak time… While in good sunlight…

An edge case to be sure.

I’m pretty sure I get predictions from HA already… So it would be nice to be able to use those as well as an option instead of the solecast one.

hi @hamish2,
i’m really glad about your tests !!

some news:

answers:

  • Our cheap night rates start before midnight and go till some time in the morning. Currently the code doesn’t allow that.

you’re right start_hr must be before end_hr, other cases need to be handled indeed. next feature for sure.

for info:
sbam configures your cheap rate setting start_hr and end_hr parameters (cf. sbam schedule --help) and you can also limit the sbam execution via a crontab timetable

for eg. in mycheap rate is between start_hr=00:00 and end_hr=07:00
and sbam sets the charge every hour btw midnight and 05:00 in the morning so
crontab=00 00-05 * * * so 5 executions (1 for hour) and 5 API call

I need a simulation mode… Mainly for my own testing. I don’t want to accidentally break what my inverter is doing :slight_smile:

a --dry-run option will be awsome indeed, i’ll try to figure out how i could implement that, i work on sbam in my spare time you know … it is a really good idea for a next feature.
In meantime you could simulate fronius http and tcp/modbus via mock servers … i do that in my unit tests for eg.

you have used all 10 API requests

it’s the Solcast free acount daily limit. just create a new account for testing …

and yes u right we need to handle the case to avoid wrong prediction when your limit is reached. (issue noted)

sure we could integrate different solar providers, next features for sure.

i’ve chosen Solcast because it seems the most complete one in term of feature by the way (it uses a real weather forecast also for the free account).

enjoy sbam :wink:
Best

@hamish2 Do you like golang :slight_smile: ? it will be awsome have a new contributor !

Do I like golang?

Well… It’s more preferable than python… syntax by whitespace… shudder… I was developing in golang (And perl) for a while in my previous job until the end of '22. I miss it a lot actually. I like C better… And definitely more fluent in C and perl. But golang kind of grew on me after a while.

1 Like

Hi @atbore-phx

I am in the UK and my Electricity provider ( Octopus ) offer a tarrif call Agile.
With Agile Octopus, you get access to half-hourly energy prices, tied to wholesale prices and updated daily.
This allow customers to charge their batteries at different times and not set to a night time schedule.

Is there in way to incorporate this into SBAM / HAOS?
Look forward to your response

This would be a good start for me, although I would still need support for dynamic energy prices (I get hourly price changes through my energy provider) to react to cheap or even free energy.
Sometimes I even get money for consuming from the grid, I’d be a fool not to use it to charge the battery :grin:
The pricing is readily available for me as HA sensor values and a forecast.

However, I run HomeAssistant (and everything else) as standalone docker containers, not as HAOS, so I can’t install addons, only integrations via HACS.

Is there any way I could get this running in my case?
If not then I think my best bet would be to build something myself via Python Script Automation and Modbus. I already get values via SolarAPI from the inverter.

Hi @sunsheep ,
sbam has been developed to be general and electricity provider indipendent.

At this time you can set these parameters to cover different scenarios:

  -t, --crontab string          crontab (default "0 0 0 0 0")
 
  -e, --end_hr string           END_HR (default "05:55")

  -s, --start_hr string         START_HR (default "00:00")

for eg.:
-s 00:00 -e 23:59 -t "*/30 * * * *" → At every 30th minute
or
-s 00:00 -e 23:59 -t "*/30 01-12 * * *" → At every 30th minute past every hour from 1 through 12.
etc … so basically covering all day with start_hr and end_hr and triggering sbam frequency with the crontab (cron - Wikipedia).

These parameters are availiable via cli or in the add-ons setting page.

hi @SilverFolfy, sbam is also availible as stand alone binary Releases · atbore-phx/sbam · GitHub, but you need to integrate in your docker or to trigger by a wrapper script etc… for custom use.
HAOS is the easier install of course.

@atbore-phx Thanks, I might try this or roll my own automation, either way it will certainly be a lot of trial and error and learning, but I’m in no hurry :smiley:

Hi Atbore-phx
I assume HR = High Rate?
Let me think of all the scenarios and come back with a sample matrix to validate/

Hi @sunsheep,
hr in parameters ? It’s a short of “hour” (an abbreviation).

hi @atbore-phx

Ok, a little lost.
Does the weather lookup in turn set the invertor to start charging and stop charging the battery.
Does this mean that if I download the schedule from the energy provider and manipulate crontab I will get the result I want?
Where in the world are you located?

There is a similar addon out there: GitHub - muexxl/batcontrol_addon

it actually can hold 2 solar forecast sites (like east/west installations).

Maybe you guys, @atbore-phx and Batcontrol: Gen24 + Batterie + Tibber = Geld sparen - Fronius - Wechselrichter - Photovoltaikforum , can work together and get the best out of both addons ?!

hi goeste,
i have an issue for that feature on my github: Suggestions for new functionality · Issue #22 · atbore-phx/sbam · GitHub
multiples array is a super feature indeed, the sbam project is opensource so everyone can join and contribute via a Pull Request.

hello,
:warning:
I propose to move all discussions to GitHub: Issues · atbore-phx/sbam · GitHub.
It will be easier to centralize every issue, feature, or topic for the SBAM project!
I’ll answer there, and I’m leaving this thread unmonitored.

@goeste, the support for multiple sites (max. 2) in sbam is now complete in version 1.3.8!

bin/sbam estimate -H <your Fronius ip> -k <your solcast api-key> -u "https://api.solcast.com.au/rooftop_sites/<your-site1>/forecasts?format=json, https://api.solcast.com.au/rooftop_sites/<your-site2>/forecasts?format=json"


{"level":"info","ts":"2024-11-09T11:00:18+01:00","msg":"Starting Calculate PV production for solar System 0"}
{"level":"info","ts":"2024-11-09T11:00:18+01:00","msg":"Forecast Solar Power for 9/11/2024: 8022 Wh"}
{"level":"info","ts":"2024-11-09T11:00:19+01:00","msg":"Starting Calculate PV production for solar System 1"} 
{"level":"info","ts":"2024-11-09T11:00:19+01:00","msg":"Forecast Solar Power for 9/11/2024: 8022 Wh"}
{"level":"info","ts":"2024-11-09T11:00:19+01:00","msg":"Total Forecast Solar Power for 9/11/2024: 16044 Wh"}
{"level":"info","ts":"2024-11-09T11:00:19+01:00","msg":"Battery Capacity to charge: 5308 Wh"} 
{"level":"info","ts":"2024-11-09T11:00:19+01:00","msg":"Battery Capacity Max: 11059 Wh"}
1 Like