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

reesaroo: v112-inverter-codes #218

Open reesaroo74 opened 7 months ago

reesaroo74 commented 7 months ago

Latest codes from Communication Protocol of Residential Hybrid Inverter v1.1.2 document

mkaiser commented 7 months ago

Looks good!

Reviewing this makes me think, if the (default=0) statements are really required? I guess we can leave them. What do you think?

reesaroo74 commented 7 months ago

Looks good!

Reviewing this makes me think, if the (default=0) statements are really required? I guess we can leave them. What do you think?

Good call. I think the availability catches the old default case, and now 0 is a valid running state.

mkaiser commented 7 months ago

hey,

the | int(default=0) re-appeared after you last commits. Was this on purpose?

reesaroo74 commented 7 months ago

Martin, I was testing this on my units, and without that, they were appearing offline ... which then had knock ons for the other sensors and sets. Putting it back in, and I was able to operate my automations via the sets again. Do you think it is a bit of a hack that now we are handling Running=0. I am getting errors intermittently when I use a modbus sniffer on that port (which would return that sensor as unavailable)

mkaiser commented 6 months ago

sorry for the late response .... pre-christmas workload....

I have been running this for some time now without any issues:

      - name: Sungrow inverter state
        unique_id: sg_inverter_state
        device_class: enum
        availability: "{{ not is_state('sensor.system_state', 'unavailable') }}"
        state: >-
          {% if ((states('sensor.system_state') |int) in [0x0000,0x0040]) %}
            Running
          {% elif ((states('sensor.system_state') |int) == 0x0410) %}
            Off-grid Charge
          {% elif ((states('sensor.system_state') |int) == 0x0200) %}
            Update Failed
          {% elif ((states('sensor.system_state') |int) == 0x0400) %}
            Maintain mode
          {% elif ((states('sensor.system_state') |int) == 0x0800) %}
            Forced mode
          {% elif ((states('sensor.system_state') |int) == 0x1000) %}
            Off-grid mode
          {% elif ((states('sensor.system_state') |int) == 0x1111) %}
            Un-Initialized
          {% elif ((states('sensor.system_state') |int) in [0x0010,0x12000]) %}
            Initial Standby
          {% elif ((states('sensor.system_state') |int) in [0x1300,0x0002]) %}
            Shutdown
          {% elif ((states('sensor.system_state') |int) in [0x1400,0x0008] ) %}
            Standby
          {% elif ((states('sensor.system_state') |int) in [0x1500,0x0004] ) %}
            Emergency Stop
          {% elif ((states('sensor.system_state') |int) in [0x1600,0x0020]) %}
            Startup
          {% elif ((states('sensor.system_state') |int) == 0x1700) %}
            AFCI self test shutdown
          {% elif ((states('sensor.system_state') |int) == 0x1800) %}
            Intelligent Station Building Status
          {% elif ((states('sensor.system_state') |int) == 0x1900) %}
            Safe Mode
          {% elif ((states('sensor.system_state') |int) == 0x2000) %}
            Open Loop
          {% elif ((states('sensor.system_state') |int) == 0x2501) %}
            Restarting
          {% elif ((states('sensor.system_state') |int) == 0x4000) %}
            External EMS mode
          {% elif ((states('sensor.system_state') |int) == in [0x55000,0x0100]) %}
            Fault
          {% elif ((states('sensor.system_state') |int) == in [0x8000,0x0001]) %}
            Stop
          {% elif ((states('sensor.system_state') |int) == 0x8100) %}
            De-rating Running
          {% elif ((states('sensor.system_state') |int) == 0x8200) %}
            Dispatch Run
          {% elif ((states('sensor.system_state') |int) == 0x9100) %}
            Warn Running
          {% else %}
            Unknown - should not see me! {{ (states('sensor.system_state') |int) }}
          {% endif %}

I cannot exactly comprehend your answer.

if sensor.system_state is not available, all derived enum names are also unavailable availability: "{{ not is_state('sensor.system_state', 'unavailable') }}"

if there are some modbus errors (but no modbus failures), a value of 0 could be returned for the system_state by the underlying modbus python implementation. In this case the enum would be decoded to "running". So there is should not be any reason to use the |default filter any more.

more on | default here: https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.default

Can we dig some more into the reason your sensors were marked unavailable / offline?

reesaroo74 commented 6 months ago

Martin, I agree. Let's leave this unmerged until I get a chance to investigate some more. I suspect it is my SH10RS that was doing something strange. I'm also under the pump with a looming code complete at work, so won't get a chance to look at this until next week at the earliest.

Paul

reesaroo74 commented 6 months ago

@mkaiser I'm still testing this. I have been getting a few glitches with both of my units when it comes out of feed limit mode. I'm doing some more testing.

mkaiser commented 5 months ago

any updates? I would like to merge, as it runs smooth on my side.

Can you post a screenshot of the glitches?

albertofralbe commented 1 month ago

Is v1.1.2 implemented now?