• Have you tried out dark mode?! Scroll to the bottom of any page to find a sun or moon icon to turn dark mode on or off!

diy solar

diy solar

Homebrew "BMS" ESP32 + SmartShunt to SMA Pylontech CAN bus on Sunny Island

Consumerbot3418

Fitting square pegs into round holes... for fun?
Joined
Jan 17, 2021
Messages
293
Location
35.4, -94.43
Not sure if it qualifies as an "advanced user experiment", but I'm presently driving my SMA Sunny Island 6048-US-10 inverters in Li-Ion BMS mode, using an ESP32 ($5), CAN board ($9), and Victron SmartShunt. (probably ought to pick a different CAN board, as this one isn't galvanically isolated)

I was inspired by @sijones2010 and his project, but needed to do some tweaking, such as manual override of the reported SoC, in order to remotely command (trick) my Sunny Islands into connecting to grid and charge.

The ESP32 is running ESPHome, and integrates nicely with Home Assistant, which is where all my off-grid control and monitoring happens.

I'm able to send the BMS messages demanded by Sunny Island, and am working on decoding the CAN messages intended for SunnyRemote, as explained by @madsci1016 in the history section here.

I am already able to manually control charge. Would like to eventually automate a retarded charge current when temperature gets too high or low, or SoC over 90%, as well as backfeed grid with a specified amount of power. As a proof of concept, setting BMS voltage limit slightly below present battery voltage will cause SI to backfeed until voltage drops below BMS voltage limit.

I've observed that SI subtracts 1V from the BMS voltage limit when off-grid. This would make it difficult to ever reach 100% SoC while off-grid with AC coupling. Wonder if anyone else has already solved this issue? I could command a higher voltage, but I guess the problem would be if a large load powered off while batteries are (nearly) full, and AC coupled PV is pumping out 10kW+. 🤔

Screenshot 2024-08-14 at 12.54.06 PM.png
 
Last edited:
Not beyond the screenshot of the ESP32's web server, but I could, if there's interest.

What was it you'd like to see, exactly?
So you connect the sunny island to the esp device and it has an ip address you can log into to make changes? How does the smart shunt connect?
 
Last edited:
Pretty much, yeah. But the web interface accessible via IP address probably won't get used much--the same controls are exposed in Home Assistant, and can be controlled with automations there. Nice to have that built in webserver to fall back on, though, just in case Home Assistant server is down for whatever reason.

It probably wouldn't be too hard to add a display, and controls with buttons, too. I may try to do that with the Eltek Flatpack2 CAN controller someday.

Connection to Smart Shunt is via VE.Direct connector. Uses UART on the ESP, receive-only, can't make changes to Smart Shunt.
 
I was inspired by @sijones2010 and his project,
(y) good to hear, I've been using code derived from his project for nearly 2 years now, controlling my Solis inverters from my DIY battery pack.

I am already able to manually control charge. Would like to eventually automate a retarded charge current when temperature gets too high or low, or SoC over 90%,
Definitely a good idea! As well as the original code to reduce charge in steps above 90%, I also enhanced the code to adjust charge current based on temperature, in accordance with EVE LF280K datasheet. See also my posting here...
 
I've observed that SI subtracts 1V from the BMS voltage limit when off-grid. This would make it difficult to ever reach 100% SoC while off-grid with AC coupling. Wonder if anyone else has already solved this issue?
Not solved it but as I my SI's are solely off grid I just add 1V to the BMS target V. So my JK PB BMS is set to 56.2V and the SI5048 reports target V as 55.2V. If the PV output is maxed out at Bat 55.1V with low house loads then the SI lags in increasing the Frequency and before the Inverters come under control of curtailment the V can overshoot to 55.8V. The JK PB BMS does not get alarmed as 55.8V is still below 56.2V, the cell balancing is activated. In addition I also monitor the Frequency on s Raspberry Pi and turn on a 3kw water heater at 50.6htz via a Wifi shelly relay which drops the batt V pretty quickly. The water heater gets turned off as the frequency drops below 50.4htz. I may add a timer so the water heater stays on for min 10 mins to reduce the on/off cycling.
 
Not solved it but as I my SI's are solely off grid I just add 1V to the BMS target V. So my JK PB BMS is set to 56.2V and the SI5048 reports target V as 55.2V. If the PV output is maxed out at Bat 55.1V with low house loads then the SI lags in increasing the Frequency and before the Inverters come under control of curtailment the V can overshoot to 55.8V. The JK PB BMS does not get alarmed as 55.8V is still below 56.2V, the cell balancing is activated. In addition I also monitor the Frequency on s Raspberry Pi and turn on a 3kw water heater at 50.6htz via a Wifi shelly relay which drops the batt V pretty quickly. The water heater gets turned off as the frequency drops below 50.4htz. I may add a timer so the water heater stays on for min 10 mins to reduce the on/off cycling.
Exactly what I was wondering, thanks! Not really an issue for FLA, but wouldn't want to tempt fate, and end up with an outage because of overvolt BMS disconnect. Compensating the 1V is dead simple, but I'm reluctant to, I figure SMA must have done it for a reason... Maybe I'll add back in 0.5V when I'm not connected to "grid" (which is actually another pair of SIs).

Quick aside: did you know that you can set up your Shelly to react to frequency all by itself, no external control required?
 
So, I managed to get the backfeed power target PID code working. In the attached image, I changed target from 1000W to 2000W about halfway through.

Probably need to spend more time trying to tune the PID values. Also considering feeding the PID loop with the power values from SmartShunt, instead of the granular (nearest 100W) values coming from SI. Since voltage can only be set in 0.1V increments, it will constantly be hunting. But ought to be able to cut down on the oscillating with better PID values.

It occurs to me that there's no reason to restrict this to backfeeding--we ought to be able to target an arbitrary discharge OR charge rate. But maybe better achieved on the charge side with the current limit?

Screenshot 2024-08-15 at 3.22.34 PM.png
 
How difficult would it be to incorporate an energy meter via home assistant to change the charge rate?

Example, i have a pv inverter exporting to grid, and sunny island is on grid. Energy meter detects 5kw is going to grid from pv inverter ,so charge rate gets set to 5kw so that the power flows to the battery

Cloud comes around and grid export is now 2kw. Charge rate gets set to 2kw so the sunny island is only using the pv inverter power and not grid power
 
How difficult would it be to incorporate an energy meter via home assistant to change the charge rate?

Example, i have a pv inverter exporting to grid, and sunny island is on grid. Energy meter detects 5kw is going to grid from pv inverter ,so charge rate gets set to 5kw so that the power flows to the battery

Cloud comes around and grid export is now 2kw. Charge rate gets set to 2kw so the sunny island is only using the pv inverter power and not grid power
Well, in your example, cloud comes around and SI starts pulling from grid 3kW until charge rate gets slowed.

I can think of a few ways of doing this. If you have an energy meter already connected to HA, an automation could be written that would fiddle with the charge current limit on the ESP device.

If you wired loads and grid through SI, that would just happen automatically. But I guess you must have a reason for not doing that?
 
Well, in your example, cloud comes around and SI starts pulling from grid 3kW until charge rate gets slowed.

I can think of a few ways of doing this. If you have an energy meter already connected to HA, an automation could be written that would fiddle with the charge current limit on the ESP device.
Ok that's great to know that it's possible.

If you wired loads and grid through SI, that would just happen automatically. But I guess you must have a reason for not doing that?
I don't have my pv going through my sunny island. I just set the sunny island to connect to grid in the morning and charge at 8a. Most of the time the 8a doesn't actually come from the grid but from the pv pv inverter that's also connected to the grid. On cloudy days when the pv inverter is not producing enough the 8a does come from the grid.

If i could use an automation to change the grid charge limit based on the output of the pv inverter that would be very nice.
 
Sorry, if I'm being a bit slow here, but can you explain the configuration a bit more? I'd assume you can set battery charge rate via the CANBus messages if not Modbus to the inverter and would have assumed that the inverter has a CT clamp to get grid / import export values. Or am I missing something as you seem to have a hybrid off-grid and grid-tied configuration?
 
I have recently solved the Webbox Modbus issue so the SI5048EM I have is now a Modbus TCP on ID3 on the Webbox IP address for my SI.

I can confirm that the read only registers work well and consistently.

Assuming the SI6048US is fixed in the same way which is highly likely as I run SI6048US firmware to get closed loop Lithium settings then there are now Modbus registers that can be written to.

These start at 40009. listing of the writable registers for SI start page 52 (read only registers start at page 47)


I have not looked too closely but this does open automation possibilities, especially in the section where the registers reference 'Plant Control'

eg
40143 Active current for operating mode “plant control” (A)
[FedInCurAtCom] 2 S32 FIX2 RW

But other than this document I can find no reference to 'Plant Control' to see if it is of use. It may be an SBU5000 feature so I need to read up on that, the SI6048US firmware also loads up successfully to the SBU5000.

An SBU5000, sold mainly in Germany and Australia.

0.85039900_1609404535.jpeg
 
Sorry, if I'm being a bit slow here
The early SI's made by SMA are really for off grid only, in the US SMA have never updated the SI's beyond the SI6048. They can connect to the grid but the controls are not your typical modern hybrid so you have to fudge your way around this limitation and it takes some doing.

In Europe SMA did produce later variations which do do hybrid type operations but still clunky and with the need for extra kit.

I have 2 SI5048's which are of the same gen as the SI6048US, instead of hybrid going total off grid is the easy way out plus its not until the SI8.0H-13 that SMA actually applied for G99 so my old SI's can never be connected to the grid in the UK anyway.

Upside is they are built like a tank, handle high loads with ease and keep going on and on.
 
Sorry, if I'm being a bit slow here, but can you explain the configuration a bit more? I'd assume you can set battery charge rate via the CANBus messages if not Modbus to the inverter and would have assumed that the inverter has a CT clamp to get grid / import export values. Or am I missing something as you seem to have a hybrid off-grid and grid-tied configuration?
Is this question for me?

The sunny island cannot see what pv inverters that are connected in parallel are doing.

In contrast, victron with ess and cts can see what parallel pv inverters are exporting and it can divert that power to its batteries.

So with sunny island you set a battery charge rate and it charges from the grid. You try to set it low enough that it only pulls from pv output but that can be hit or miss on cloudy days.


One could also just ac couple but that opens up a whole new can of worms , described here https://diysolarforum.com/threads/forcing-sunny-island-on-grid.73289/
 
If i could use an automation to change the grid charge limit based on the output of the pv inverter that would be very nice.
You could almost certainly get the PV inverter's output imported into HA, probably via modbus. I don't know where your loads are, but you'd only really need a CT/energy meter if you had no other way to measure or calculate surplus PV.

Sorry, if I'm being a bit slow here, but can you explain the configuration a bit more? I'd assume you can set battery charge rate via the CANBus messages if not Modbus to the inverter and would have assumed that the inverter has a CT clamp to get grid / import export values. Or am I missing something as you seem to have a hybrid off-grid and grid-tied configuration?
In my case, I'm "waterfalling" from a pair of SIs into another pair, all strictly off-grid. Without a Webbox (discontinued), there is no modbus interface to these US Sunny Islands. With an RS-485 piggyback ($$) and a RasPi running YASDI, it's possible to access values and set parameters, but it's rather slow and awkward. There's a yasdi2mqtt docker image that makes import of values into HA simple, but offers no control.

Owners of US Sunny Islands that want to change operating parameters need to walk up to the unit and struggle through the two line LCD interface, or else buy RS-485 piggyback plus Webbox or RasPi. But even then (unlike Victron and Schneider), you can't specify a target power to push or pull from the grid.

But now I can! I've got a number entity on the ESP32 device that presents as a slider from -7000 to +7000, and an on/off switch to have it automatically chase the desired power to or from "grid", which it does by manipulating the target (charge) voltage. It's not perfect, but seems to work well enough:

Screenshot 2024-08-17 at 3.15.59 PM.png

If it proves to work reliably, it'd be pretty exciting, as this makes the SI 6048-US-10 much more flexible.

I can imagine the possibility of programming it to respond to frequency fluctuations by sinking extra power when the frequency (or voltage) goes up, and giving power back at times the frequency (or voltage) drops. This could be automated with just the ESP and CAN, as the SI provides voltage and frequency measurements on CAN, but they're not very precise.
 
You could almost certainly get the PV inverter's output imported into HA, probably via modbus. I don't know where your loads are, but you'd only really need a CT/energy meter if you had no other way to measure or calculate surplus PV.
I really wouldn't even need the inverter data. A simple ct(i heard shelly cts have HA compatibility) letting ha know how much is being exported would suffice i think .

Heck one might not even need HA. if the esp32 can read a ct then it could be programmed to change the charge rate based on ct data

Owners of US Sunny Islands that want to change operating parameters need to walk up to the unit and struggle through the two line LCD interface, or else buy RS-485 piggyback plus Webbox or RasPi. But even then (unlike Victron and Schneider), you can't specify a target power to push or pull from the grid.
You can't specify a target power to push to the grid but you can change how much it pulls from the grid using the setting GdCurNom(nominal grid current)

In my case the parameter i would want esp32 to be able to change is InvChrgCurMax(maximum ac charging current)

If there is no pv export, set charging current to zero. If there is 4.8kw of pv export, set charging current to 20A

But now I can! I've got a number entity on the ESP32 device that presents as a slider from -7000 to +7000, and an on/off switch to have it automatically chase the desired power to or from "grid", which it does by manipulating the target (charge) voltage. It's not perfect, but seems to work well enough:

Does it write to flash memory? I read some concerns here about a finite amount of writes to the sunny island memory

Only bad if storage is Flash and system was designed assuming updates would only be done a few hundred times.
Flash wears out around 1000 write cycles, and that even includes SSD used in computers.
If it proves to work reliably, it'd be pretty exciting, as this makes the SI 6048-US-10 much more flexible.

I agree!
 
I really wouldn't even need the inverter data. A simple ct(i heard shelly cts have HA compatibility) letting ha know how much is being exported would suffice i think.

Heck one might not even need HA. if the esp32 can read a ct then it could be programmed to change the charge rate based on ct data
This is exactly what I was going to tell you. Haven't done it myself, but it should be possible, depending on how deep you want to dive.

You can't specify a target power to push to the grid but you can change how much it pulls from the grid using the setting GdCurNom(nominal grid current)

In my case the parameter i would want esp32 to be able to change is InvChrgCurMax(maximum ac charging current)

If there is no pv export, set charging current to zero. If there is 4.8kw of pv export, set charging current to 20A
esp32 won't be able to change any parameters. It would require implementation of YASDI and comms with the RS485, meaning piggyback required. And parameters would be written to flash, which could be a longevity concern.

Does it write to flash memory? I read some concerns here about a finite amount of writes to the sunny island memory
From what I understand it does not. I found a SMA document "Technical Information - Connecting Batteries with external Battery Management System to SUNNY ISLAND 6.0H-11". On page 17, it says SI loses every setting that came via comm interface when switched off, and default values will be used until overwritten by BMS. That seems a clear indication that nonvolatile storage isn't used, and frequent updates/changes aren't a concern.

ps - nice new profile pic!
 
This is exactly what I was going to tell you. Haven't done it myself, but it should be possible, depending on how deep you want to dive.
I was thinking, iotawatt and emporia vue both use cts so I'm sure one can use cts with esp32

esp32 won't be able to change any parameters. It would require implementation of YASDI and comms with the RS485, meaning piggyback required. And parameters would be written to flash, which could be a longevity concern.

Ok i wasn't clear on that but now i think i get it. You're simply emulating a bms and using the "bms" to control the charging and discharging of the sunny island so no need to write any data to flash.

Pretty smart idea..
ps - nice new profile pic!
Thanks! I haven't decided yet if im ecstatic that i have no bill, or bummed that the credit will keep growing but I'll never get paid for it 😀😂
 
The sunny island cannot see what pv inverters that are connected in parallel are doing.

So with sunny island you set a battery charge rate and it charges from the grid. You try to set it low enough that it only pulls from pv output but that can be hit or miss on cloudy days.


One could also just ac couple but that opens up a whole new can of worms , described here https://diysolarforum.com/threads/forcing-sunny-island-on-grid.73289/
I've not had a problem at all with my PV and SI working well together charging the batteries and it's very easy to set up to charge from the grid if required. Their is loads of flexibility in them to do pretty well anything you want.
 
I've not had a problem at all with my PV and SI working well together charging the batteries and it's very easy to set up to charge from the grid if required. Their is loads of flexibility in them to do pretty well anything you want.
Which pv inverters and are you ac coupled or ac retrofit?
 
are you ac coupled or ac retrofit?
What do you mean by that?

2 x SB4000TL20 and one Tripower 12000TL10 on 3 phase grid formed by 3 x SI5048
1 x SB4000TL20 on single phase grid with 1 x SI5048 using 3 phase grid as its grid backup.
 

diy solar

diy solar
Back
Top