springfall2008 / batpred

Home battery prediction and charging automation for Home Assistant, supporting many inverter types
https://springfall2008.github.io/batpred/
123 stars 43 forks source link

Please add support for Huawei inverters. #684

Open JohanAlvedal opened 8 months ago

JohanAlvedal commented 8 months ago

Please add support for Huawei inverters.

I use https://github.com/wlcrs/huawei_solar. This integration exposes the information and functions made available by Huawei Solar inverters directly via one of its Modbus interfaces in Home Assistant.

And not to forget Nordpool https://github.com/custom-components/nordpool/

example of sensors in HA

PV power W = sensor.inverter_input_power Battery SOC = sensor.battery_state_of_capacity Battery charge/discharge in W = sensor.battery_charge_discharge_power Export sensor KWh = sensor.power_meter_exported (total) Import (Grid) kWh = sensor.power_meter_consumption (total)

number.battery_maximum_charging_power number.battery_maximum_discharging_power select.battery_working_mode number.battery_end_of_discharge_soc number.battery_end_of_charge_soc

springfall2008 commented 8 months ago

The previous log showed the charge service failing, I added some more debug in the above link need to try to capture the error again so we can see why.

JohanAlvedal commented 8 months ago

The previous log showed the charge service failing, I added some more debug in the above link need to try to capture the error again so we can see why.

https://justpaste.it/g6buw

JohanAlvedal commented 8 months ago

Hi springfall2008 I think I have found a possible way to go, which is much easier than force charge etc. If you choose Work mode on the inverter, you can "force" it to do things quite easily, i.e. TOU, and if you set it to charge between 00:00-23:59, it always charges when you choose it.

However, if you choose Maximize self consumption, it starts to discharge, but only if it is a value in how many W (number.battery_maximum_discharging_power).

This means that when it is

Idle 1 = [select.battery_working_mode]: maximise_self_consumption, number.battery_maximum_discharging_power, 0W.

Idle 2 = [select.battery_working_mode]: time_of_use_luna2000, number.battery_maximum_discharging_power, 0W.

Charge = [select.battery_working_mode] : time_of_use_luna2000, number.battery_maximum_discharging_power, 2500W

Discharge = [select.battery_working_mode]: maximise_self_consumption, number.battery_maximum_discharging_power, 1500W

Discharge action:

Charge action:

Idle action:

or Idle 2 action:

So if predbat wants to change these dynamically, it works fine for example with Battery charge/discharge curves.

action:

action:

In other words, it can be difficult to make it work well via force charge if you don't always mix in the number.battery_maximum_charging_power / number.battery_maximum_discharging_power values because they control the power values.

For example huawei_solar.stop_forcible_charge is tricky to get that if you don't choose number.battery_maximum_charging_power / number.battery_maximum_discharging_power = 0 then it basically works immediately.

springfall2008 commented 8 months ago

I'm really struggling to understand what you mean here and why the maximum discharging power would be changed for charging.

I think the issue you might have right now is the huawei minimum charge/discharge level is 12% so you need to adjust input_number.predbat_set_reserve_min in Home Assistant to a value of 12.

JohanAlvedal commented 8 months ago

On the contrary, to stop discharging, you must set number.battery_maximum_discharging_power to 0 if you have inverter mode: Maximize self consumption. Then to discharge the battery again, the value must be changed to, for example, 1500W

If you want, I can show you via google meet, so it might be easier to understand. However, my English is not 100%

springfall2008 commented 8 months ago

Surely setting discharging power to 0 will stop the battery from covering the house load or did I miss anything?

Did you try changing your reserve min to 12% as above and re-test?

JohanAlvedal commented 8 months ago

Did you try changing your reserve min to 12% as above and re-test? = yes, I run now and have to wait for the result. but have been away for a couple of days when I ran a different flow then.

No, you didn't miss anything. What is expected to happen when it goes to idle? Should it continue to drain the battery? Because then my question is if there is any difference between discharege and idle?

I am a little unsure if my inverter's Maximize self consumption mode is the same as what you call eco mode. It discharges all the time as long as there is some % in the battery,

springfall2008 commented 8 months ago

Ah okay there is a terminology difference here, so 'idle' in Predbat means ECO Mode in GE inverter which is when the battery covers the house load. This is different from what it calls Discharge which is when you export to the grid at maximum rate.

JohanAlvedal commented 8 months ago

the problem right now is that if it should charge to 33% as an example. Then it charges to 33%, stops charging, then automatically starts discharging for a while and then charges to 33% again, etc., etc. the only way to make the battery stop discharging is to set number.battery_maximum_discharging_power to 0. Unfortunately, huawei_solar.stop_forcible_charge in combination with work mode Maximize self consumption does not help

springfall2008 commented 8 months ago

the problem right now is that if it should charge to 33% as an example. Then it charges to 33%, stops charging, then automatically starts discharging for a while and then charges to 33% again, etc., etc. the only way to make the battery stop discharging is to set number.battery_maximum_discharging_power to 0. Unfortunately, huawei_solar.stop_forcible_charge in combination with work mode Maximize self consumption does not help

That's progress, if its working then as the next step I can add this to the code :)

Did you have to change the apps.yaml any further?

JohanAlvedal commented 8 months ago

Same thing with hold charge, there are two options as far as I can see. Either set (number.battery_maximum_discharging_power) to 0w or change workmode to (select.battery_working_mode) to time_of_use_luna2000 and then go to maximize_self_consumption to discharge the battery.

my apps.yaml

https://justpaste.it/7iexm

JohanAlvedal commented 8 months ago

Same thing with hold charge, there are two options as far as I can see. Either set (number.battery_maximum_discharging_power) to 0w or change workmode to (select.battery_working_mode) to time_of_use_luna2000 and then go to maximize_self_consumption to discharge the battery.

my apps.yaml

https://justpaste.it/7iexm

Or wait it's wrong with hold mode if you set it to always load in TOU (time_of_use_luna2000) then it's best to stay in Work mode: maximize_self_consumption and set number.battery_maximum_discharging_power to 0 W Then it should stay there

springfall2008 commented 8 months ago

I think your apps.yaml has an error, shouldn't charge/discharge rate be set as follows:

charge_rate:

Have you tried turning off 'set_charge_freeze'? The reason it doesn't work is you have the reserve hard wired at 12 rather than set in a way that Predbat can change it. Normally in charge freeze the reserve is set to the current battery level to avoid the discharging, mosty as setting discharge power to 0 with GE inverters doesn't totally prevent discharge.

Can you try with set_charge_freeze off and also correct the above? Then please share a logfile?

JohanAlvedal commented 8 months ago

I think your apps.yaml has an error, shouldn't charge/discharge rate be set as follows:

charge_rate: - number.battery_maximum_charging_power discharge_rate: - number.battery_maximum_discharging_power

Have you tried turning off 'set_charge_freeze'? The reason it doesn't work is you have the reserve hard wired at 12 rather than set in a way that Predbat can change it. Normally in charge freeze the reserve is set to the current battery level to avoid the discharging, mosty as setting discharge power to 0 with GE inverters doesn't totally prevent discharge.

Can you try with set_charge_freeze off and also correct the above? Then please share a logfile?

Aha let me change and restart. set_charge_freeze was off, but Set Discharge Freeze Only is on

JohanAlvedal commented 8 months ago

https://justpaste.it/g2flr

springfall2008 commented 8 months ago

So far looks like, see how it goes...

JohanAlvedal commented 8 months ago

Hello Unfortunately, it is the same as before. After a charging session, it discharges a few percent, and then charges to the target of, for example, 100% over and over again. Charging the battery seems to work fine but if it should be hold or when it gets up to its target that it should "stay" as long as the % is not expected to drop or discharge. So to make this work, number.battery_maximum_discharging_power must be set to 0 on hold charge or when the charge % target has been reached. Now predbat insists on changing number.battery_maximum_discharging_power to 3500 all the time so I have to manually change predbat to monitor mode and then to number.battery_maximum_discharging_power 0

pred1 99 100

springfall2008 commented 8 months ago

Okay thanks for testing, I'll make a change to use discharging power as a next step.

springfall2008 commented 8 months ago

Can you try this version which should disable the discharge during charge periods? https://github.com/springfall2008/batpred/blob/huawei/apps/predbat/predbat.py

JohanAlvedal commented 8 months ago

Can you try this version which should disable the discharge during charge periods? https://github.com/springfall2008/batpred/blob/huawei/apps/predbat/predbat.py

Good, I'll try and get back to you tomorrow

JohanAlvedal commented 8 months ago

Unfortunately, it was the same as before. It insists on setting number.battery_maximum_discharging_power to 3500W. You can see how it has behaved since 05:00 this morning in the attached image and log file. In the end I set it to 0 and put predbat in monitor mode

Skärmavbild 2024-02-20 kl  06 31 28

https://justpaste.it/fv4fb

springfall2008 commented 8 months ago

So I thin what's happening is your inverter turns off charging once the target is reached rather than holding it there.

I've tried to make another update to the same file to turn off discharging while the charge happens and not just when it finishes:

https://github.com/springfall2008/batpred/blob/huawei/apps/predbat/predbat.py

Can you please try this one?

JohanAlvedal commented 8 months ago

So I thin what's happening is your inverter turns off charging once the target is reached rather than holding it there.

I've tried to make another update to the same file to turn off discharging while the charge happens and not just when it finishes:

https://github.com/springfall2008/batpred/blob/huawei/apps/predbat/predbat.py

Can you please try this one?

Exactly like that but with the result that it immediately discharges.

Ok I'll try again with the new one

JohanAlvedal commented 8 months ago

Now it looks like it's working, I'll leave it for a few days and get back to you.

One thing that I react to is all the notifications, I have inverter notify on and had over 50 notifications since I went to bed last night.

springfall2008 commented 8 months ago

That's good news. I'd certainly turn off inverter notification once it's working

JohanAlvedal commented 8 months ago

Just saw this, though it seems to work.

https://justpaste.it/9lhwr

springfall2008 commented 7 months ago

I think I see the issue it tried to discharge to 4% but your min reserve is 14%, maybe a bug?

springfall2008 commented 7 months ago

I think you need to set 'battery_min_soc' to 14 in your apps.yaml

JohanAlvedal commented 7 months ago

The sensor that controls the end of discharge is number.battery_end_of_discharge_soc A bit unsure of what happened but last night it didn't charge the battery as planned but maybe that changed last night?

https://justpaste.it/cwo6n

springfall2008 commented 7 months ago

I think you need to set 'battery_min_soc' to 14 in your apps.yaml

Did you make this change?

JohanAlvedal commented 7 months ago

I had already entered it.

  charge_rate:
    - number.battery_maximum_charging_power
  discharge_rate:
    - number.battery_maximum_discharging_power
  battery_power:
    - sensor.battery_charge_discharge_power
  pv_power:
    - sensor.inverter_input_power
  load_power:
    - sensor.power_meter_active_power
  soc_percent:
    - sensor.battery_state_of_capacity
  soc_max:
   - 10
  charge_limit:
   - number.battery_end_of_charge_soc
  reserve:
   - 12
  battery_min_soc:
   - 14
springfall2008 commented 1 month ago

Is this resolved now?

JohanAlvedal commented 1 month ago

You can close it, there are some quirks though, but I've started other threads about this