Bidirectional charger with PV Hybrid inverter and pyPLC
Re: Bidirectional charger with PV Hybrid inverter and pyPLC
Hi there,
I'm quite new in the forum and this project is exactly what I'm searching for.
I'm wondering, if it would be possible telling the Inverter via battery can bus interface to set the required voltage.
I'm aiming to realize something similar with a Fronius Gen24 Inverter emulating a byd - battery. (what dala did)
Cheers
Wolfgang
I'm quite new in the forum and this project is exactly what I'm searching for.
I'm wondering, if it would be possible telling the Inverter via battery can bus interface to set the required voltage.
I'm aiming to realize something similar with a Fronius Gen24 Inverter emulating a byd - battery. (what dala did)
Cheers
Wolfgang
- johu
- Site Admin
- Posts: 6596
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 335 times
- Been thanked: 1472 times
- Contact:
Re: Bidirectional charger with PV Hybrid inverter and pyPLC
So far I haven't. The inverter stays in standby mode if there is no sufficient voltage on the battery input (or PV I suppose)
I'm trying to pull some more data from the inverter.
I found modbus register 5147 (5146 0-based) contains bus voltage. While the inverter is not running and assuming there are no PV panels attached then bus voltage is equal to the battery input voltage. When running it looks like the boost converter becomes active and voltage rises to 600V
On the CAN bus I also found some stuff that is not yet in BYD-CAN.cpp
0x091:
(byte[2] << 8 + byte[3])/10 is battery current
(byte[4] << 8 + byte[5])/10 is inverter temperature
Also battery power is reported correctly. I sent a dummy value of 360V but the power (register 13022) is actually based on the physical voltage. So that is one way to obtain present voltage, just divide by current.
I'm trying to pull some more data from the inverter.
I found modbus register 5147 (5146 0-based) contains bus voltage. While the inverter is not running and assuming there are no PV panels attached then bus voltage is equal to the battery input voltage. When running it looks like the boost converter becomes active and voltage rises to 600V
On the CAN bus I also found some stuff that is not yet in BYD-CAN.cpp
0x091:
(byte[2] << 8 + byte[3])/10 is battery current
(byte[4] << 8 + byte[5])/10 is inverter temperature
Also battery power is reported correctly. I sent a dummy value of 360V but the power (register 13022) is actually based on the physical voltage. So that is one way to obtain present voltage, just divide by current.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
- johu
- Site Admin
- Posts: 6596
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 335 times
- Been thanked: 1472 times
- Contact:
Re: Bidirectional charger with PV Hybrid inverter and pyPLC
Na, the high value resistors will do the trick. Couple of meg-ohms leakage won't trip anything. Back at SMA all voltage sensing was non-isolated with chains of high value resistors.
I have ordered one of those cheap 350-1200V transformer boards, will try it first before developing something.
And finally I have committed some code: https://github.com/jsphuebner/esp-egycounter
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
- johu
- Site Admin
- Posts: 6596
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 335 times
- Been thanked: 1472 times
- Contact:
Re: Bidirectional charger with PV Hybrid inverter and pyPLC
Actually nervermind the voltage sensing. The inverters bus_voltage suffices for our purposes.
I also think the inverter begins its lengthy startup sequence when it sees some voltage. I hope it doesn't consume current.
I also think the inverter begins its lengthy startup sequence when it sees some voltage. I hope it doesn't consume current.
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
- johu
- Site Admin
- Posts: 6596
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 335 times
- Been thanked: 1472 times
- Contact:
Re: Bidirectional charger with PV Hybrid inverter and pyPLC
Added a parts list and started a very brief cook book here: https://openinverter.org/wiki/Bidirecti ... parts_list
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
- johu
- Site Admin
- Posts: 6596
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 335 times
- Been thanked: 1472 times
- Contact:
Re: Bidirectional charger with PV Hybrid inverter and pyPLC
I ran some tests with the little HV supply. I was hoping it would deliver the threshold voltage to start up the inverter with 0 power. But it already takes minutes to charge up the very small input capacity. The inverter does indeed change into Startup mode, at least that's a bonus. But it then seems to realize that the input voltage isn't stable and returns to Standby mode.
Not quite sure where to go from there. Since it takes very long to precharge the inverter there is no use in turning on the HV supply on the point. It would need to be always on and keep the inverter precharged and ready to run. Have to check how long it takes from setting the parameter to it actually transferring power.
This could also mean I'd need a relay to direct the precharge voltage away from the CCS connector. I think OEM cars will be angry if they see voltage outside of CableCheck, PreCharge or CurrentDemand
EDIT: wait... the capacity inside the inverter is behind a diode. So as soon as the HV supply is off, there is no more voltage on the CCS connector. So then we don't need a relay.
EDIT2: the new plan!
Not quite sure where to go from there. Since it takes very long to precharge the inverter there is no use in turning on the HV supply on the point. It would need to be always on and keep the inverter precharged and ready to run. Have to check how long it takes from setting the parameter to it actually transferring power.
This could also mean I'd need a relay to direct the precharge voltage away from the CCS connector. I think OEM cars will be angry if they see voltage outside of CableCheck, PreCharge or CurrentDemand
EDIT: wait... the capacity inside the inverter is behind a diode. So as soon as the HV supply is off, there is no more voltage on the CCS connector. So then we don't need a relay.
EDIT2: the new plan!
- System is off (i.e. hybrid inverter, 5% PWM, PLC and HV supply shut off)
- CCS is plugged in denoted by 5V on PP pin
- Power up inverter and HV supply (set to 500V)
- After some minutes inverter is precharged and ready to run
- Start 5% PWM and PLC, shut down HV supply
- Inverter should remain precharged as its DC bus discharges rather slowly. DC bus voltage does not exit the inverter as it's behind a diode
- In CableCheck fire up HV supply again
- In PreCharge apply cars battery voltage by slowly pulsing the HV supply (maybe attach a 1u cap to its output)
- In CurrentDemand bring up inverter and shut down HV supply
- When we reach a SoC limit or press some button on the EVSE side power down, then exit the CCS session when current is gone
- If the car exits the charge session try to shut down the inverter quickly
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
- johu
- Site Admin
- Posts: 6596
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 335 times
- Been thanked: 1472 times
- Contact:
Re: Bidirectional charger with PV Hybrid inverter and pyPLC
More thinking out loud 
Measured some times (bus charged to 370V, well above threshold of 160V):
0:00 Send start command
2:15 Standby to Startup
2:25 Click
2:45 Start Boost
2:50 Error
Then the HV supply, cranked up to the max setting: It takes 6 minutes to reach 370V and doesn't go any higher. As expected voltage drops very quickly when turning it off and steps right back up to bus voltage when re-enabled.
So now we have to time the CCS state machine to connect the battery at around 2:30 minutes. The big question is, how will cars react if they see voltage before CableCheck? I think this should be avoided, making it even more challenging.
So we precharge the inverter to 370V and as soon as we enter state CableCheck we need to turn off the HV supply
Then:
For cars that don't time out we can proceed to CurrentDemand as quickly as possible and the car will just sit there until the inverter has started up. This makes stuff much simpler:

Measured some times (bus charged to 370V, well above threshold of 160V):
0:00 Send start command
2:15 Standby to Startup
2:25 Click
2:45 Start Boost
2:50 Error
Then the HV supply, cranked up to the max setting: It takes 6 minutes to reach 370V and doesn't go any higher. As expected voltage drops very quickly when turning it off and steps right back up to bus voltage when re-enabled.
So now we have to time the CCS state machine to connect the battery at around 2:30 minutes. The big question is, how will cars react if they see voltage before CableCheck? I think this should be avoided, making it even more challenging.
So we precharge the inverter to 370V and as soon as we enter state CableCheck we need to turn off the HV supply
Then:
- Enable inverter
- We hope to reach ContractAuthentication after 0:30 seconds - voltage has dropped to 330V
- ContractAuthentication enable inverter - stay in ContractAuthentication until enabling the inverter is 1:00 minute ago
- We hope to reach CableCheck after 00:10 - voltage has dropped to 300V (1:10 minutes ago since we turned off HV supply)
- Enable HV supply, stay in CableCheck for 1:00, voltage will rise to 330V
- Change to Precharge, now its up to the car to proceed to the next state.
- Enabling the inverter is now 2:00 + precharge time ago. We can spend at most 0:40 seconds in Precharge, because then the boost converter is started and the contactors must be closed by then. So max 350V it possible
- Spent the remaining part of the 0:40 seconds in PowerDelivery
- Once we've reached CurrentDemand the HV supply can be turned off
For cars that don't time out we can proceed to CurrentDemand as quickly as possible and the car will just sit there until the inverter has started up. This makes stuff much simpler:
- Assume Bus precharged to 370V
- We see PP, turn off HV supply and enable inverter
- Proceed to CableCheck as quickly as possible, say 0:30 seconds. Voltage will have sagged to 330V
- Enable supply, finish CableCheck let the precharging happen, say 0:30 seconds for 350V
- After about 2 minutes the inverter will deliver or draw current
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
- johu
- Site Admin
- Posts: 6596
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 335 times
- Been thanked: 1472 times
- Contact:
Re: Bidirectional charger with PV Hybrid inverter and pyPLC
Tested the above with Touran (well it had to work as it doesn't care about port voltage). What was more interesting was the timing.
Started with 370V on the DC bus. From plugging in to Current demand took 25s and bus voltage had sagged to 348V (Battery voltage 366V). CableCheck and Precharge went through so quickly that the voltage change didn't even show.
Currently electricity is expensive so I'm sucking energy from the car: Not super precise but should be good enough. Target values are maybe written every 5s, not quite sure how modbus4mqtt works in that regard
Started with 370V on the DC bus. From plugging in to Current demand took 25s and bus voltage had sagged to 348V (Battery voltage 366V). CableCheck and Precharge went through so quickly that the voltage change didn't even show.
Currently electricity is expensive so I'm sucking energy from the car: Not super precise but should be good enough. Target values are maybe written every 5s, not quite sure how modbus4mqtt works in that regard
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
Re: Bidirectional charger with PV Hybrid inverter and pyPLC
Hi!
This is some very interesting work you've been performing here. I own a 2020 e208 (Peugeot) and I am quite curious about how well this V2x approach could be done on this model. Basically, if the car is not happy with a "negative DC charging" session then your ingenious solution is not applicable.
Do you happen to know about the behavior of this model or similar? I tried to find the forum Thread with the compatible cars but the wiki link sends to a github page.
I will follow your work and, if I can, contribute myself to the forum (already sniffed some CAN traffic from the car in various states but I have little spare time). The e208 is the only car we own at the moment so bricking the car or poping a HV fuse is not something I would like to deal with. Could be an excuse to get a 2nd car tho!
Cheers from a new member.
This is some very interesting work you've been performing here. I own a 2020 e208 (Peugeot) and I am quite curious about how well this V2x approach could be done on this model. Basically, if the car is not happy with a "negative DC charging" session then your ingenious solution is not applicable.
Do you happen to know about the behavior of this model or similar? I tried to find the forum Thread with the compatible cars but the wiki link sends to a github page.
I will follow your work and, if I can, contribute myself to the forum (already sniffed some CAN traffic from the car in various states but I have little spare time). The e208 is the only car we own at the moment so bricking the car or poping a HV fuse is not something I would like to deal with. Could be an excuse to get a 2nd car tho!
Cheers from a new member.
- johu
- Site Admin
- Posts: 6596
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 335 times
- Been thanked: 1472 times
- Contact:
Re: Bidirectional charger with PV Hybrid inverter and pyPLC
I don't think anyone has tested Stellantis yet, the list you're looking for is here: https://openinverter.org/wiki/Bidirecti ... tible_cars
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
-
- Posts: 26
- Joined: Sat Oct 26, 2019 1:05 pm
- Location: Kansas, USA
- Has thanked: 2 times
- Been thanked: 3 times
- Contact:
Re: Bidirectional charger with PV Hybrid inverter and pyPLC
I want to use my Gen24 10kW, Nissan leaf battery, and Ford Lightning Pro Station with DC/AC Combo plug to allow me to charge discharge as a second power source. This will allow me to install way more solar than I'm allowed to install currently and push my bill down to the minimum.
-
- Posts: 3
- Joined: Mon Apr 17, 2023 8:01 am
Re: Bidirectional charger with PV Hybrid inverter and pyPLC
Good morning
did somebody test the V2G setup with an Renaul Zoe CCS - version?
Thx in advance for your informations.
BR
Michael
did somebody test the V2G setup with an Renaul Zoe CCS - version?
Thx in advance for your informations.
BR
Michael
Re: Bidirectional charger with PV Hybrid inverter and pyPLC
(Sorry for posting charger related stuff in the other thread: viewtopic.php?p=79001#p79001 )
For completness, also mentioning it here: To apply a HV voltage to the DC lines, I use this modded step-up converter: https://github.com/dalathegreat/Battery ... age-source In pyPLC I then just try a few PWM frequencies, until the car is happy: https://github.com/lewurm/pyPLC/blob/cd ... #L303-L339
However that doesn't work well if the inverter is on the same line, as the capacitor in the inverter would take aaaaages (I tried, and stopped after 30min). For my inverter, Kostal Plenticore Plus G1, that wouldn't work anyway: The protocol essentially requires to apply HV voltage to the battery input at a given time when the inverter asks for it. So matching that timing with the PreCharge of the car is kind of impossible.
Instead I'm using three contactors (one with a precharge resistor, although I think that one wouldn't be strictly necessary in my case). I only start communication with the inverter once the car is in CurrentDemand and thus only once in this state the inverter can request closing the contactors.
I'm using this: https://www.te.com/de/product-2071584-4.html
With this setup the car (Tesla Model 3) is in CurrentDemand within less than 10s after plugging in. Until the inverter then finally (dis)charges, it can take up to two minutes. Not great, not terrible
No physical interaction with the inverter is needed in my setup, which was particularly important because the inverter is located in the basement.
I should mention that someone wrote a tool to interact with the web API of the inverter, and that allows me to toggle battery support of the inverter programmatically, which makes it overall more predictable: https://github.com/lewurm/pyPLC/blob/cd ... 1105-L1117
For completness, also mentioning it here: To apply a HV voltage to the DC lines, I use this modded step-up converter: https://github.com/dalathegreat/Battery ... age-source In pyPLC I then just try a few PWM frequencies, until the car is happy: https://github.com/lewurm/pyPLC/blob/cd ... #L303-L339
However that doesn't work well if the inverter is on the same line, as the capacitor in the inverter would take aaaaages (I tried, and stopped after 30min). For my inverter, Kostal Plenticore Plus G1, that wouldn't work anyway: The protocol essentially requires to apply HV voltage to the battery input at a given time when the inverter asks for it. So matching that timing with the PreCharge of the car is kind of impossible.
Instead I'm using three contactors (one with a precharge resistor, although I think that one wouldn't be strictly necessary in my case). I only start communication with the inverter once the car is in CurrentDemand and thus only once in this state the inverter can request closing the contactors.
I'm using this: https://www.te.com/de/product-2071584-4.html
With this setup the car (Tesla Model 3) is in CurrentDemand within less than 10s after plugging in. Until the inverter then finally (dis)charges, it can take up to two minutes. Not great, not terrible

I should mention that someone wrote a tool to interact with the web API of the inverter, and that allows me to toggle battery support of the inverter programmatically, which makes it overall more predictable: https://github.com/lewurm/pyPLC/blob/cd ... 1105-L1117
For what it's worth, that isn't the case on my inverter (Kostal Plenticore Plus G1), I can see the DC voltage slowly dropping on the battery input.
- johu
- Site Admin
- Posts: 6596
- Joined: Thu Nov 08, 2018 10:52 pm
- Location: Kassel/Germany
- Has thanked: 335 times
- Been thanked: 1472 times
- Contact:
Re: Bidirectional charger with PV Hybrid inverter and pyPLC
Small update on this. I have tweaked the scripts to automate things more. Now as soon as CCS is plugged in and the inverter ready the control script changes over to using the cars battery instead of the small stationary one. I installed an IP67 switch with LED next to the car to stop the CCS session. The LED blinks when the system is ready and is solid once pyPLC is in state CurrentDemand.
Here is a pretty nice day that has everything
- Charging the car from solar PV (yellow)
- Running dishwasher and laundry machine from car (and PV)
- Changing over to the stationary battery (blue) as the car is disconnected
- Supplying smaller loads in the evening
You can see there is very little draw from the grid that day (red). PV supplied enough energy for cooking, dish washer, 3 laundries and even added 2% (1 kWh) to the car.
PV power isn't measured as it comes from 4 micro inverters.
I've also added more controls to the web page: So now I can program max SoC, maximum price for EV/stationary charging from grid and minimum price for discharging either of the batteries (I'm on a dynamic spot market plan). So already some degree of automation.
Would like to automatically determine the thresholds with forecast data. There's a project that apparently does this but I haven't understood how to use it
https://github.com/Akkudoktor-EOS/EOS
Here is a pretty nice day that has everything
- Charging the car from solar PV (yellow)
- Running dishwasher and laundry machine from car (and PV)
- Changing over to the stationary battery (blue) as the car is disconnected
- Supplying smaller loads in the evening
You can see there is very little draw from the grid that day (red). PV supplied enough energy for cooking, dish washer, 3 laundries and even added 2% (1 kWh) to the car.
PV power isn't measured as it comes from 4 micro inverters.
I've also added more controls to the web page: So now I can program max SoC, maximum price for EV/stationary charging from grid and minimum price for discharging either of the batteries (I'm on a dynamic spot market plan). So already some degree of automation.
Would like to automatically determine the thresholds with forecast data. There's a project that apparently does this but I haven't understood how to use it
https://github.com/Akkudoktor-EOS/EOS
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9