batpred icon indicating copy to clipboard operation
batpred copied to clipboard

Add support for Solar Assistant

Open xhemp opened this issue 1 year ago • 9 comments

Would be great to have support for Solar Assistant ( https://solar-assistant.io/ ). It supports many types of inverters and the beta version has a proper power management that works fine with Growatt (my case) inverters as well. I saw another issue opened here for Huaweii ( #684 ) so I will try to play a bit with the template yaml and see where I get, just wanted to get this on the radar (and also confirm if this is something doable or not). Thanks!

xhemp avatar Feb 22 '24 14:02 xhemp

Could make sense, but can share details on how to control it in HA?

springfall2008 avatar Mar 03 '24 20:03 springfall2008

Hey, thanks for getting back to me! So the way I use SA with Home Assistant via MQTT: For example, there's a switch called Work mode priority, there you select Load first, Battery first or Grid first. That is tied to the device_mode topic on MQTT. Attached is a screenshot of all the MQTT topics for Solar Assistant:

Screenshot 2024-03-03 at 22 11 01

If you need anything else or have any other questions, let me know.

xhemp avatar Mar 03 '24 22:03 xhemp

Do these MQTT topics appear as HA entities?

I would need a list of HA entities that hold the basic information required for apps.yaml together with some example automations used to charge and force discharge the battery

springfall2008 avatar Mar 04 '24 08:03 springfall2008

They do, yes and sure thing, here's the entities list: entities_list.txt Please, let me know if you need anything else!

xhemp avatar Mar 04 '24 11:03 xhemp

I guess I don't really know what these do without context.

Can you take this template and try to map these sensors to the line items listed here:

https://github.com/springfall2008/batpred/blob/main/templates/solaredge.yaml

Then if you can create a simple automation in HA to start and stop charging the battery from grid and to discharge the battery to the grid that can go into the configuration also.

springfall2008 avatar Mar 07 '24 08:03 springfall2008

@springfall2008 Sure thing, I am abroad this week but I will give this a go next week, thanks!

xhemp avatar Mar 11 '24 11:03 xhemp

Those are the sensor values I came up with ( I added a few questions to understand what's the need on some of them):

battery_rate_max: - number.growatt_spa_battery_first_stop_charge charge_rate: 3000 discharge_rate: 3000 battery_power: - sensor.growatt_spa_battery_power pv_power: - sensor.growatt_spa_pv_power soc_max: 6

For the automation, here they are:

Services to control charging/discharging

service: select.select_option entity_id: "select.growatt_spa_work_mode_priority" option: "Battery first" charge_stop_service: service: select.select_option entity_id: "select.growatt_spa_work_mode_priority" option: "Load first" discharge_start_service: service: select.select_option entity_id: "select.growatt_spa_work_mode_priority" option: "Grid first"

Let me know if this is what you were looking for and if you need any changes or an explanation.

xhemp avatar Mar 17 '24 22:03 xhemp

charge_rate - should be a setting in Watts e.g. 3000=3kW. You can just hard-wire it as 3000 for now discharge_rate - as charge rate

soc_max is a value in kWh which is the size of the battery e.g. 10 would be a 10 kWh battery

On the services, does Grid first force the battery to discharge at full rate?

springfall2008 avatar Mar 18 '24 08:03 springfall2008

charge_rate - should be a setting in Watts e.g. 3000=3kW. You can just hard-wire it as 3000 for now discharge_rate - as charge rate

soc_max is a value in kWh which is the size of the battery e.g. 10 would be a 10 kWh battery

On the services, does Grid first force the battery to discharge at full rate?

Thanks for clarifying. Grid first forces the battery to discharge at whatever percentage is set on another sensor ( number.growatt_spa_grid_first_discharge_rate ).

Edit: updated the soc values.

xhemp avatar Mar 18 '24 09:03 xhemp

I would love to get this one sorted, any help is appreciated!

xhemp avatar Nov 02 '24 22:11 xhemp

Did you ever get this to work?

springfall2008 avatar Nov 16 '24 15:11 springfall2008

I didn't, no, but I am keen on trying again

xhemp avatar Nov 16 '24 17:11 xhemp

The service API is a bit more comprehensive now e.g. for Solax we configure apps.yaml as

  # Service for start/stop
  charge_start_service:
    service: select.select_option
    entity_id: select.solax_manual_mode_select
    option: "Force Charge"
  charge_stop_service:
    service: select.select_option
    entity_id: select.solax_manual_mode_select
    option: "Stop Charge and Discharge"
  discharge_start_service:
    service: select.select_option
    entity_id: select.solax_manual_mode_select
    option: "Force Discharge"

springfall2008 avatar Nov 16 '24 20:11 springfall2008

Thanks for that, I will have a go on this next week and let you know.

xhemp avatar Nov 17 '24 05:11 xhemp

I tried to change the SX4 template to this:

https://pastebin.com/2Jf07e8F

Got an error for InverterType ( Error: Exception raised Inverter type not defined) so not sure on what I need to set it there. Anything else I need to change, do you think?

xhemp avatar Nov 19 '24 10:11 xhemp

Managed to add SA (Solar Assistant) to the config.py, same as the SX4 and was able to pass the inverter type error. Looks like it's working just confirming if it's doing what it's supposed to do now, will update you later today.

PredBat looks like it's running and doing its thing (I can see the battery charging now before the 16:00 to 19:00 expensive zone). Have some errors in the logs:

For the predbat.status:

2024-11-24 10:10:11.829656: Charge window will be: 2024-11-24 11:00:00+00:00 - 2024-11-24 11:30:00+00:00 - current soc 95 target 82 2024-11-24 10:10:11.830098: Inverter 0 disabled charge window while waiting for schedule (now 11-24 10:10:00 target set_window_minutes 30 charge start time 11-24 11:00:00) 2024-11-24 10:10:11.830332: Adjust idle time, charge 00:00:00-00:00:00 discharge 10:00:00-11:01:00 2024-11-24 10:10:11.830834: Adjust demand (idle) time computed is 11:01:00-23:59:00 2024-11-24 10:10:11.831393: Next export window will be: 2024-11-24 10:00:00+00:00 - 2024-11-24 11:01:00+00:00 at reserve 45 2024-11-24 10:10:11.831500: Exporting now - current SoC 6.17 and target 2.92 2024-11-24 10:10:11.831737: Inverter 0 Adjust force export to True, change times from 10:00:00 - 11:01:00 to 10:00:00 - 11:01:00 2024-11-24 10:10:11.831792: Adjust idle time, charge 00:00:00-00:00:00 discharge 10:00:00-11:01:00 2024-11-24 10:10:11.832090: Adjust demand (idle) time computed is 11:01:00-23:59:00 2024-11-24 10:10:11.832312: Inverter 0 Skipping service charge_stop_service domain charge with data {'device_id': ''} as already called 2024-11-24 10:10:11.832366: Inverter 0 Skipping service discharge_start_service domain discharge with data {'device_id': '', 'target_soc': 45, 'power': 3000} as already called 2024-11-24 10:10:11.832421: Inverter 0 Skipping service charge_stop_service domain charge with data {'device_id': ''} as already called 2024-11-24 10:10:11.832544: Inverter 0 adjust target soc for charge to 45% (2.93kWh/6.5kWh 6.5kWh) based on going from 95% -> 45% total add is -3.24kWh and this battery needs to add -3.24kWh to get to 2.94kWh 2024-11-24 10:10:11.832594: Inverter 0 Current charge limit is 100% and new target is 45% 2024-11-24 10:10:11.832672: Error: Exception raised 'NoneType' object has no attribute 'split' 2024-11-24 10:10:11.834489: Error: Traceback (most recent call last): File "/config/predbat.py", line 11416, in run_time_loop self.update_pred(scheduled=True) File "/config/predbat.py", line 10176, in update_pred status, status_extra = self.execute_plan() File "/config/predbat.py", line 8884, in execute_plan self.adjust_battery_target_multi(inverter, self.export_limits_best[0], isCharging, isExporting) File "/config/predbat.py", line 8530, in adjust_battery_target_multi inverter.adjust_battery_target(new_soc_percent, is_charging, is_exporting) File "/config/inverter.py", line 1220, in adjust_battery_target self.write_and_poll_value("charge_limit", self.base.get_arg("charge_limit", indirect=False, index=self.id), soc) File "/config/inverter.py", line 1282, in write_and_poll_value domain, entity_name = entity_id.split(".") AttributeError: 'NoneType' object has no attribute 'split' 2024-11-24 10:10:11.918143: Info: record_status Error: Exception raised 'NoneType' object has no attribute 'split' 2024-11-24 10:10:11.918495: Error: 'NoneType' object has no attribute 'split'

And warnings:

Warn: Inverter control auto restart trigger: Unable to read inverter time Warn: Unable to read inverter time string 2024-11-19T14:55:00 using formats ['%Y-%m-%dT%H:%M:%S%z', '%Y-%m-%d %H:%M:%S%z', '%Y-%m-%d %H:%M:%S'] Warn: Inverter 0: Using inverter type SA - not all features are available

I am now comparing the inverter type set on config.py with the documentation to see what I can/need to set to true or false.

xhemp avatar Nov 19 '24 14:11 xhemp

Something I also realised is that the holidays days left are not decreasing at midnight (I'm not at home at the moment).

xhemp avatar Nov 23 '24 18:11 xhemp

Looks like the errors I am getting above happen when the inverter has to be set to export, when I check Solar Assistant, it doesn't show it exporting so I am unable to export it, unfortunately.

Edit: Scratch that, I've been trying to put as much info as I can about the inverter on apps.yml, looks like now export is working fine.

Edit 2: No, it isn't working, got an export now showing up and BatPred told the inverter to change to Load first, will wait for @springfall2008 help on this one to see if I can finish configuring Solar Assistant fully with BatPred.

Edit 3: Changed config.py and added a vanilla (every feature set to False) configuration and everything seems to be working well (the errors I added above are gone). I probably can enable some of the features but will wait for springfall's comments. For now, it's working as expected!

xhemp avatar Nov 24 '24 10:11 xhemp

@springfall2008 I would really appreciate if you can add the SA config (with all false at the moment) to the config.py for now.

"SA": {
    "name": "Solar Assistant",
    "has_rest_api": False,
    "has_mqtt_api": False,
    "output_charge_control": "none",
    "charge_control_immediate": False,
    "current_dp": 0,
    "has_charge_enable_time": False,
    "has_discharge_enable_time": False,
    "has_target_soc": False,
    "has_reserve_soc": False,
    "has_timed_pause": False,
    "charge_time_format": "S",
    "charge_time_entity_is_option": False,
    "soc_units": "%",
    "num_load_entities": 1,
    "has_ge_inverter_mode": False,
    "time_button_press": False,
    "clock_time_format": "%Y-%m-%dT%H:%M:%S",
    "write_and_poll_sleep": 5,
    "has_time_window": False,
    "support_charge_freeze": False,
    "support_discharge_freeze": False,
    "has_idle_time": False,
    "can_span_midnight": False,
    "charge_discharge_with_rate": False,
}

xhemp avatar Dec 06 '24 11:12 xhemp