mkaiser / Sungrow-SHx-Inverter-Modbus-Home-Assistant

Sungrow SH Integration for Home Assistant for SH3K6, SH4K6, SH5K-20, SH5K-V13, SH3K6-30, SH4K6-30, SH5K-30, SH3.RS, SH3.6RS, SH4.0RS, SH5.0RS, SH6.0RS, SH5.0RT, SH6.0RT, SH8.0RT, SH10RT, SH5.0RT-20, SH6.0RT-20, SH8.0RT-20, SH10RT-20, SH5.0RT-V112, SH6.0RT-V112, SH8.0RT-V112, SH10RT-V112, SH5.0RT-V122, SH6.0RT-V122, SH8.0RT-V122, SH10RT-V122, SH4.6R
325 stars 83 forks source link

Configure the inverter #11

Closed lindehoff closed 1 year ago

lindehoff commented 2 years ago

Hi, First of all, thank you so much for this, I just got an SH8.0RT and this integration is awesome.

I have a feature request, is it possible to set parameters over Modbus? If so it would be great if we could set parameters like:

mkaiser commented 2 years ago

thanks ;)

I just figured out to write to modbus holding registers, so this will be definitivly do-able for me in the future

For sure I can make some kind of a selector to change the battery management mode between "force charge / discharge / auto".

I am currently not sure how to map the timing-related modbus functions available to a usable-Homeassistant UI. What do you expect for a time scheduled operation?

lindehoff commented 2 years ago

This sounds great. I have a couple of scenarios when I want to "force" the invert to different operational modes:

  1. When electricity is very cheap I want to force change the battery form the grid
  2. When I'm charging my EV I want to tell the inverter not to drain the battery, no-discharge
  3. When grid electricity is very cheap I want to tell the inverter not to use the battery, same as above (no-discharge)
  4. When I can sell at a high price I want to tell the inverter to not change the battery (Not sure this is possible)

So I don't need to have to set specific time/date/schedule, that can be done in Home assistant. Instead we only need to be able to tell the inverter:

If we have these the we can use home assistant to build the "smartness"

mkaiser commented 2 years ago

committed here in branch "testing": https://github.com/mkaiser/Sungrow-SHx-Inverter-Modbus-Home-Assistant/tree/testing

currently it is more a proof-of concept. I was able to force charge / discharge. Will push in to main branch, if someone can confirm it to be working.

To activate a "force battery charge", look at the "EMS" section of the dashboard (right side) and configure the red-circled entries image

There are still some issues, please let me know, if you have anyone has suggestions:

~Martin

lindehoff commented 2 years ago

Looks very promising, I have don som small tests and everything seams to work. We can calculate the battery kWh capacity with Holding registry 13057, like so:

      - name: Battery capacity Ah
        slave: !secret sungrow_modbus_slave
        address: 13056
        input_type: holding
        count: 1
        scan_interval: 600
        data_type: uint16
        swap: word
        precision: 0
        unit_of_measurement: "Ah"
        device_class: energy
        state_class: total_increasing
        scale: 1

And the create a template sensor:

      sungrow_battery_capacity_kwh:
        friendly_name: "Battery capacity kWh"
        unit_of_measurement: kWh
        device_class: energy
        value_template: >-
          {{ ((states('sensor.battery_capacity_ah') | int(default=0) / 1000 * 240) / 1000) | round(1) }} 
mkaiser commented 2 years ago

totally missed the other battery capacity register in sungrows register map. The datasheet does not meantion the sh10 support for register 13058.... I just requested an updated protokoll description from sungrow. Maybe they have updates, bringing more light into this :)

In your emplate you used the factor 240. Does this correspond to your current battery voltage?

lindehoff commented 2 years ago

It works for my SH8.0RT so I would imagine it works for SH10.0RT. The 240 factor is the voltage going from the battery and in my house its around 230-250. So I get 15.7 kWh and the battery should be 16 kWh so close enough.

bjeanes commented 2 years ago

I just requested an updated protokoll description from sungrow

TI_20211231_Communication Protocol of Residential Hybrid Inverter_V1.0.23_EN.pdf

Here is 1.0.23, which is at least newer than the one mentioned in README, but may not be latest. I am also waiting to hear back from SunGrow on latest version.

bjeanes commented 2 years ago
  • I don't know how to use hexadecimal values in the writeModbus routines.

Wrap the hex in template braces, like {{ 0xaa }} to force Python to evaluate it to a number:

Screen Shot 2022-07-27 at 1 40 44 pm
Svanmark commented 2 years ago

Hi, nice work! I was just testing forced charging using the integration from testing branch. It seems to work well with SH10.0RT. Following the progress.

Bullischorsch commented 2 years ago

committed here in branch "testing": https://github.com/mkaiser/Sungrow-SHx-Inverter-Modbus-Home-Assistant/tree/testing

Hi, thanks a lot for your work! I use your code since some months and now see this expansion. Unfortunately is doesn't work for me. The new entities under EMS are not available, the older ones are still there. Do I have to reload something? Or has the inverter to be in a special mode? Currently it is in "Netzunabhängiger Modus".

Georg

Bullischorsch commented 2 years ago

committed here in branch "testing": https://github.com/mkaiser/Sungrow-SHx-Inverter-Modbus-Home-Assistant/tree/testing

Hi, thanks a lot for your work! I use your code since some months and now see this expansion. Unfortunately is doesn't work for me. The new entities under EMS are not available, the older ones are still there. Do I have to reload something? Or has the inverter to be in a special mode? Currently it is in "Netzunabhängiger Modus".

Georg

Solved this issue. I renamed the config file in the integrations subdir and restarted HA, afterwards the new configured items where loaded. Seem to be some caching thing.

FlyHigh-Swe commented 2 years ago

Looks very promising, I have don som small tests and everything seams to work. We can calculate the battery kWh capacity with Holding registry 13057, like so:

I am not sure if I am doing something wrong here or misunderstood something. When I read register 13057 (13056 in the code) I get the value 65535 and when I apply the same calculation (Ah to kWh) I also get 15.6 but my battery is actually 9,6Kwh.

I also have the SH8RT but suspect I get an error code when reading the registry. I am using a modbus addon in node red to test this but all other values return the same values as this integration so I doubt that the issue is in Node Red.

FlyHigh-Swe commented 2 years ago

committed here in branch "testing": https://github.com/mkaiser/Sungrow-SHx-Inverter-Modbus-Home-Assistant/tree/testing

currently it is more a proof-of concept. I was able to force charge / discharge. Will push in to main branch, if someone can confirm it to be working.

Its working very good for me also using a SH08RT. The automation to change to forced mode etc works excellent from the dashboard. And thank you for developing this awesome integration!

(I am actually using node red for writing Modbus data at the moment since all other automations is there but I would never have understood how to do it if it wasn't for your code!)

mkaiser commented 1 year ago
  • I don't know how to use hexadecimal values in the writeModbus routines.

Wrap the hex in template braces, like {{ 0xaa }} to force Python to evaluate it to a number:

thanks! That was really helpful - incorporated that in the last commit :)

mkaiser commented 1 year ago

hmm

still cannot figure out, why I can't read the two registers

  - name: Battery type
    slave: !secret sungrow_modbus_slave
    address: 13054 # 13055
    input_type: holding
    count: 1
    data_type: uint16
    swap: word
    precision: 0
    scan_interval: 60

and

result is always 65535 on my SH10.RT

any ideas?

bjeanes commented 1 year ago

@mkaiser that register is not used/available on the SH#RS/RT inverters. It only applies to the SH#K inverters, like SH3K6, etc

See https://www.photovoltaikforum.com/core/attachment/235914-ti-20211231-communication-protocol-of-residential-hybrid-inverter-v1-0-23-en-pdf/ to lookup that register address (13057, it's 13056 here because the protocol address is -1 from the documented address in all cases)

mkaiser commented 1 year ago

bjeanes, you are right with the not supported registers :)

hopefully my inner confusion just ended...

@ FlyHigh-Swe

your SH8RT has also no support for the register 13057 (like my SH10RT).

So it is expected, that the register read will return 0xFFFF / 65535.

Therefore the equation ('sensor.battery_capacity_ah') | int(default=0) / 1000 * 240) / 1000) | round(1) }}

will always return 15,7284 (65535 / 1000 *240 /1000)

mkaiser commented 1 year ago

new update in testing branch

@FlyHigh-Swe, @lindehoff : added (secret / hidden / reverse engineered) register for the battery capacity - no need for a template any more :)

I guess all requests in this issue are satisfied - please open a new one, if I missed something :)

brief changelog

mkaiser commented 1 year ago

closing issue. Battery capacity for non SH10RT is still an issue, but that should be in another thread