Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Sunsynk inverter via Solarsynk2 add-on for Home Assistant #129

Open
ElectricMolehill opened this issue Feb 18, 2024 · 91 comments
Labels
inverter support Support for new hardware

Comments

@ElectricMolehill
Copy link

Hi fboundy

  • this is fantastic, just what I was looking for. Unfortunately I bought a solar system before coming across pv_opt and it's Sunsynk. Sorry I'm not qualified to write the inverter class would you consider doing it? I have written up what I know in the attached document and also completed the template below. There are one or two gaps, maybe we can fill them by testing or asking the developer of the solarsynk2 add-on martinville

regards
Mark

PV Opt can be updated to support additional models and brands of inverter. If you want to request this, please supply as much of the following information as possible:

Home Assistant Entities to Read

PV Opt reads data from a number of entities in Home Assistant. These will vary by inverter. Please document what your inverter provides. Examples are provided from the Solis Solax Modbus integration:
Battery minimum SOC: number.solis_battery_minimum_soc
Battery SOC:         sensor.solis_battery_soc
Either:
  Load power:        [sensor.solis_house_load, sensor.solis_bypass_load], or
  Load today:        sensor.solis_house_load_today
Either:
  Grid import power: sensor.solis_grid_import_power and
  Grid export power: sensor.solis_grid_export_power
Or:
  Grid import today: sensor.solis_grid_import_today and
  Grid export today: sensor.solis_grid_export_today

Inverter Control

PV Opt also needs to control your inverter. How this is done and what can be done varies hugely by brand, by model and by the integration you use with Home Assistant. Please provide as much detail under each heading. Examples are provided for the Solis inverter using the both the Solax Modbus Integration and the HA Core Modbus functionality. Please add your details below:

Examples

Solis Solax Modbus Solis Core HA Modbus
How do you enable forced charging? Only done via timed charge Only done via timed charge
How do you enable forced discharging? Only done via timed discharge Only done via distimed charge
Are forced charge and discharge controlled using Power or Current? Current Current
Does your inverter support timed charging slots? Yes Yes
Does your inverter support timed discharging slots? Yes Yes
How do you enabled timed charge? Set the following: number.timed_charge_start_hour, number.timed_charge_start_minute, number.timed_charge_end_hour, number.timed_charge_start_minute. Then press 'button.solis_update_charge_discharge_times. Set the required current to number.solis_timed_charge_current. Ensure select.solis_energy_storage_control_switch has Timed Grid Charging enabled. Use the modbus\write_register service to write start and end hours and minutes to the correct registers. Ensure the energy_storage_control_switch has Bits 2 and 5 enabled. Set the required current using the modbus\write_register service
How do you enabled timed charge? As for charging but all entities are discharge rather than charge As for charging but registers are different.
Can you set a target SOC for a timed charge period? No No
Can you set a target SOC for a timed discharge period? No No
What modes does you inverter have and how are they controlled? One register on the inverter Energy Control Switch which controls mode in a bit-wise sense. Only some modes can be selected vai the entity select.solis_energy_storage_control_switch One register on the inverter Energy Control Switch which controls mode in a bit-wise sense. The required number is set using the modbus\write_register service

Your Setup

What is the inverter brand?

Sunsynk

What is the inverter model?

ECCO 3.6kW hybrid inverter SYNK-3.6K-SG04LP1

What integration do you use in Home Assistant

Solarsynk2 add-on. There is another one Deye/Sunsynk Home Assistant add-on by kellerza but this requires a direct wired connection to the inverter

How do you enable forced charging?

Only done via a timer. Set a time slot x, tick grid time x to allow charging from grid, target SOC x (above current SOC) and power x. 6 slots are available

How do you enable forced discharging?

Only done via a timer. Set a time slot x, tick grid time x to allow charging from grid, target SOC x (below current SOC) and power x

Are forced charge and discharge controlled using Power or Current?

Power (W) and target SOC whichever is the smaller

Does your inverter support timed charging slots?

6 slots used for charge and discharge. Should be contiguous, sequential and cover the whole 24 hrs

Does your inverter support timed discharging slots?

Same timeslots as for charging but with a different target SOC

How do you enabled timed charge?

Set Use Timer = true To do this, populate helper input_text.solarsynk_{inverter serial no}_settings with json to update Sunsynk cloud api: {"peakAndVallery": "1"} (just possible this is a misspelling) Also required for slot x - Start time ("sellTime(x)": "02:00") Grid timer x ("time(x)on": true) Target SOC ("cap(x)": "80") if this is higher value than current SOC, batteries wil charge up to this value from the grid Power x ("sellTime(x)Pac": "3600") End time is defined implicitly by the start time of the next slot. An appdaemon process runs every 5 min to post the contents of this helper to the Sunsunk cloud api. This is not ideal because it's not online. Perhaps I could get the Solarsynk developer martinville to add a realtime update method

How do you enabled timed discharge?

As for charging but set target SOC low

Can you set a target SOC for a timed charge period?

Yes - this would be the usual manual method

Can you set a target SOC for a timed discharge period?

Yes

What modes does you inverter have and how are they controlled?

There are some settings which limit export to load or grid. Details to be confirmed but probably should be set manually

Any other useful information

See attached doc [sunsynk inverter class for pv_opt.odt](https://github.com/fboundy/pv_opt/files/14324224/sunsynk.inverter.class.for.pv_opt.odt)
@ElectricMolehill
Copy link
Author

Forgot to add HA entities to read:

Battery minimum SOC: sensor.solarsynk_{inverter sn}_battery_shutdown_cap (%)
Battery SOC:         sensor.solarsynk_{inverter sn}_battery_soc (%)
Either:
  Load power:        sensor.solarsynk_{inverter sn}_load_power (kW), or
  Load today:        sensor.solarsynk_{inverter sn}_day_load_energy (i.e kWh)
Either:
  Grid import power: sensor.solarsynk_{inverter sn}_grid_power (this is probably total import and export)
  Grid export power: 
Or:
  Grid import today: sensor.solarsynk_{inverter sn}_day_grid_import (kWh) and
  Grid export today: sensor.solarsynk_{inverter sn}_day_grid_export (kWh)

@fboundy
Copy link
Owner

fboundy commented Feb 19, 2024

I can certainly try to get something working for you. It may take a while - need to solve a few other bugs 1st.

@ElectricMolehill
Copy link
Author

That's great, thankyou. The installation's only been in for a week and we're not certified to export yet. Then I'll need to familiarise myself with programming it manually. What do you think about the update settings method provided by the Solarsynk add-on? It takes up to 5 min to send to the cloud, then maybe another 5 min until the results are readable from HA sensors. Is that fast enough?

regards
Mark

@fboundy
Copy link
Owner

fboundy commented Feb 23, 2024

OK - I've had a very preliminary start at this. It will is v4.0.0-alpha-1 pre-release so you will need to enable Beta versions in HACS and manually select it. You will also need the config_sunsynk.yaml file from the GitHub release or the branch associated with this Issue (rename it to config.yaml

If you are very lucky it might work in Read Only mode! Either way please send me the logs. In the meantime I will try to have a look at the documentation for the integration.

@ElectricMolehill
Copy link
Author

Thanks I'll give it a go! I'll try to clarify the working modes for the inverter tomorrow - they control whether the inverter gives priority to essential load / non-essential load / battery / grid export. I've also discovered another check we should do - the inverter will support battery types which use voltage instead of SOC to control charge / discharge so we should check that the battery is compatible with SOC. Also, I think my documentation is wrong about ticking 'Grid' for a discharge, it looks like it should be unticked. I'll update the documentation

@ElectricMolehill
Copy link
Author

Sorry my mistake - {inverter sn} should be {sunsynk_serial} as defined in solarsynk addon. Also - cosmetic change - could you change the spelling of solarsync2 to solarsynk2 please. I don't know how far I can get with testing because we're not certified for export yet so we haven't changed tariff from the fixed rate Flexible Octopus to some thing smart such as Agile or Flux. Unless there's a way to bypass it for testing purposes?

@ElectricMolehill
Copy link
Author

I think there are 2 typos in sunsynk.py:
image

@fboundy
Copy link
Owner

fboundy commented Feb 24, 2024

Is there any way of extracting {sunsynk_serial} from the addon? If not I might prefer to keep {inverter_sn} as a generic parameter across brands. Will fix the typos now and re-release as alpha-2

@fboundy
Copy link
Owner

fboundy commented Feb 24, 2024

alpha-2 available. You will need to manually copy config-sunsynk.yaml

@ElectricMolehill
Copy link
Author

[sunsynk_serial} is in the config for the Solarsynk add-on but I can't see a sensor for it

@fboundy
Copy link
Owner

fboundy commented Feb 24, 2024 via email

@ElectricMolehill
Copy link
Author

Sorry but I think there's another typo:
image

@ElectricMolehill
Copy link
Author

Also I think the underline character is missing in {inverter_sn} on all of the sensors above

@ElectricMolehill
Copy link
Author

Updated my documentation for the inverter. There are a couple of problems, such as

  • No method in Solarsynk integration to check max power of inverter
  • No method in Solarsynk integration to check whether an Auxiliary power source (e.g. generator / wind turbine) is connected which I imagine would invalidate a pv_opt plan
  • The Solarsynk update method is based on a batch process and takes 5 - 10 minutes to return, plus the return codes are only visible in the Solarsynk log

Apart from that I think it should work!
sunsynk inverter class for pv_opt v2.odt

@fboundy
Copy link
Owner

fboundy commented Feb 25, 2024

That's great - I will have a proper read of this now and have a think about how to implement it

@ElectricMolehill
Copy link
Author

Here are the logs from running v4.0.0 alpha2
error.log
main.log
pv_opt.log

@fboundy
Copy link
Owner

fboundy commented Mar 6, 2024 via email

@ElectricMolehill
Copy link
Author

Hope you're having a nice holiday. I made some progress by hard coding the inverter serial number in config.yaml (inverter serial number redacted manually - 10 digits, also my Octopus account has an e instead of an m):

image
image

Now pv_opt gets further:
error.log
main.log
pv_opt.log

You'll see I'm on the Octopus Flux tariff for import but don't yet have an export tariff. I have submitted the MCS certificate and permission from the DNO but I think it can take weeks to get an export MPAN number

@alz41
Copy link

alz41 commented Mar 9, 2024

following developments

@fboundy
Copy link
Owner

fboundy commented Mar 16, 2024

I've synced this branch up with the main branch so it should now handle the lack of an export contract OK which was the point of failure before. Also added the inverter_sn to the redaction list. Released as 4.0.0-alpha3

@ElectricMolehill
Copy link
Author

Hope you had a good holiday! We got our export MPAN this morning but Octopus don't seem to have taken any readings yet. Perhaps overnight. I reloaded the Octopus integration in HA and the export sensors appeared. I installed pv_opt 4.0.0-alpha4 and ran again. I reverted to the config_sunsynk.yaml from GitHub and used this to overwrite my config.yaml because pv_opt doesn't seem to be picking up some values correctly. I edited it to add the correct value of {inverter_sn}. From the logs it looks like pv_opt isn't picking up {device_name} or {inverter_sn}. Also I think there are a couple of typos in config.yaml:

  • inverter_type: "SUNSYNK_SOLARSYNC2" should be inverter_type: "SUNSYNK_SOLARSYNK2"
  • "maximum_dod_percent": "sensor.{device_name}_{inverter sn}_battery_shutdown_cap" # presumably should be {inverter_sn}
  • "id_battery_soc": " sensor.{device_name}_{inverter sn}_battery_soc" # as above underline character missing
  • "id_consumption_today": "sensor.{device_name}_{inverter sn}_day_load_energy" # as above, underline character missing
  • "id_grid_import_today": "sensor.{device_name}_{inverter sn}_day_grid_import" # as above, underline character missing
  • "id_grid_export_today": "sensor.{device_name}_{inverter sn}_day_grid_import" # as above, underline character missing, also I think import should be export
    error.log
    main.log
    pv_opt.log
    Also I think redaction list needs another line for my MPAN number which is of the form 99e9999999_9999999999999 instead of 99m9999999_9999999999999 (perhaps e and m are region markers?)

@fboundy
Copy link
Owner

fboundy commented Mar 17, 2024

Thanks for this. In 4.0.0-alpha-5 I have removed config-sunsynk.yaml and merged all the changes in to the main config.yaml. You should just need to un-comment the final block of parameters in this file.

I've also updated the regex pattern for the MPAN.

Hopefully with the correction of SOLARSYNC2 to SOLARSYNK2 it should get a bit further. Let me know how you get on.

@ElectricMolehill
Copy link
Author

Thanks - got a lot further this time but still seems to be ending with an error:
ValueError: cannot reindex on an axis with duplicate labels
Redaction mostly working but there are a couple of lines in pv_opt.log still containing inverter serial number and account_MPAN number
One of the defaults in config.yaml still looks wrong :
image
Think this should read
id_grid_export_today: sensor.{device_name}_{inverter_sn}day_grid_export
instead of
id_grid_export_today: sensor.{device_name}
{inverter_sn}_day_grid_import
error.log
main.log
pv_opt.log

@fboundy fboundy added the inverter support Support for new hardware label Mar 20, 2024
@alz41
Copy link

alz41 commented Mar 25, 2024

would really like to get this working

@fboundy
Copy link
Owner

fboundy commented Mar 27, 2024

OK - apologies for the delay. Please can you try pre-release 4.0.0-sunsynk-alpha-7 which should address the issues above and also includes various patches made to the production release.

@ElectricMolehill
Copy link
Author

Thanks I'll give it a go. Actually I wasn't ready until today - SSD failed and it's taken me a week to get a replacement and recover Home Assistant from backup. We've also got some persistent connectivity problems with Solarsynk as a result of which my updates from a couple of HA automations don't seem to be working. It seems to be affecting all users of Solarsynk so it might be the cloud app that is at fault. On the plus side I'm now exporting to the grid and getting paid for it. As a result I've found out more about the Sunsynk inverter's eccentricities. For example, charge current is not controlled by the timers. Also, to discharge the batteries to the grid I need to change the Work Mode from 'Limited to Home' = 2 to 'Selling First' = 0 in real time because otherwise I can't discharge the battery to Home at other times without exporting as well. I've also found a different Sunsynk HA integration by MorneSaunders360 which also works via the cloud API but has an HA service to update the inverter which might be more appropriate for pv_opt. I'll have a look at that. In the meantime I have updated my documentation - sorry if I've misled you so far!
sunsynk inverter class for pv_opt v3.odt

@alz41
Copy link

alz41 commented Mar 27, 2024

OK - apologies for the delay. Please can you try pre-release 4.0.0-sunsynk-alpha-7 which should address the issues above and also includes various patches made to the production release.

Currently unable to test properly due to ongoing problems with Solarsynk.

Sunsynk.py still has references to "SUNSYNK_SOLARSYNC2" should be "SUNSYNK_SOLARSYNK2" (Lines 72, 86, 117)

error.log
main.log
pv_opt.log

@fboundy
Copy link
Owner

fboundy commented Mar 28, 2024

4.0.0-sunsynk-alpha-8 should fix the typos and also bring the underlying code up to date with the latest production release

@ElectricMolehill
Copy link
Author

I think I've got the latest version but it's reporting

  • PV Opt v4.0.0-4.0.0-sunsynk-alpha-7
    in the pv_opt.log

When I start the application it is stuck at 'Initialising PV model'. There is a warning in error.log:

@fboundy
Copy link
Owner

fboundy commented Apr 3, 2024 via email

@ElectricMolehill
Copy link
Author

@alz41 is Mosquitto running OK?

@alz41
Copy link

alz41 commented Apr 3, 2024

@fboundy whats strange is the sensors are created but not the helpers

LOG AFTER 30MINS OF RUNNING (ERROR LOG [EMPTY)

error.log
main.log
pv_opt.log

@fboundy
Copy link
Owner

fboundy commented Apr 3, 2024

OK - I'll try to get an update out tomorrow which is up to date with the main beta version. Might help

@alz41
Copy link

alz41 commented Apr 3, 2024

OK - I'll try to get an update out tomorrow which is up to date with the main beta version. Might help

thanks

Mosquitto log shows connection as below

Mosquitto broker
2024-04-03 19:06:31: New client connected from 172.30.33.6:55967 as localad (p2, c1, k60, u'PV_OPT').

@fboundy
Copy link
Owner

fboundy commented Apr 4, 2024

I've just released 3.14.0-alpha-16 (decided that this won't be v4 after all) which should have a lot more functioning features. It doesn't write to the solarsynk helper entity but it writes the JSON that it would have written to the log file.

I'm trying to get all these various features into 3.14.0 and get that out asap so let me know what you find

@alz41
Copy link

alz41 commented Apr 4, 2024

3.14.0-alpha-16
helpers still not being created

error.log
main.log
pv_opt.log

Mosquitto.log
2024-04-04 21:51:52: New connection from 172.30.33.6:52653 on port 1883.
2024-04-04 21:51:52: New client connected from 172.30.33.6:52653 as localad (p2, c1, k60, u'PV_OPT').

Supervisor.log
2024-04-04 20:48:11.237 INFO (MainThread) [supervisor.auth] Auth request from 'core_mosquitto' for 'PV_OPT'
2024-04-04 20:48:11.711 INFO (MainThread) [supervisor.auth] Successful login for 'PV_OPT'
2024-04-04 20:57:04.842 INFO (MainThread) [supervisor.auth] Auth request from 'core_mosquitto' for 'PV_OPT'
2024-04-04 20:57:05.317 INFO (MainThread) [supervisor.auth] Successful login for 'PV_OPT'
2024-04-04 21:51:52.312 INFO (MainThread) [supervisor.auth] Auth request from 'core_mosquitto' for 'PV_OPT'
2024-04-04 21:51:53.567 INFO (MainThread) [supervisor.auth] Successful login for 'PV_OPT'

@fboundy
Copy link
Owner

fboundy commented Apr 4, 2024 via email

@alz41
Copy link

alz41 commented Apr 7, 2024

Does sound like an MQTT problem.

solar assistant works fine with MQTT, ANY IDEA HOW TO DEBUG.
Have already uninstalled rebooted and reinstalled still same error

@fboundy
Copy link
Owner

fboundy commented Apr 8, 2024

I've successfully debugged MQTT issues with MQTT Explorer in the past.

There is an error being caused by a bug in the sunsynk controller which I will fix for the next release . This isn't related to the MQTT but if we can get everything else running perhaps we can diagnose better.

@alz41
Copy link

alz41 commented Apr 9, 2024 via email

@fboundy
Copy link
Owner

fboundy commented Apr 9, 2024

Should be fixed in the 3.14.0 release

@alz41
Copy link

alz41 commented Apr 9, 2024

logs from 3.14.0 release
14:37:26 WARNING pv_opt: Unexpected error in worker for App pv_opt:

error.log
main.log
pv_opt.log

@alz41
Copy link

alz41 commented Apr 10, 2024

@alz41 is Mosquitto running OK?

@ElectricMolehill
Yes, Sensors show when i connect with MQTT EXPLORER but not showing in Home Assistant

@fboundy
Copy link
Owner

fboundy commented Apr 11, 2024

I'm away for a couple of days. Will try to look when I'm back

@ElectricMolehill
Copy link
Author

I installed v3.14.1 - it's running fine but I had to add 2 lines to config.yaml:

  • battery_voltage: sensor.{device_name}_{inverter_sn}_battery_voltage
  • id_solar_power: sensor.{device_name}_{inverter_sn}_pv1_power (i.e. string 1 only)

I had to spell out inverter_sn explicitly in both cases as pv_opt did not pick it up from config
Solarsynk has 1 power sensor for each PV string pv1 and pv2. It doesn't have a total value for pv power but it does for battery related sensors such as battery_power1 / battery_power2 and battery_power so perhaps I could ask for a total to be added

Good news is, Solarsynk is now running reliably with no dropouts since SSL certificate checking was disabled
image
(ignore the glitch yesterday just after 21:00 - I accidentally pulled the network cable loose)

I think I misunderstood the meaning of 'Hold SOC' when I sent you my documentation. Does it mean - 'maintain SOC for a 15 min timeslot without charging or discharging at all'? If so then I was wrong and there is a way to do this. I'll need to do some more testing to confirm the best way to do it

error.log
main.log
pv_opt.log

@alz41
Copy link

alz41 commented Apr 14, 2024

version 3.14.2 logs

error.log
main.log
pv_opt.log

@fboundy
Copy link
Owner

fboundy commented Apr 15, 2024

@alz41: 3.14.3 should fix the error in solarsynk_set_helper

@ElectricMolehill: It should also allow you to specify two a list of entities for the solar power:

  id_solar_power: 
    - sensor.{device_name}_pv_power_1
    - sensor.{device_name}_pv_power_2

@alz41
Copy link

alz41 commented Apr 15, 2024

3.14.3 logs

WARNING pv_opt: Unexpected error in worker for App pv_opt:

error.log
main.log
pv_opt.log

@alz41
Copy link

alz41 commented Apr 17, 2024

after changing overwrite_ha_on_restart: to false and ev charger to none everything working as expected.

should PVOPT be making changes to inverter settings for charge/discharge?

@fboundy
Copy link
Owner

fboundy commented Apr 18, 2024

At present it should just be writing the state of the Solarsynk helper to the log but I've just spotted a typo. I will fix and issue an update but if you want to edit yourself it is line 135 in sunsynk.py. It should be:

    self.rlog(f"Setting SolarSynk input helper {entity_id} to {new_json}")

@alz41
Copy link

alz41 commented Apr 18, 2024

@fboundy

At present it should just be writing the state of the Solarsynk helper to the log but I've just spotted a typo. I will fix and issue an update but if you want to edit yourself it is line 135 in sunsynk.py. It should be:

    self.rlog(f"Setting SolarSynk input helper {entity_id} to {new_json}")

Made the above change,
Clicking send to inverter on the Pvopt test card raises the following error - pandas._libs.tslibs.parsing.DateParseError: Unknown datetime string format, unable to parse: sensor.{device_name}_2301058444_prog1_time

Full logs below
error.log
main.log
pv_opt.log

@alz41
Copy link

alz41 commented Apr 18, 2024

Rebooting HA with read only set true in Pvop config runs, but setting read only false gives error

error.log
main.log
pv_opt.log

@ElectricMolehill
Copy link
Author

I've updated my sunsynk document to include some new information such as

@fboundy
Copy link
Owner

fboundy commented Apr 27, 2024

Been tied up with other things but will hopefully get back on this next week

@ElectricMolehill
Copy link
Author

I've had pv_opt running in read only mode for a couple of weeks now without error. I don't always understand the plan it produces but that is probably because I don't understand the algorithm. Solarsynk is also running reliably now since the CA cert check was removed

@fboundy
Copy link
Owner

fboundy commented Apr 30, 2024 via email

@ElectricMolehill
Copy link
Author

pv_opt.log

@alz41
Copy link

alz41 commented May 1, 2024

reboot HA
First load logs
error.log
main.log
pv_opt.log

change ev charge to none @ 17:34
error.log
main.log
pv_opt.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inverter support Support for new hardware
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants