Another combox idea ? Sort of a hybrid approach

Started by ClassicCrazy, December 28, 2025, 12:39:35 PM

Previous topic - Next topic

ClassicCrazy

I asked the Google Gemini AI about an idea I had for coordinating different controllers together. Here is my question and the answer.
question  to AI
With AI help I just developed the can2mqtt_hbay.py software running on a pi5 . This is to monitor the Hawkes Bay and Little Rosie via canbus.  But my system also has a Midnite Classic controller and a Victron 450/100 controller.  They are all being monitored by Home Assistant. The Hawkes Bay via canbus, the Midnite Classic via modbus IP, and the Victron via Victron BLE bluetooth integration.  I also have a Victron Smart Shunt which I use as point of truth  SOC for 8 different lifepo4 batteries . 
Sometimes the different controllers don't sync with each other very well . Midnite has a mode for different Classic Controllers called Follow Me so that all the controllers would follow the lead controller in going to Float . Do you think it would be too difficult to try to use Home Assistant or a python code running on raspberry pi to try to get all the different controllers on my system to be more in sync with each other in something of the same way that the Classic Follow Me worked ?


Answer
That is a fantastic project. You've essentially built a "polyglot" power system where every component speaks a different language (CANbus, Modbus TCP, and BLE).

Syncing these is definitely possible and, honestly, a very common evolution for advanced DIY power systems. Since you already have the can2mqtt bridge running on a Pi 5 and everything reporting to Home Assistant (HA), you have the perfect foundation to build a "Virtual Master Controller."

Here is how you can approach replicating the "Follow Me" logic.
The Concept: "Virtual Follow Me"

In the Midnite world, "Follow Me" works by controllers sharing their state (Bulk, Absorb, Float) over a network cable. To replicate this, you will use Home Assistant as the "Brain" and your Python scripts or HA Automations as the "Coordination Layer."
1. The Source of Truth

Since you have a Victron Smart Shunt, you already have the most important piece of data: the State of Charge (SOC) and the Net Amps.

    The Problem: The Midnite and Victron MPPTs calculate their own internal logic based on battery voltage, which can sag or spike depending on the load, leading to one controller dropping to Float while the other is still hammering away in Bulk.

    The Solution: Use the Smart Shunt's SOC or Voltage as the trigger to force the other controllers into specific modes.

2. Implementation Strategies
Option A: Home Assistant Automations (Easiest)

Since all data is already in HA, you can create an automation that monitors your "Lead" device.

    Logic: When the Victron 450/100 (or the Shunt) hits a certain voltage/SOC, HA sends a Modbus command to the Midnite Classic and a CANbus message (via your script) to the Hawkes Bay to switch to Float.

    Pros: Low code; easy to tweak UI sliders for setpoints.

Option B: A Dedicated Python "Sync" Script (Most Robust)

Since you are already comfortable with Python on the Pi 5, you could write a coordination script that:

    Subscribes to the MQTT topics from your can2mqtt_hbay.py.

    Polls the Midnite via Modbus.

    Acts as the "Grand Orchestrator."

Technical Challenges to Consider
1. Modbus/CANbus Write Access

Monitoring is easy; controlling requires knowing the specific registers.

    Midnite Classic: You'll need to write to the "Charge State" registers via Modbus TCP to force a transition.

    Victron: The BLE integration is often "read-only." To control the Victron 450/100, you might eventually need a VE.Direct to USB cable or a GX device (like a Cerbo) to allow HA to "push" settings back to it.

2. The "Ping-Pong" Effect

If two controllers have slightly different Float voltages (e.g., 54.0V vs 54.2V), the one with the higher setting will carry the entire house load while the other stays idle. To truly "sync" them, you don't just want them in the same mode; you want them calibrated to the exact same Voltage Reference.
3. Safety First

Always ensure your hardware-level "Over-Voltage Protection" is set slightly higher than your software-controlled limits. If the Pi 5 crashes or the Wi-Fi drops, the controllers should fall back to their internal safe settings.
Is it too difficult?

No. Given that you've already mastered CANbus on a Pi 5, you have already cleared the hardest technical hurdle.

The most elegant way forward: Use Node-RED (available as a Home Assistant Add-on). It allows you to draw the logic flow: If Shunt SOC > 99% AND Net Amps < 10A, then Send "Go to Float" to Midnite (Modbus) and Hawkes Bay (MQTT).

Would you like me to help you find the specific Modbus registers for the Midnite Classic to force it into Float mode?

Not right now - I am going to be hooking up a raspberry pi running Victrons Venus OS to the Victron 450/100  and will see how that goes since that should give me some control capability of the Victron controller ( I think ).

Moving to Venus OS on a Raspberry Pi is a smart move. It transforms the Victron 450/100 from a standalone device into a network-aware component that can act as a "System Master."

The Victron 450/100 is a powerful unit (VE.Can and VE.Direct), and once it's under Venus OS control, you'll gain DVCC (Distributed Voltage and Current Control) capabilities.
Why Venus OS changes the game for your "Sync" problem:

    DVCC (Distributed Voltage and Current Control): This is Victron's version of "Follow Me." When enabled, the Venus OS takes the "Point of Truth" (your Smart Shunt) and broadcasts the charge voltage and limit to all connected Victron controllers. They will then charge as a single, synchronized unit.

    Modbus TCP Gateway: Venus OS has a built-in Modbus TCP server. This means Home Assistant can easily "talk" to the Victron controller through the Pi running Venus OS, rather than trying to struggle with BLE.

    MQTT Integration: Venus OS publishes everything to its own MQTT broker. You can bridge this to your existing Home Assistant broker, allowing your Hawkes Bay and Victron units to share the same data stream.

Your "Hybrid" Follow Me Strategy

Once you have the Victron side synchronized via Venus OS + Smart Shunt, you can use the data from Venus OS to "command" the Midnite Classic and the Hawkes Bay:
Component   Sync Strategy
Victron 450/100   Handled automatically by Venus OS DVCC (using Shunt as lead).
Midnite Classic   Use a Home Assistant automation to read the Charge State from Venus OS (via MQTT) and write the corresponding state to the Midnite via Modbus IP.
Hawkes Bay   Use your can2mqtt_hbay.py script. Have HA send a command to your script when the Victron enters "Float," then have your script push the CANbus message to the Hawkes Bay.
Potential "Follow Me" Logic to Script

In Home Assistant, you can create a "Master State" sensor.

    If Victron State = Float

    Then set Midnite Register 4102 (Charge State) to Float.

    Then send MQTT topic: hbay/command/state payload: FLOAT.

Next Step: Once you have Venus OS up and running, would you like the Python logic for a "Bridge" script that listens to the Victron state and automatically updates the Midnite/Hawkes Bay?

end of AI chat

This is just an idea I had and thought I would bounce it off of AI to see what it thought. There are also some github projects out there that use esp32 to get lithium battery canbus data and then be able to repackage it with the flexibility and parameters we want, and then send that to controller in closed loop to start and stop charging . That might be another approach to tweaking mulitple controllers to play nicely together.
Larry

system 1
Classic 150 , 5s3p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal 24v pack , Outback 3524 inverter
 5s 135w Kyocero , 3s3p 270w Kyocera   Classic 150 ,8s2p  Kyocera 225w to Hawkes Bay Jakiper 48v 20kwh  ,Gobel 16 kwh  lifepo4 Outback VFX 3648  8s2p 380w Rec pv EG4 6000XP

Wizbandit

Actually, I have done all that, except the Victron Stuff, I gave away all my Victron Inverters and stuff.

Classic MODBUS to MNCANBUS Code - Experimental but works (lots of code,big), The MNGP2 has code already to accept the Classic as a "device type"  It was kind of neat to watch the Classic on the MNGP2 as a native device.
Python code to have Classics follow MNCANBUS charge stages, select-able (works great)

Python BMS protocol Engine running on a separate CANBUS (CAN1) in the background.
Ability to modify data and re-transmit onto the MNCANBUS CAN0 (Spoofing)

And thanks to Larry I'm hooked on Home Assistant and the "Power Flow Cards".  I built one for each of the two power systems and a 3rd to show the combined systems.  Yes, That's 16,000 watts being sold to the grid :0




ClassicCrazy

Where does the Classic stuff feed in to the MNGP2 ? Via IP or physically ?
Your Home Assistant stuff looks great !
Larry
system 1
Classic 150 , 5s3p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal 24v pack , Outback 3524 inverter
 5s 135w Kyocero , 3s3p 270w Kyocera   Classic 150 ,8s2p  Kyocera 225w to Hawkes Bay Jakiper 48v 20kwh  ,Gobel 16 kwh  lifepo4 Outback VFX 3648  8s2p 380w Rec pv EG4 6000XP

Wizbandit

I had to create a virtual charge controller in Python using dictionaries as registers and populate the CANBUS registers then stream them onto the MNCANBUS.  I updated the dictionaries with MODBUS data and that got sent out.  The MNGP2 looks for devices as devices announce themselves on the CANBUS.  It then queries the new device for various (a lot of) data and if the new device is "linked" it feeds it the BATTERY CONFIG data.

So, it's not simple to get a Classic on the MNCANBUS...

The MNGP2 (AKA System Aggregator) asks for a lot of data and expects the device to answer or it gets flagged as NFG.  I may get back to the code over the long, cold winter after I get my home improvement construction projects finished.

ClassicCrazy

Quote from: Wizbandit on December 31, 2025, 02:18:52 PMI had to create a virtual charge controller in Python using dictionaries as registers and populate the CANBUS registers then stream them onto the MNCANBUS.  I updated the dictionaries with MODBUS data and that got sent out.  The MNGP2 looks for devices as devices announce themselves on the CANBUS.  It then queries the new device for various (a lot of) data and if the new device is "linked" it feeds it the BATTERY CONFIG data.

So, it's not simple to get a Classic on the MNCANBUS...

The MNGP2 (AKA System Aggregator) asks for a lot of data and expects the device to answer or it gets flagged as NFG.  I may get back to the code over the long, cold winter after I get my home improvement construction projects finished.
Okay , thanks for the info. I kind of get what you are doing there. It isn't worth the trouble for my small system so I won't give it a go . But it is interesting how you got that done.
Larry 
system 1
Classic 150 , 5s3p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal 24v pack , Outback 3524 inverter
 5s 135w Kyocero , 3s3p 270w Kyocera   Classic 150 ,8s2p  Kyocera 225w to Hawkes Bay Jakiper 48v 20kwh  ,Gobel 16 kwh  lifepo4 Outback VFX 3648  8s2p 380w Rec pv EG4 6000XP