marstek-venus-rs485-node-red icon indicating copy to clipboard operation
marstek-venus-rs485-node-red copied to clipboard

feature request: self consumption mode using marstek self consumption mode.

Open kiss81 opened this issue 9 months ago • 14 comments

My first node red experience, but I just got this up and running for my 4 v3's! The options to set limits per battery and have battery rotation based on the percentage left in the batteries is so impressive @gitcodebob !

Would love to see one more feature: the option so have the "self-consumption" mode using marstek's CT anti feed mode instead of the modbus control using your PID controller.

The reason for this is to reduce the amount modbus control changes. We are yet not sure if this could potentially damage the battery in the long term. It probably is a a non issue and your PID controller is superior, but having the choice would be really nice. (keeping your battery rotation strategy and limits).

I hope this request is clear and feasible. Let me know if I need to explain it better or if you need help or someone testing things!

Thank you so much!

kiss81 avatar Feb 07 '26 23:02 kiss81

Hi kiss81, thanks a lot.

Switching to the Marstek's own anti-feed algorithm is possible (e.g. by switching to 'Marstek Control' in HBC), but as you may have noticed it instantly rejects a lot of the custom features, limits and settings that where set via modbus. It goes it's own way.

I have not experimented with it extensively, but the possibilities currently look very limited and would diverge a bit from what HBC is trying to do. I foresee other regions of development to get precedence. Thanks for your care for this subject.

Have you been in contact with Marstek suppliers on this subject to find out more about this long term effect you are describing?

gitcodebob avatar Feb 07 '26 23:02 gitcodebob

Hi kiss81, thanks a lot.

Switching to the Marstek's own anti-feed algorithm is possible (e.g. by switching to 'Marstek Control' in HBC), but as you may have noticed it instantly rejects a lot of the custom features, limits and settings that where set via modbus. It goes it's own way.

I have not experimented with it extensively, but the possibilities currently look very limited and would diverge a bit from what HBC is trying to do. I foresee other regions of development to get precedence. Thanks for your care for this subject.

Have you been in contact with Marstek suppliers on this subject to find out more about this long term effect you are describing?

Thank you for the fast reply! It goes it's own way yes, but the funny thing is that anti-feed does respect the charge / discharge limits that are set through modbus. So my guess is that you don't loose that much functionality when switching from full control to anti-feed. I wish my node red knowledge was good enough to try it. :)

I haven't contact Marstek, but I can imagine setting the charge / discharge power so often can damage the internal flash memory of the unit. On the other hand if some are using this for some months now it's probably fine, but time will tell.

kiss81 avatar Feb 08 '26 00:02 kiss81

@gitcodebob If you can give me a little bit of a starting point with a stripped version (complete PID part can be removed?) of the self-consumption.json I can play around with it and try some stuff to see if it's worth (later) implementing it in a nice way. Thank you and have a great weekend!

Edit: or would it be easier to just add a switch to toggle between the modes and leave the PID in place?

Edit 2: someone made a script that should work for 2 batteries that might can be used as example how to implement / what to do: https://github.com/hansvanlin/Marstek-venus-A

kiss81 avatar Feb 08 '26 10:02 kiss81

Trying to understand the current node red flows and I might have an idea where to implement it: If I get it right I think I can just do it in the main "set batteries" loop. In case a battery is in "charge / discharge" mode I just put it in anti-feed instead without really setting the force power.... Only thing I don't know if the PID calculations in the self consumption flow gets upset by doing so. I will give it a try and see what will happen. :)

kiss81 avatar Feb 09 '26 15:02 kiss81

It took me some time, but I do think I kind of got it working. It is just a quick and dirty solution that is in a stage that I can test it now. The modification in Set Batteries is quite clean. I added this:

const CTMODE = {
    MANUAL: "manual",
    ANTIFEED: "anti-feed",
    AI: "ai"
}

let ctMode = CTMODE.MANUAL;

if(solution.mode == CMODE.CHARGE || solution.mode == CMODE.DISCHARGE)
{
    ctMode = CTMODE.ANTIFEED;
}
else
{
    ctMode = CTMODE.MANUAL;
}

// Set | Mode
const serviceCallCtMode = {
    "action": "select.select_option",
    "target": {
        "entity_id": [`select.${target}_user_work_mode`]
    },
    "data": {
        "option": String(ctMode) // forced charge mode (stop, charge, discharge)
    }
};

Some dirty stuff I had to do now to make it work:

  1. disconnect the set rs485 mode (in the home battery master switch)
  2. remove the battery.rs485 !== "enable") check in load distribution of the self consumption mode.
  3. remove the "set power" connection from the "set batteries"

What Needs to be done to make it better:

  1. It still sets the forcible charge / discharge rs485 value for now as this is used as a variable for each battery... This needs to be and intermediate variable to prevent this.
  2. The DOD in the marstek app can be different from what's set in the dashboard battery limits. I didn't check if the DOD can be set over rs485, but that would be a nice solution.
  3. a more proper solution would be to make it a complete new mode: "Full control (marstek CT)" or something.

But first I will test if this modification would work. I will report here when I know more. :)

Edit: a small improvement for the current script: add the "on change" function also between the "set batteries" and "Set mode (charge/discharge/stop)".

kiss81 avatar Feb 09 '26 21:02 kiss81

Hi kiss81,

Have a look at point 5 in https://docs.homebatterycontrol.com/01-getting-started for Marstek Mode.

It seems you are switching the batteries to exactly that mode. However, instead of using the app to set the Marsteks to Manual, anti-feed, AI - you have found a way to set it through node-RED.

Have a look if this is what you are seeking. If yes, it would not be much work to add a selector for the 3 modes into HBC.

It will also save you rewriting the Full Control flows.

Have a look and let me know what you discover.

gitcodebob avatar Feb 10 '26 08:02 gitcodebob

@gitcodebob It sort of works, but there is one issue to fix: When turning on self consumption one of the batteries starts discharging. Everything looks normal. But of course the grid power starts to go to zero, as is the PID value in the graph. (funny it still kind of works while doing nothing :)) The power per battery and the battery state looks normal (negative power value and "discharging" state)

But at some point the PID and GRID lines cross each other because of a little overshoot. Then battery 1 stops for a short while and the second battery starts to charge and things get messy of course. :)

Image

Not sure what's causing this behavior. Any clue? I also tried keep setting the forcible charge / discharge power (even though it's not going to be used), but that doesn't help. Thank you!

kiss81 avatar Feb 10 '26 08:02 kiss81

Hi kiss81,

Have a look at point 5 in https://docs.homebatterycontrol.com/01-getting-started for Marstek Mode.

It seems you are switching the batteries to exactly that mode. However, instead of using the app to set the Marsteks to Manual, anti-feed, AI - you have found a way to set it through node-RED.

Have a look if this is what you are seeking. If yes, it would not be much work to add a selector for the 3 modes into HBC.

It will also save you rewriting the Full Control flows.

Have a look and let me know what you discover.

Thank you for your reply. I want a kind of hybrid between the full control self-consumption mode and marstek mode. :)

Instead of full marstek mode, now your node red self-control decides when to charge / discharge a battery. By doing so it adds some nice features you already made:

  1. Max charge / discharge power setting per battery
  2. charging cutoff capacity
  3. more efficient charge / discharge. (instead of load balancing)

The issue I had I got fixed now it seems by bypassing the PID and set it to B_power instead now. It seems to run really nice now (considering my 10sec P1 updates... :( )

//msg.payload = Number(PID_output); // changed msg.payload = Number(B_power);

Discharging seems to work now. The PID settings make no sense now, but output smoothing can still be used. For discharging this seems to work. Let's hope for some sun soon so I can test charging.

Will post my progress.

It was running really nice. Maybe too much output smoothing, but I don't need it to react on spikes till I get a new meter with 1 second p1 data. Image

kiss81 avatar Feb 10 '26 09:02 kiss81

Image

Discharge works! Here it's switching to battery 3 discharging as battery 1 was getting below it's cutoff percentage. Don't mind the crazy grid power: I now filter my p1 data a lot as I still have a 10 second p1 update meter. (will be replaced soon). Changed one more thing to make sure it can charge / discharge with multiple batteries:

//msg.payload = Number(PID_output); // changed
msg.payload = Number(PID_output + B_power); 

Not sure if this is going to work well for the "load distribution" code, but let's see. If this works I will rewrite all the modifications in a new "hybrid self consumption mode" as that's the cleanest way to implement this. The PID calculation make no sense now.

kiss81 avatar Feb 10 '26 09:02 kiss81

Switching to two batteries here because of a peak in power usage. The graph shows it's "charging" as soon as the grid power goes below zero. In reality it's actually still discharging... My system is really slow now because of the 10 seconds p1 updates but it works ok. Only when going back to one battery discharge it stops for a second...

Image

Hopefully can fix that faulty charge state when implementing a proper hybrid mode.

kiss81 avatar Feb 10 '26 10:02 kiss81

I got it working quite well now. This is really a "hacked" version. I am checking on tweakers if people are interested to test it. If so I will try to make a proper fork / version with a separate mode & flow so you can integrate it into your repository. Important: only "full control + self consumption" works now. You also need to make sure your batteries get CT data (check it in the marstek app). Only the all in flow need to be imported. Home assistant dashboard needs no changes except for now some PID specific settings (see README)

https://github.com/kiss81/marstek-venus-rs485-node-red

Update: Changed the use of the rs485 stop/charge/discharge status. It now uses a stub value so the only rs485 message during self-consumption is the toggle between manual and anti-feed per battery.

kiss81 avatar Feb 11 '26 20:02 kiss81

It works really nice now! I see one improvement: when the weather is half cloudy and the situation switches between charging / discharging, it would be best to stay with the same battery... It seems it now just picks the first battery, but not the one that's last charged. (the one I want to select) @gitcodebob I think I should implement that in the "load distribution"?

Image

kiss81 avatar Feb 12 '26 12:02 kiss81

Found the advanced setting for it in the flow:

flow.set("has_reverse_priority_discharge", false);

All good now!

kiss81 avatar Feb 12 '26 15:02 kiss81

Hi kiss, sorry for the late response. Thanks for sharing your solution.

gitcodebob avatar Mar 02 '26 21:03 gitcodebob