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
304 stars 79 forks source link

Load 1 ON/OFF Mode Switch for the DO-port holding register 130011 or more complex DO-Configuration and Load Control Mode by using registers 13001-13016 #271

Closed tttooommmeeekkk closed 3 months ago

tttooommmeeekkk commented 3 months ago

Is your feature request related to a problem? Please describe. I actually can not switch the inverters DO relay ("ON/OFF" or "closed/opened") without logging into the built-in webinterface. In some cases I can not reach the local webinterface and make any changes (webinterface seems to be overloaded). HA-Modbus-control seem work anyway and the communication to/with the inverter seems to be more stable and reliable. So a HA-integrated switch would be a kind and reliable solution for switching the DO-Port in situations I would like to (and reduce the dependence of working inverter-webinterface). I already wrote some code to my local modbus_sungrow.yaml that reads the holding-register 13011 (Load-Control-Mode 1 ON/OFF). Here are my existing code-snippets:

- name: Inverter DO Relais an aus raw
        unique_id: sg_inverter_do_relais_an_aus_raw
        device_address: !secret sungrow_modbus_slave
        address: 13010 # reg 13011
        input_type: holding
        data_type: uint16
        precision: 0
        state_class: measurement
        scan_interval: 31
- name: Inverter DO Relais an aus
        unique_id: sg_inverter_do_relais_an_aus
        availability: "{{ not is_state('sensor.inverter_do_relais_an_aus_raw', 'unavailable') }}"
        # TODO: test state_class with enum
        # state_class: measurement
        device_class: enum
        state: >-
          {% if ((states('sensor.inverter_do_relais_an_aus_raw') | int(default=0)) == 0x00AA) %}
            {# AN - Relais ist geschlossen #}
            Geschlossen
          {% elif ((states('sensor.inverter_do_relais_an_aus_raw') | int(default=0))  == 0x0055) %} 
            {# AUS - Relais ist offen #}
            Offen
          {% else %}
            Unknown - should not see me!
          {% endif %}
        icon: >-
          {% if is_state("sensor.inverter_do_relais_an_aus", "Offen") %}
            mdi:electric-switch
          {% elif is_state("sensor.inverter_do_relais_an_aus", "Geschlossen") %}
            mdi:electric-switch-closed
          {% else %}
            mdi:help-circle-outline
          {% endif %}

It would be nice to have the DO-port of the inverter be switchable by HA, so that one can manually switch the el. relays (without logging into the inverters local webbrowser): for example to activate the heatpumps "instant-hot-water-program" that is connected to that DO-Port (when there is PV-surplus).

Describe the solution you'd like The DO relay should become closed/ON when it gets state 0xAA (decimal: 170) and become opened/OFF when it gets state 0x55 (decimal: 85).

Describe alternatives you've considered A) No support of such an switch. or B) A more complex programming for the whole DO-Configuration (Holding Registers 13001 - 13016).

Additional context The DO-switch-position seems only to be shown by manually switching the register 13011 (as I actually do it by using the inverters webinterface). If the DO-port-configuration (h-register 13001) is set to "1: Load Control Mode" AND the Load Control Mode (h-register 13002) is set to "2: Power optimized mode" (for using PV-surplus with set h-registers 13012-13016) the register 13011 gets no change in status (maybe there is another readonly?-register for a state of a closed/opened DO-Port when using "2. Power optimized mode") .

tttooommmeeekkk commented 3 months ago

Found the workaround/extension here:

122

elektrinis commented 2 months ago

Have you managed to do a normal control of DO port? Do I understand this correctly, that I need to:

  1. Set #13001 to Load control mode
  2. Set #13002 to ON/OFF mode
  3. Set #13011 to 0xAA to ON and 0x55 to OFF?

Is this all, or anything else is needed?

tttooommmeeekkk commented 2 months ago

Yes. The extension done by dl1ekm works as expected (for me with the mentiomed annotations in the discussion-section of his project. But you can also set the register 13011 without a changing the other 2. However I do not know, what happens, when register 13002 is set to e.g. "power optimized mode" and switches the DO and you overrides this by setting register 13011 it seems the best way to do it, as you wrote (set all 3 registers).