springfall2008 / batpred

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

Please add support for Huawei inverters. #684

Open JohanAlvedal opened 6 months ago

JohanAlvedal commented 6 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 5 months ago

Can you attempt to take a sample configuration from 'templates' and try it with your sensors? I suspect you will need my help to control charging and discharging, its not obvious to me how these are triggered

JohanAlvedal commented 5 months ago

Taken from the github link above: The integration offers multiple services that you can call to dynamically change the behavior of the battery:

forcible_charge: Forcible Charge forcible_charge_soc: Forcible Charge to a SoC level forcible_discharge: Forcible Discharge forcible_discharge_soc: Forcible Discharge to a SoC level stop_forcible_charge: Stop the forcible charge or discharge Forcible Charge

This allows you to forcibly charge your battery for a given duration or to a given SoC level of your battery. While a forcible charge is active, it will direct all power received from the solar panels to your battery instead of covering your home electricity usage.

If the "Charge from grid" toggle is set, it will also draw power from the grid until the given charge power level is reached.

Forcible Discharge

This allows you to forcibly discharge your battery for a given duration or to a given SoC level of your battery. This forces the inverter to inject more power to the AC-side than your home electricity usage, which will consequently be pushed onto the grid.

Stop Forcible charge or discharge

Calling this service will cancel any running forcible charge of forcible discharge command.

I have a reasonably functioning config. there will be no direct errors in the log as far as I can see. then of course it could be the wrong sensors I have, etc.

https://pastebin.pl/view/a70a067e

springfall2008 commented 5 months ago

I've made some changes on a branch:

  1. Updated template - https://github.com/springfall2008/batpred/blob/huawei/templates/huawei.yaml

This has a new inverter type select HU and the services for charge/discharge defined

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

Added code for the new inverter type and using the services.

Please give this a try, however for it to work you need to fix your load sensor otherwise its not going to do anything useful

JohanAlvedal commented 5 months ago

Thank you very much, I will double check and get back to you.

JohanAlvedal commented 5 months ago

`2024-02-05 21:50:03.612180 INFO pred_bat: Inverter 0 Stop charge via Service 2024-02-05 21:50:03.616484 INFO pred_bat: Inverter 0 Stop discharge via Service 2024-02-05 21:50:03.627270 WARNING HASS: Error calling Home Assistant service default/huawei_solar/stop_forcible_charge 2024-02-05 21:50:03.627592 WARNING HASS: Code: 500, error: 500 Internal Server Error

Server got itself in trouble 2024-02-05 21:50:03.637760 WARNING HASS: Error calling Home Assistant service default/huawei_solar/stop_forcible_charge 2024-02-05 21:50:03.638070 WARNING HASS: Code: 500, error: 500 Internal Server Error

Server got itself in trouble 2024-02-05 21:50:03.647732 INFO pred_bat: Will not recompute the plan, it is 5.0 minutes old and max age is 10 minutes 2024-02-05 21:50:03.648596 INFO pred_bat: IBoost model today updated to 0.364 2024-02-05 21:50:03.649539 INFO pred_bat: Completed run status Idle`

springfall2008 commented 5 months ago

I must have the service name wrong, you can change it in apps.yaml if you can figure out the correct name

springfall2008 commented 5 months ago

Okay I think I might know the issue, the service needs a device_id to be set.

Can you:

  1. Update predbat.py from the latest on the branch (https://github.com/springfall2008/batpred/blob/main/apps/predbat/predbat.py)
  2. add 'device_id: xxxxx' to your apps.yaml where the xxxxx is the device_id that Home Assistant reports. The best way to find it is to go into developer tools, services and try to trigger the stop charge service, then once it works to go to YAML mode and copy the device_id from there. Also please snapshot what you see there in case my attempt still doesn't work.
JohanAlvedal commented 5 months ago

Did you remove "HU" from the latest predbat.py ?

I added it and then the errors in the log disappeared, kinda.

2024-02-06 10:49:00.459610 WARNING pred_bat: pred_bat: Entity sensor.predbat_HU_scheduled_charge_enable not found in namespace default 2024-02-06 10:49:00.459997 INFO AppDaemon: pred_bat: Entity sensor.predbat_HU_scheduled_charge_enable created in namespace: default 2024-02-06 10:49:00.466792 WARNING pred_bat: pred_bat: Entity sensor.predbat_HU_scheduled_discharge_enable not found in namespace default 2024-02-06 10:49:00.467225 INFO AppDaemon: pred_bat: Entity sensor.predbat_HU_scheduled_discharge_enable created in namespace: default 2024-02-06 10:49:00.473172 WARNING pred_bat: pred_bat: Entity sensor.predbat_HU_reserve not found in namespace default 2024-02-06 10:49:00.473689 INFO AppDaemon: pred_bat: Entity sensor.predbat_HU_reserve created in namespace: default 2024-02-06 10:49:00.479548 WARNING pred_bat: pred_bat: Entity sensor.predbat_HU_charge_limit not found in namespace default 2024-02-06 10:49:00.480066 INFO AppDaemon: pred_bat: Entity sensor.predbat_HU_charge_limit created in namespace: default 2024-02-06 10:49:00.485759 WARNING pred_bat: pred_bat: Entity sensor.predbat_HU_charge_rate not found in namespace default 2024-02-06 10:49:00.486206 INFO AppDaemon: pred_bat: Entity sensor.predbat_HU_charge_rate created in namespace: default 2024-02-06 10:49:00.491926 WARNING pred_bat: pred_bat: Entity sensor.predbat_HU_discharge_rate not found in namespace default 2024-02-06 10:49:00.492366 INFO AppDaemon: pred_bat: Entity sensor.predbat_HU_discharge_rate created in namespace: default 2024-02-06 10:49:00.498661 WARNING pred_bat: pred_bat: Entity sensor.predbat_HU_inverter_mode not found in namespace default 2024-02-06 10:49:00.499134 INFO AppDaemon: pred_bat: Entity sensor.predbat_HU_inverter_mode created in namespace: default 2024-02-06 10:49:00.504829 WARNING pred_bat: pred_bat: Entity sensor.predbat_HU_charge_start_time not found in namespace default 2024-02-06 10:49:00.505279 INFO AppDaemon: pred_bat: Entity sensor.predbat_HU_charge_start_time created in namespace: default 2024-02-06 10:49:00.511097 WARNING pred_bat: pred_bat: Entity sensor.predbat_HU_charge_end_time not found in namespace default 2024-02-06 10:49:00.511613 INFO AppDaemon: pred_bat: Entity sensor.predbat_HU_charge_end_time created in namespace: default 2024-02-06 10:49:00.517356 WARNING pred_bat: pred_bat: Entity sensor.predbat_HU_discharge_start_time not found in namespace default 2024-02-06 10:49:00.517861 INFO AppDaemon: pred_bat: Entity sensor.predbat_HU_discharge_start_time created in namespace: default 2024-02-06 10:49:00.523877 WARNING pred_bat: pred_bat: Entity sensor.predbat_HU_discharge_end_time not found in namespace default 2024-02-06 10:49:00.524444 INFO AppDaemon: pred_bat: Entity sensor.predbat_HU_discharge_end_time created in namespace: default

springfall2008 commented 5 months ago

Sorry I gave you the wrong link you need to take predbat from the Huawei branch and not From main

gcoan commented 5 months ago

however for it to work you need to fix your load sensor otherwise its not going to do anything useful

@JohanAlvedal if you don't have a native 'home load' sensor easily available in HA, there's the code for custom template to calculate home load from import, export, solar and battery data in the HA docs you could utilise https://springfall2008.github.io/batpred/apps-yaml#data-from-givtcp

JohanAlvedal commented 5 months ago

however for it to work you need to fix your load sensor otherwise its not going to do anything useful

@JohanAlvedal if you don't have a native 'home load' sensor easily available in HA, there's the code for custom template to calculate home load from import, export, solar and battery data in the HA docs you could utilise https://springfall2008.github.io/batpred/apps-yaml#data-from-givtcp

Made one now so I have to wait for some history.

springfall2008 commented 5 months ago

@JohanAlvedal did you try the correct code here? with device_id set https://github.com/springfall2008/batpred/blob/huawei/apps/predbat/predbat.py

JohanAlvedal commented 5 months ago

@JohanAlvedal did you try the correct code here? with device_id set https://github.com/springfall2008/batpred/blob/huawei/apps/predbat/predbat.py

Result of newest prebat.py

https://pastebin.pl/view/9a7685c4

springfall2008 commented 5 months ago

You would need to move away from monitor mode and into control charge to see if it does anything

JohanAlvedal commented 5 months ago

You would need to move away from monitor mode and into control charge to see if it does anything

https://pastebin.pl/view/025b0676

springfall2008 commented 5 months ago

Hmm, odd error - can you go to 'settings, system, logfiles' and select appdeamon (or adddeamon-predbat) and then check for the full error at the end of this log and paste it here please?

JohanAlvedal commented 5 months ago
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/lib/python3.11/concurrent/futures/_base.py", line 456, in result return self.get_result() ^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/concurrent/futures/_base.py", line 401, in get_result raise self._exception File "/usr/lib/python3.11/site-packages/appdaemon/adapi.py", line 1752, in call_service self._check_service(service) File "/usr/lib/python3.11/site-packages/appdaemon/adapi.py", line 1579, in _check_service if service.find("/") == -1: ^^^^^^^^^^^^ AttributeError: 'dict' object has no attribute 'find'

2024-02-06 21:35:03.822087 WARNING pred_bat: ------------------------------------------------------------ 2024-02-06 21:40:03.724586 WARNING pred_bat: ------------------------------------------------------------ 2024-02-06 21:40:03.724732 WARNING pred_bat: Unexpected error in worker for App pred_bat: 2024-02-06 21:40:03.724837 WARNING pred_bat: Worker Ags: {'id': '2f9cb91f26b34c9f8125f68e37b1abdf', 'name': 'pred_bat', 'objectid': '52bbd711c5934b25b04ddaff81ad2496', 'type': 'scheduler', 'function': <bound method PredBat.run_time_loop of <predbat.PredBat object at 0x7f3af340f910>>, 'pin_app': True, 'pin_thread': 0, 'kwargs': {'interval': 300, 'random_start': 0, 'random_end': 0, '__thread_id': 'thread-0'}} 2024-02-06 21:40:03.724926 WARNING pred_bat: ------------------------------------------------------------ 2024-02-06 21:40:03.726075 WARNING pred_bat: Traceback (most recent call last): File "/usr/lib/python3.11/site-packages/appdaemon/threading.py", line 1022, in worker funcref(self.AD.sched.sanitize_timer_kwargs(app, args["kwargs"])) File "/usr/lib/python3.11/site-packages/appdaemon/adbase.py", line 35, in f_app_lock return f(*args, kw) ^^^^^^^^^^^^^^ File "/config/apps/predbat.py", line 12003, in run_time_loop raise e File "/config/apps/predbat.py", line 11999, in run_time_loop self.update_pred(scheduled=True) File "/usr/lib/python3.11/site-packages/appdaemon/adbase.py", line 35, in f_app_lock return f(*args, *kw) ^^^^^^^^^^^^^^ File "/config/apps/predbat.py", line 11037, in update_pred status, status_extra = self.execute_plan() ^^^^^^^^^^^^^^^^^^^ File "/config/apps/predbat.py", line 9841, in execute_plan inverter.adjust_charge_immediate(self.charge_limit_percent_best[0]) File "/config/apps/predbat.py", line 2452, in adjust_charge_immediate self.base.call_service(self.base.get_arg("charge_start_service"), device_id=self.base.get_arg("device_id", index=self.id), target_soc=target_soc) File "/usr/lib/python3.11/site-packages/appdaemon/utils.py", line 231, in inner_sync_wrapper f = run_coroutine_threadsafe(self, coro(self, args, kwargs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/appdaemon/utils.py", line 313, in run_coroutine_threadsafe result = future.result(self.AD.internal_function_timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/concurrent/futures/_base.py", line 456, in result return self.get_result() ^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/concurrent/futures/_base.py", line 401, in get_result raise self._exception File "/usr/lib/python3.11/site-packages/appdaemon/adapi.py", line 1752, in call_service self._check_service(service) File "/usr/lib/python3.11/site-packages/appdaemon/adapi.py", line 1579, in _check_service if service.find("/") == -1: ^^^^^^^^^^^^ AttributeError: 'dict' object has no attribute 'find'

2024-02-06 21:40:03.726209 WARNING pred_bat: ------------------------------------------------------------ 2024-02-06 21:45:03.762781 WARNING pred_bat: ------------------------------------------------------------ 2024-02-06 21:45:03.763146 WARNING pred_bat: Unexpected error in worker for App pred_bat: 2024-02-06 21:45:03.763319 WARNING pred_bat: Worker Ags: {'id': '2f9cb91f26b34c9f8125f68e37b1abdf', 'name': 'pred_bat', 'objectid': '52bbd711c5934b25b04ddaff81ad2496', 'type': 'scheduler', 'function': <bound method PredBat.run_time_loop of <predbat.PredBat object at 0x7f3af340f910>>, 'pin_app': True, 'pin_thread': 0, 'kwargs': {'interval': 300, 'random_start': 0, 'random_end': 0, '__thread_id': 'thread-0'}} 2024-02-06 21:45:03.763519 WARNING pred_bat: ------------------------------------------------------------ 2024-02-06 21:45:03.764956 WARNING pred_bat: Traceback (most recent call last): File "/usr/lib/python3.11/site-packages/appdaemon/threading.py", line 1022, in worker funcref(self.AD.sched.sanitize_timer_kwargs(app, args["kwargs"])) File "/usr/lib/python3.11/site-packages/appdaemon/adbase.py", line 35, in f_app_lock return f(*args, kw) ^^^^^^^^^^^^^^ File "/config/apps/predbat.py", line 12003, in run_time_loop raise e File "/config/apps/predbat.py", line 11999, in run_time_loop self.update_pred(scheduled=True) File "/usr/lib/python3.11/site-packages/appdaemon/adbase.py", line 35, in f_app_lock return f(*args, *kw) ^^^^^^^^^^^^^^ File "/config/apps/predbat.py", line 11037, in update_pred status, status_extra = self.execute_plan() ^^^^^^^^^^^^^^^^^^^ File "/config/apps/predbat.py", line 9841, in execute_plan inverter.adjust_charge_immediate(self.charge_limit_percent_best[0]) File "/config/apps/predbat.py", line 2452, in adjust_charge_immediate self.base.call_service(self.base.get_arg("charge_start_service"), device_id=self.base.get_arg("device_id", index=self.id), target_soc=target_soc) File "/usr/lib/python3.11/site-packages/appdaemon/utils.py", line 231, in inner_sync_wrapper f = run_coroutine_threadsafe(self, coro(self, args, kwargs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/appdaemon/utils.py", line 313, in run_coroutine_threadsafe result = future.result(self.AD.internal_function_timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/concurrent/futures/_base.py", line 456, in result return self.get_result() ^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/concurrent/futures/_base.py", line 401, in get_result raise self._exception File "/usr/lib/python3.11/site-packages/appdaemon/adapi.py", line 1752, in call_service self._check_service(service) File "/usr/lib/python3.11/site-packages/appdaemon/adapi.py", line 1579, in _check_service if service.find("/") == -1: ^^^^^^^^^^^^ AttributeError: 'dict' object has no attribute 'find'

2024-02-06 21:45:03.765711 WARNING pred_bat: ------------------------------------------------------------

springfall2008 commented 5 months ago

What do you have in apps.yaml for 'charge_start_service' ?

JohanAlvedal commented 5 months ago

charge_start_service: service: huawei_solar/forcible_charge_soc data: target_soc: 100 power: "3000"

JohanAlvedal commented 5 months ago

IMG_0322

springfall2008 commented 5 months ago

No sorry in apps.yaml it should say:

charge_start_service: service: huawei_solar/forcible_charge_soc device_id: XXXX

And you need to replace the XXXX with your device ID as per the above template

JohanAlvedal commented 5 months ago

https://pastebin.pl/view/9172ef45

apps.yaml code

Services to charge/discharge

charge_start_service: service: huawei_solar/forcible_charge_soc device_id: 6893ee838a0972bd3e50d9e0faa0ba5a

charge_stop_service: service: huawei_solar/stop_forcible_charge device_id: 6893ee838a0972bd3e50d9e0faa0ba5a

discharge_start_service: service: huawei_solar/forcible_discharge_soc device_id: 6893ee838a0972bd3e50d9e0faa0ba5a

discharge_stop_service: service: huawei_solar/stop_forcible_charge device_id: 6893ee838a0972bd3e50d9e0faa0ba5a

Predbat, HA log

` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/concurrent/futures/_base.py", line 456, in result return self.get_result() ^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/concurrent/futures/_base.py", line 401, in get_result raise self._exception File "/usr/lib/python3.11/site-packages/appdaemon/adapi.py", line 1752, in call_service self._check_service(service) File "/usr/lib/python3.11/site-packages/appdaemon/adapi.py", line 1579, in _check_service if service.find("/") == -1: ^^^^^^^^^^^^ AttributeError: 'dict' object has no attribute 'find'

2024-02-06 22:12:55.709484 WARNING pred_bat: ------------------------------------------------------------ 2024-02-06 22:13:30.822254 WARNING pred_bat: ------------------------------------------------------------ 2024-02-06 22:13:30.822428 WARNING pred_bat: Unexpected error in worker for App pred_bat: 2024-02-06 22:13:30.822533 WARNING pred_bat: Worker Ags: {'id': 'ac684c787a14409cafd0896086e6776f', 'name': 'pred_bat', 'objectid': 'e1f704e86c354964a1212ad9e1b4e6b9', 'type': 'scheduler', 'function': <bound method PredBat.update_time_loop of <predbat.PredBat object at 0x7f23ac9af690>>, 'pin_app': True, 'pin_thread': 0, 'kwargs': {'interval': 15, 'random_start': 0, 'random_end': 0, '__thread_id': 'thread-0'}} 2024-02-06 22:13:30.822620 WARNING pred_bat: ------------------------------------------------------------ 2024-02-06 22:13:30.823769 WARNING pred_bat: Traceback (most recent call last): File "/usr/lib/python3.11/site-packages/appdaemon/threading.py", line 1022, in worker funcref(self.AD.sched.sanitize_timer_kwargs(app, args["kwargs"])) File "/usr/lib/python3.11/site-packages/appdaemon/adbase.py", line 35, in f_app_lock return f(*args, kw) ^^^^^^^^^^^^^^ File "/config/apps/predbat.py", line 11981, in update_time_loop raise e File "/config/apps/predbat.py", line 11976, in update_time_loop self.update_pred(scheduled=False) File "/usr/lib/python3.11/site-packages/appdaemon/adbase.py", line 35, in f_app_lock return f(*args, *kw) ^^^^^^^^^^^^^^ File "/config/apps/predbat.py", line 11037, in update_pred status, status_extra = self.execute_plan() ^^^^^^^^^^^^^^^^^^^ File "/config/apps/predbat.py", line 9841, in execute_plan inverter.adjust_charge_immediate(self.charge_limit_percent_best[0]) File "/config/apps/predbat.py", line 2452, in adjust_charge_immediate self.base.call_service(self.base.get_arg("charge_start_service"), device_id=self.base.get_arg("device_id", index=self.id), target_soc=target_soc) File "/usr/lib/python3.11/site-packages/appdaemon/utils.py", line 231, in inner_sync_wrapper f = run_coroutine_threadsafe(self, coro(self, args, kwargs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/appdaemon/utils.py", line 313, in run_coroutine_threadsafe result = future.result(self.AD.internal_function_timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/concurrent/futures/_base.py", line 456, in result return self.get_result() ^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/concurrent/futures/_base.py", line 401, in get_result raise self._exception File "/usr/lib/python3.11/site-packages/appdaemon/adapi.py", line 1752, in call_service self._check_service(service) File "/usr/lib/python3.11/site-packages/appdaemon/adapi.py", line 1579, in _check_service if service.find("/") == -1: ^^^^^^^^^^^^ AttributeError: 'dict' object has no attribute 'find'

2024-02-06 22:13:30.823890 WARNING pred_bat: ------------------------------------------------------------ 2024-02-06 22:15:03.818652 WARNING pred_bat: ------------------------------------------------------------ 2024-02-06 22:15:03.818856 WARNING pred_bat: Unexpected error in worker for App pred_bat: 2024-02-06 22:15:03.819021 WARNING pred_bat: Worker Ags: {'id': 'a325f77312ec4a40a42917bbda943697', 'name': 'pred_bat', 'objectid': 'e1f704e86c354964a1212ad9e1b4e6b9', 'type': 'scheduler', 'function': <bound method PredBat.run_time_loop of <predbat.PredBat object at 0x7f23ac9af690>>, 'pin_app': True, 'pin_thread': 0, 'kwargs': {'interval': 300, 'random_start': 0, 'random_end': 0, '__thread_id': 'thread-0'}} 2024-02-06 22:15:03.819152 WARNING pred_bat: ------------------------------------------------------------ 2024-02-06 22:15:03.820364 WARNING pred_bat: Traceback (most recent call last): File "/usr/lib/python3.11/site-packages/appdaemon/threading.py", line 1022, in worker funcref(self.AD.sched.sanitize_timer_kwargs(app, args["kwargs"])) File "/usr/lib/python3.11/site-packages/appdaemon/adbase.py", line 35, in f_app_lock return f(*args, kw) ^^^^^^^^^^^^^^ File "/config/apps/predbat.py", line 12003, in run_time_loop raise e File "/config/apps/predbat.py", line 11999, in run_time_loop self.update_pred(scheduled=True) File "/usr/lib/python3.11/site-packages/appdaemon/adbase.py", line 35, in f_app_lock return f(*args, *kw) ^^^^^^^^^^^^^^ File "/config/apps/predbat.py", line 11037, in update_pred status, status_extra = self.execute_plan() ^^^^^^^^^^^^^^^^^^^ File "/config/apps/predbat.py", line 9841, in execute_plan inverter.adjust_charge_immediate(self.charge_limit_percent_best[0]) File "/config/apps/predbat.py", line 2452, in adjust_charge_immediate self.base.call_service(self.base.get_arg("charge_start_service"), device_id=self.base.get_arg("device_id", index=self.id), target_soc=target_soc) File "/usr/lib/python3.11/site-packages/appdaemon/utils.py", line 231, in inner_sync_wrapper f = run_coroutine_threadsafe(self, coro(self, args, kwargs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/appdaemon/utils.py", line 313, in run_coroutine_threadsafe result = future.result(self.AD.internal_function_timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/concurrent/futures/_base.py", line 456, in result return self.get_result() ^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/concurrent/futures/_base.py", line 401, in get_result raise self._exception File "/usr/lib/python3.11/site-packages/appdaemon/adapi.py", line 1752, in call_service self._check_service(service) File "/usr/lib/python3.11/site-packages/appdaemon/adapi.py", line 1579, in _check_service if service.find("/") == -1: ^^^^^^^^^^^^ AttributeError: 'dict' object has no attribute 'find'

2024-02-06 22:15:03.820551 WARNING pred_bat: ------------------------------------------------------------`

springfall2008 commented 5 months ago

Sorry I'm maybe not being specific, the apps.yaml should say:

Services to charge/discharge

device_id: 6893ee838a0972bd3e50d9e0faa0ba5a

charge_start_service: huawei_solar/forcible_charge_soc charge_stop_service: huawei_solar/stop_forcible_charge discharge_start_service: huawei_solar/forcible_discharge_soc discharge_stop_service: huawei_solar/stop_forcible_charge

JohanAlvedal commented 5 months ago

predbat.log https://pastebin.pl/view/06a3d469

Addon log. s6-rc: info: service s6rc-oneshot-runner: starting s6-rc: info: service s6rc-oneshot-runner successfully started s6-rc: info: service base-addon-banner: starting


Add-on: appdaemon-predbat Predbat pre-install in AppDaemon

Add-on version: 1.0.6 You are running the latest version of this add-on. System: Home Assistant OS 11.5 (amd64 / generic-x86-64) Home Assistant Core: 2024.1.6 Home Assistant Supervisor: 2024.01.1

Please, share the above information when looking for help or support in, e.g., GitHub, forums or the Discord chat.

s6-rc: info: service base-addon-banner successfully started s6-rc: info: service fix-attrs: starting s6-rc: info: service base-addon-log-level: starting s6-rc: info: service fix-attrs successfully started s6-rc: info: service base-addon-log-level successfully started s6-rc: info: service legacy-cont-init: starting s6-rc: info: service legacy-cont-init successfully started s6-rc: info: service init-appdaemon: starting s6-rc: info: service init-appdaemon successfully started s6-rc: info: service appdaemon: starting s6-rc: info: service appdaemon successfully started s6-rc: info: service legacy-services: starting [00:49:32] INFO: Starting AppDaemon... s6-rc: info: service legacy-services successfully started

HA core log Logger: homeassistant.helpers.service Source: helpers/service.py:246 First occurred: 01:17:09 (8 occurrences) Last logged: 06:00:41

Referenced entities switch.predbat_load_filter_modal are missing or not currently available Referenced entities switch.predbat_set_status_notify are missing or not currently available Referenced entities switch.predbat_set_inverter_notify are missing or not currently available Referenced entities switch.predbat_set_reserve_enable are missing or not currently available

springfall2008 commented 5 months ago

Can you actually try trigger a force charge and a force discharge to a target SOC in Developer Tools/Services and then send me the YAML for both of them (if they actually work)?

springfall2008 commented 5 months ago

I think I might have to add 'power', if so what value?

JohanAlvedal commented 5 months ago

I think I might have to add 'power', if so what value?

Charge night time 4500w Charge day 2500w Discharge 1500-2000w

JohanAlvedal commented 5 months ago

IMG_0327 IMG_0326 IMG_0325 IMG_0324 IMG_0323

springfall2008 commented 5 months ago

Do the above all work okay when you hit 'call service'?

It seems that we need to add power, what's the maximum power?

springfall2008 commented 5 months ago

Updated to include power setting here: https://raw.githubusercontent.com/springfall2008/batpred/huawei/apps/predbat/predbat.py

JohanAlvedal commented 5 months ago

Yes, it works. But they need different types of settings in battery so they can be difficult to combine. Ex TOU only works if you have chosen it. Maximise ... only work at force….

JohanAlvedal commented 5 months ago

Updated to include power setting here: https://raw.githubusercontent.com/springfall2008/batpred/huawei/apps/predbat/predbat.py

Where do i add soc and watts?

springfall2008 commented 5 months ago

Updated to include power setting here: https://raw.githubusercontent.com/springfall2008/batpred/huawei/apps/predbat/predbat.py

Where do i add soc and watts?

They are in the code, just update to the version I linked (I just fixed a typo on it).

JohanAlvedal commented 5 months ago

It seems to work roughly, but there is still a little that needs to be polished as, for example, my house's fuses are at risk of blowing if it charges more than 2500w during the day unless the sun is shining / charging. It is currently a bit useless as tomorrow's prices still show today's and ? So it doesn't always schedule a charge at night, which it might not always but still. A perhaps easier way to go might be TOU. ex. Huawei Solar: Set TOU Periods Time/duration. in combination with the battery's work mide, Maximize self consumption. for sunny days when it can then charge the battery and then sell the surplus. We've got 30 cm of snow here now so my solar cells give 0w at the moment so I'll let it roll for a few days and we'll see how it behaves.

Skärmavbild 2024-02-08 kl  07 11 21 Skärmavbild 2024-02-08 kl  07 17 11
springfall2008 commented 5 months ago

Now we have a first draft of the controls we need to get your basic Predbat predictions working correctly. Do you now have enough history to get sensible load predictions? What do your charts and battery plan look like?

Maximum charge rate can be capped in apps.yaml if you want

JohanAlvedal commented 5 months ago

IMG_1552 IMG_1553 IMG_1554 IMG_1555

springfall2008 commented 5 months ago

How big is your battery, the charge and discharge seem very slow?

JohanAlvedal commented 5 months ago

How big is your battery, the charge and discharge seem very slow?

10 kw

springfall2008 commented 5 months ago

There's something wrong here, your battery is being reported as 100kWh

2024-02-07 06:00:03.089884 INFO pred_bat: Inverter 0 SOC: 96.0 kW 96 % Current charge rate 4500.0 w Current discharge rate 4500.0 w Current power 0.0 w Current voltage 52.0

springfall2008 commented 5 months ago

soc_max should be set to the battery size in kWh and not to a percentage number

soc_max:

Should work if your battery is 10kWh

On the other hand charge_limit should be set to the correct target charge %, although its not being used in this integration maybe it could be this: number.battery_end_of_charge_soc

So it should be:

  soc_max:
   - 10
  charge_limit:
    - number.battery_end_of_charge_soc
JohanAlvedal commented 5 months ago

Ok that explains a lot

JohanAlvedal commented 5 months ago

but should I use soc_percent: - sensor.battery_state_of_capacity Or soc_kw: - sensor.battery_to_kwh

springfall2008 commented 5 months ago

I believe either is fine, I'd use whichever is the primary source of information

JohanAlvedal commented 5 months ago

It was supposed to start charging now at 22:00 but nothing happened. Was there something I needed to do with power and soc in my Apps.yaml?

springfall2008 commented 5 months ago

What does the log say?

JohanAlvedal commented 5 months ago

What does the log say?

https://justpaste.it/cuug6

springfall2008 commented 5 months ago

So the force charge service didn't work

2024-02-08 22:00:03.682763 WARNING HASS: Error calling Home Assistant service default/huawei_solar/forcible_charge_soc 2024-02-08 22:00:03.683995 WARNING HASS: Code: 400, error: 400: Bad Request

springfall2008 commented 5 months ago

Can you update to this version with some extra debug info and re-run and gather the log?

https://raw.githubusercontent.com/springfall2008/batpred/huawei/apps/predbat/predbat.py

BTW: Did the change to the soc_max fix the plan, what does it look like now?

JohanAlvedal commented 5 months ago

BTW: Did the change to the soc_max fix the plan, what does it look like now?

Yes, that seems to be true now.

JohanAlvedal commented 5 months ago

I have to take a step back and go through which working mode it should be, etc. because right now I see it's behaving a bit funny. Will see this weekend if I have time to test.

Right now it's running TOU with schedules being put in and it's working very well. It might be another way to proceed with the Charge battery process. To easily discharge, you can instead change the work mode to Maximize self consumption, because then the discharge starts immediately. You can also use number.battery_maximum_discharging_power to set power. Then you set back to working mode TOU to interrupt the discharge

Then it is also an idea to try to get the prices for tomorrow also because now, for example, it wants to charge the battery before 00:00 when it is the cheapest that day. Then predbat does not know that it will be even cheaper, for example at 02:00