kellerza / sunsynk

Deye/Sunsynk Inverter Python library and Home Assistant OS Addon
https://kellerza.github.io/sunsynk/
MIT License
206 stars 88 forks source link

The Grid Connected sensor unknown state after HA restart #182

Closed ech0-py closed 1 year ago

ech0-py commented 1 year ago

You Inverter

Deye 8kw 1phase (SG01 generation)

Addon

Sunsynk/Deye Inverter Add-on (multi) Current version: 0.5.9

Addon configuration... ```yaml DRIVER: umodbus INVERTERS: - SERIAL_NR: "" HA_PREFIX: DY MODBUS_ID: 1 PORT: tcp://homeassistant.local:502 SENSOR_DEFINITIONS: single-phase SENSORS: - total_pv_energy - total_battery_charge - total_battery_discharge - total_grid_export - total_grid_import - load_Limit - control_mode - switch_power_on_off - pv1_power - pv2_power - essential_power - battery_power - battery_soc - non_essential_power - grid_ct_power - use_timer - priority_load - grid_voltage - grid_frequency - inverter_current - inverter_power - grid_connected - overall_state - fault - day_battery_charge - day_battery_discharge - battery_voltage - battery_charging_voltage - battery_float_voltage - battery_absorption_voltage - battery_equalization_voltage - battery_current - grid_power - day_grid_import - day_grid_export - day_load_energy - aux_power - day_pv_energy - pv1_voltage - pv1_current - pv2_voltage - pv2_current - radiator_temperature - dc_transformer_temperature - serial - device_type - comm_protocol_version - fw_control_board - fw_comm_board SENSORS_FIRST_INVERTER: [] MANUFACTURER: Sunsynk READ_ALLOW_GAP: 5 READ_SENSORS_BATCH_SIZE: 20 SCHEDULES: - KEY: grid_connected READ_EVERY: 5 REPORT_EVERY: 5 CHANGE_ANY: true - KEY: °C READ_EVERY: 5 REPORT_EVERY: 10 CHANGE_ANY: true - KEY: W READ_EVERY: 5 REPORT_EVERY: 5 CHANGE_ANY: false CHANGE_BY: 80 CHANGE_PERCENT: 0 - KEY: rw READ_EVERY: 15 REPORT_EVERY: 300 CHANGE_ANY: true CHANGE_BY: 0 CHANGE_PERCENT: 0 NUMBER_ENTITY_MODE: box MQTT_HOST: core-mosquitto MQTT_PORT: 1883 MQTT_USERNAME: MQTT_PASSWORD: DEBUG: 0 DEBUG_DEVICE: /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AQ0259H2-if00-port0 ```

Describe the issue/bug and what you expect

After one of the recent updates (not sure which one) the Grid Connected sensor goes to the "unknown" state after HA restart, while mqtt-explorer shows that sensor is present and availability topic is present. Reloading of MQTT integration do nothing, restarting of sunsynk addon helps to resolve the issue.

Not sure where I can see what's going wrong

Logs (if applicable)


07:54:39 INFO    Schedules:
+----------------+-----+------+--------+-----------+----------+------------+
|      Key       | src | Read | Report | Change by | Change % | Change any |
+----------------+-----+------+--------+-----------+----------+------------+
|   date_time    |     |  60  |   60   |           |          |    True    |
|       rw       |  *  |  15  |  300   |           |          |    True    |
|       w        |  *  |  5   |   5    |     80    |          |            |
|      kwh       |     | 300  |  300   |           |          |            |
|    any_unit    |     |  15  |  300   |           |          |            |
|    no_unit     |     |  15  |  300   |           |          |    True    |
| grid_connected |  +  |  5   |   5    |           |          |    True    |
|       °c       |  +  |  5   |   10   |           |          |    True    |
+----------------+-----+------+--------+-----------+----------+------------+
homeassistant/binary_sensor/2301132069/grid_connected

{"unique_id": "2301132069_grid_connected", "device": {"identifiers": ["2301132069"], "manufacturer": "Sunsynk", "model": "8kW Inverter (**2069)", "name": "DY"}, "state_topic": "SUNSYNK/status/2301132069/grid_connected", "name": "Grid Connected", "availability": [{"topic": "SUNSYNK/status/2301132069/availability"}], "object_id": "dy_grid_connected"}

chrome_9qmL69od4n

chrome_PqUAIbOKng

kellerza commented 1 year ago

My guess would be this has to do with the MQTT retain Retain flag

What this means is that your MQTT explorer was open when the message was received on MQTT, but it's not kept on the server. If you restart MQTT explorer you will see the same result as you see with restarting HASS. The value will not exist (Unknown)

The value needs to be reported again. In theory no_unit should be reported every 5 min... not sure why the HASS state mentions 6 min unknown, since there should have been a 5min in that 6min (they will not be synced)

ech0-py commented 1 year ago

But I have configured schedule to report every 5sec (full addon config I've added to the Addon configuration... expand section, that not obvious I guess), thus I though everything should be ok, but it's not. Addon does really report grid_connected = 1 every 5 seconds, I see it in mqtt explorer as well

SCHEDULES:
  - KEY: grid_connected
    READ_EVERY: 5
    REPORT_EVERY: 5
    CHANGE_ANY: true

I made another longer test to show that even mosquitto restart doesn't help and entity was in unknown state for more than 20 minutes long l

kellerza commented 1 year ago

Mosquitto restart won't help. Probably only the addon restart

Can you try setting change_any to false? or removing it from the schedule?

ech0-py commented 1 year ago

Still the same in both cases:

Sure, only the addon restart helps

N1c084 commented 1 year ago

Same for me. But just change the grid state in real from on to off and the state of entity appear clearly now.

Le mar. 12 sept. 2023 à 08:04, ech0-py @.***> a écrit :

Still the same in both cases:

  • change_any: false (or remove the grid_connected from the schedule)
  • restart HA
  • sensor becomes unknown
  • wait for 5+ minutes until every other sensor get value
  • sensor is still unknown

Sure, only the addon restart helps

— Reply to this email directly, view it on GitHub https://github.com/kellerza/sunsynk/issues/182#issuecomment-1715041883, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYDJ6M4UJWP6763IQFSRONDXZ73NLANCNFSM6AAAAAA4SAIKXI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

kellerza commented 1 year ago

I've added a possible fix in the edge branch, only unit tested for now

ech0-py commented 1 year ago

But just change the grid state in real from on to off and the state of entity appear clearly now.

I can confirm. If in unknown state I turn off the inverter and then turn on it the entity changes the state accordingly

kellerza commented 1 year ago

For some reason the BinarySensor required an actual change (by any means) to work. This sensors is the only Binary Sensor today.

We have so much load-shedding in South Africa I probably would have never picked up this bug 🤣

ech0-py commented 1 year ago

I confirm that on the edge everything now works as expected From my perspective, what's changed:

I appreciate your efforts, sir, god bless you <3

N1c084 commented 1 year ago

🤣in France very rare grid outage . But I force every day my inverter to go off -on grid depending of battery soc, so I see the unknow to ok value when the state change appear. Binary start at first change

Le mar. 12 sept. 2023 à 09:06, Johann Kellerman @.***> a écrit :

For some reason the BinarySensor required an actual change (by any means) to work. This sensors is the only Binary Sensor today.

We have so much load-shedding in South Africa I probably would have never picked up this bug 🤣

— Reply to this email directly, view it on GitHub https://github.com/kellerza/sunsynk/issues/182#issuecomment-1715121791, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYDJ6MYNGE4OZEF6ALXKJPDX2ACWPANCNFSM6AAAAAA4SAIKXI . You are receiving this because you commented.Message ID: @.***>

ech0-py commented 1 year ago

But I force every day my inverter to go off -on grid depending of battery soc

Unfortunately in Ukraine we have a lot of outages during last year =\ Sorry I know this is off topic, but can you describe how you achieve that? Is that manual way (turn off the breaker by hands), automatic (smart zigbee/wifi relay/breaker) or mb even some kind of software (writing to the modbus registry, for example). I'm trying found ways to achieve low energy consumption from the grid/battery during the night

N1c084 commented 1 year ago

Just change minimum frequency to a value outage your grid For example 50Hz grid

min frequency set to 52Hz and then inverter go alone to off grid by opening the internal grid input relay

Le mar. 12 sept. 2023 à 10:56, ech0-py @.***> a écrit :

But I force every day my inverter to go off -on grid depending of battery soc

Sorry I know this is off topic, but can you describe how you achieve that? Is that manual way (turn off the breaker by hands), automatic (smart zigbee/wifi relay/breaker) or mb even some kind of software (writing to the modbus registry, for example). I'm trying found ways to achieve low energy consumption from the grid/battery during the night

— Reply to this email directly, view it on GitHub https://github.com/kellerza/sunsynk/issues/182#issuecomment-1715300671, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYDJ6M3PUK4PTEDIAERMSILX2APUFANCNFSM6AAAAAA4SAIKXI . You are receiving this because you commented.Message ID: @.***>