bohdan-s / SunGather

GNU General Public License v3.0
148 stars 61 forks source link

Support for SG8K-D Inverter #8

Closed rianbk closed 2 years ago

rianbk commented 2 years ago

Hey,

Firstly thanks for this, been working on something like this personally but found yours on whirlpool. The script seems to be working in some capacity but I don't think you directly support this model.

Traceback (most recent call last):
File "/usr/local/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.10/threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "/usr/src/sungather/exports/mqtt.py", line 38, in publish
self.sensor_topic = self.sensor_topic.replace('{model}', inverter.get('device_type_code', 'unknown').replace('.',''))
AttributeError: 'int' object has no attribute 'replace'
Exception in thread Thread-72 (publish):

I have sent a request to sungrowpower for the modbus register

daloser commented 2 years ago

Can you double check the IP for the MQTT server is correct? If you are using the Mosquito one built into HA then it will be same IP as HA.

fast reply ever haha :) thanks for having a look. Yes IP address in config file for MQTT is correct for HA/MQTT server (using mosquito built into HA with default ports too)

bohdan-s commented 2 years ago

Can you try restarting HA Host? Maybe a MQTT client ID conflict. Easiest way is to restart the MQTT component (or whole host). I'll add some code to check for this and change client in next build.

daloser commented 2 years ago

Restarted a few times, also reinstalled the MQTT addon just incase - still no luck. I am getting MQTT hits in the log it seems, but no devics and or entities under the MQTT Integrations

Mosquitto broker log: 1642324204: New connection from 192.168.1.211 on port 1883. 1642324204: New client connected from 192.168.1.211 as pv_data (p2, c1, k60). 1642324236: Socket error on client pv_data, disconnecting. 1642324236: New connection from 192.168.1.211 on port 1883. 1642324236: New client connected from 192.168.1.211 as pv_data (p2, c1, k60). 1642324268: Socket error on client pv_data, disconnecting. 1642324268: New connection from 192.168.1.211 on port 1883. 1642324268: New client connected from 192.168.1.211 as pv_data (p2, c1, k60). 1642324299: Socket error on client pv_data, disconnecting. 1642324299: New connection from 192.168.1.211 on port 1883. 1642324299: New client connected from 192.168.1.211 as pv_data (p2, c1, k60).

bohdan-s commented 2 years ago

Hmmmm I got those same errors during testing as well. But stopping SunGather, restarting MQTT and then starting SunGather resolved the error and I couldn't reproduce it again. I'll have a look at it tomorrow and see if I can find the source.

bohdan-s commented 2 years ago

@daloser Just pushed 0.2.3 with some improved code to detect if exports are failing. Can you confirm the IP and Port in the config match the log (of it fails again)?

daloser commented 2 years ago

I have updated and reconfig - and no error in the console; and seems to be reporting to MQTT broker; but im not getting any devices detected, so maybe an issue for me there. mqtt addon log: 1642378160: New client connected from 192.168.1.211 as SunGather (p2, c1, k60).

If I stop Mosquitto broker - i get error in the log; so the error report is working: 2022-01-17 10:42:29 ERROR MQTT: Connection 192.168.1.201:1883 2022-01-17 10:42:29 ERROR MQTT: Error: [Errno 111] Connection refused

Maybe something is wrong in my broker setup, not sure what as its all default. I'll have to have a think about it.

Thanks for the update

rianbk commented 2 years ago

I've been getting funny exports to pvoutput, no generation is getting calculated on the graphs properly image I'll try updating and restarting.

rianbk commented 2 years ago

I also can see it publishing MQTT, seems to be updating the topic fine, but homeassistant isn't discovering the inverter.

rianbk commented 2 years ago

@bohdan-s i've commented out the internal tempreture, but it seem we are potentially exported a value of 0 (the orange line on the graph) instead of sending nothing. image

dbonnell commented 2 years ago

@bohdan-s i've commented out the internal tempreture, but it seem we are potentially exported a value of 0 (the orange line on the graph) instead of sending nothing.

@rianbk Did you also comment out the v5 parameter for inverter_temperature in the parameters section of pvoutput in config.yaml?

Also, I'm not entirely sure what "temperature" v5 should be - inverter or ambient. I assumed it was inverter and have been logging that for ages but the pvoutput API docs are unclear. I can see those values in pvoutput when looking at a single day and up until Jan 14, when looking a level up, it was showing what looks like the ambient temperature in the Temperature column, but is now showing the logged (inverter) temperature (v5). So perhaps v5 is supposed to be ambient temperature and if not provided, it looks it up from the weather service based on your location?

After a bit of Googling I found a discussion on calculating insolation and it looks like the temperature uploaded to v5 is used for insolation derating, so it should be the ambient temperature if you have it, and definitely not the inverter temperature. I'm going to remove v5 from my configuration.

image

dbonnell commented 2 years ago

@bohdan-s Two typos in sungather.py, line# 139. Should be "Inverter" and "scraped".

logging.info(f'Inventer: Successfully scrapped in ...')

Also config-example.yaml, line#11

# use_local_time: False                   # [Optional] Default False, Uses Inventer time, ...
bohdan-s commented 2 years ago

You are all to quick for me! @dbonnell fixed :) @rianbk I have pushed 0.2.4. You are correct, i was cheating and sending '0' instead of no value. This was causing issues. I have now set it, so you if you send v2 and v4 then it will calculate correctly, It was missing the "net data" flag. It will now not send a 0 if there is no setting for it in the config.yaml.

rianbk commented 2 years ago

You are all to quick for me! @dbonnell fixed :) @rianbk I have pushed 0.2.4. You are correct, i was cheating and sending '0' instead of no value. This was causing issues. I have now set it, so you if you send v2 and v4 then it will calculate correctly, It was missing the "net data" flag. It will now not send a 0 if there is no setting for it in the config.yaml.

Shall update and test :)

dbonnell commented 2 years ago

@bohdan-s pvoutput is also no longer working for me. Console output says it is logging to pvoutput but the last data I have in pvoutput is Jan 14.

2022-01-17 13:54:55 INFO     PVOutput: Data uploaded
bohdan-s commented 2 years ago

@dbonnell for the temperature, do you have a link to that discussion? I can not find anything about what temp it should be?

PVOutput only updates every 5 minutes, so need to wait :) its very annoying when testing

dbonnell commented 2 years ago

@dbonnell for the temperature, do you have a link to that discussion? I can not find anything about what temp it should be?

PVOutput only updates every 5 minutes, so need to wait :) its very annoying when testing

Yeah, I can see data again now. Thanks.

Here's that post that discussed the use of v5 in pvoutput

https://forum.pvoutput.org/t/what-temperature-is-used-to-calculate-insolation/2106

bohdan-s commented 2 years ago

@dbonnell thanks, I'll add the forum link to the config-example and comment it out by default.

bohdan-s commented 2 years ago

@daloser the MQTT update should fix HA. I had to remove the device in HA and restart SunGather for it to re-create with the correct data.

daloser commented 2 years ago

@daloser the MQTT update should fix HA. I had to remove the device in HA and restart SunGather for it to re-create with the correct data.

THanks - ill update and retest shortly. Thanks for the fast support and edits :) 👍

rianbk commented 2 years ago

@bohdan-s I seem to be getting a interesting results on pvoutput. I've deleted the data from the day. On the first push i get all the data since the container has been running, then the second push i loose the power data image image log.txt

I also still cant get it to re-register with HA :(

bohdan-s commented 2 years ago

@rianbk I was just looking at my PVOutput and thinking the same, I think its because I have set the Net Data flag on (which we need) something funny is happening with the days data. I also notice it is pushing the power/energy to 2 decimal places which might be messing it up as well. Just pushed 0.2.5 that fixes the decimal places, looks like data is correct now for me, it takes a while to update

bohdan-s commented 2 years ago

As for HA, do you see it under Config > devices > devices > Solar Inverter?

rianbk commented 2 years ago

As for HA, do you see it under Config > devices > devices > Solar Inverter?

I deleted it a few versions back (when topics where getting renamed) and its never discovered again since (its not there)

bohdan-s commented 2 years ago

My fault, i pushed a old version of the config-example. Sorry I have updated it now, MQTT section should look like this (notice the HA_Discovery and HA_Topics name changes):

  - name: mqtt
    enabled: True                           # [Optional] Default is False
    host: 192.168.1.50                      # [Required] IP or Hostname of MQTT Server 
    # port: 1883                            # [Optional] Default 1883
    # topic: "inverter/{model}/registers"   # [Optional] Default: "inverter/{model}/registers", Variable {model} will be replaced with model number of inverter
    # username:                             # [Optional] Username is MQTT server requires it
    # password:                             # [Optional] Password is MQTT server requires it
    homeassistant: True                     # [Optional] Default False, Publish discovery and sensors for HomeAssistant
    ha_sensors:                             # [Optional] / [Required] ha_discovery: True, Topics to enable discovery for HA
      - name: "Daily Generation"
        sensor_type: sensor
        register: daily_power_yields
        unit: kWh
        dev_class: energy
        state_class: total_increasing
      - name: "Active Power"
        sensor_type: sensor
        register: total_active_power
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Load Power"
        sensor_type: sensor
        register: load_power
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Meter Power"
        sensor_type: sensor
        register: meter_power
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Export to Grid"
        sensor_type: sensor
        register: export_to_grid
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Import from Grid"
        sensor_type: sensor
        register: import_from_grid
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Temperature"
        sensor_type: sensor
        register: internal_temperature
        unit: °C
        dev_class: temperature
        state_class: measurement
      - name: "Power State"
        sensor_type: binary_sensor
        register: run_state
        dev_class: running
        payload_on: "ON"
        payload_off: "OFF"
rianbk commented 2 years ago

My fault, i pushed a old version of the config-example. Sorry I have updated it now, MQTT section should look like this (notice the HA_Discovery and HA_Topics name changes):

  - name: mqtt
    enabled: True                           # [Optional] Default is False
    host: 192.168.1.50                      # [Required] IP or Hostname of MQTT Server 
    # port: 1883                            # [Optional] Default 1883
    # topic: "inverter/{model}/registers"   # [Optional] Default: "inverter/{model}/registers", Variable {model} will be replaced with model number of inverter
    # username:                             # [Optional] Username is MQTT server requires it
    # password:                             # [Optional] Password is MQTT server requires it
    homeassistant: True                     # [Optional] Default False, Publish discovery and sensors for HomeAssistant
    ha_sensors:                             # [Optional] / [Required] ha_discovery: True, Topics to enable discovery for HA
      - name: "Daily Generation"
        sensor_type: sensor
        register: daily_power_yields
        unit: kWh
        dev_class: energy
        state_class: total_increasing
      - name: "Active Power"
        sensor_type: sensor
        register: total_active_power
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Load Power"
        sensor_type: sensor
        register: load_power
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Meter Power"
        sensor_type: sensor
        register: meter_power
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Export to Grid"
        sensor_type: sensor
        register: export_to_grid
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Import from Grid"
        sensor_type: sensor
        register: import_from_grid
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Temperature"
        sensor_type: sensor
        register: internal_temperature
        unit: °C
        dev_class: temperature
        state_class: measurement
      - name: "Power State"
        sensor_type: binary_sensor
        register: run_state
        dev_class: running
        payload_on: "ON"
        payload_off: "OFF"

Might be worth having a version check in the config in case you update to version with outdated config syntax

rianbk commented 2 years ago

My fault, i pushed a old version of the config-example. Sorry I have updated it now, MQTT section should look like this (notice the HA_Discovery and HA_Topics name changes):

Updated to the latest config, now getting

2022-01-17 17:57:35 DEBUG MQTT: Publishing: inverter/SG8KD/registers : {"device_type_code": "SG8K-D", "run_state": "ON", "daily_power_yields": 61.4, "total_power_yields": 2626.9, "internal_temperature": 54.0, "phase_a_voltage": 240.8, "total_active_power": 321, "work_state_1": "Run", "daily_export_energy": 394, "total_export_energy": 36906, "daily_import_energy": 98, "total_import_energy": 9901, "daily_direct_energy_consumption": 220, "total_direct_energy_consumption": 54899, "start_stop": "Start", "export_to_grid": 0, "import_from_grid": 0, "timestamp": "2022-1-17 17:57:33"}
2022-01-17 17:57:35 WARNING PVOutput: v4 configured to use load_power but inverter is not returning this register

Exception in thread Thread-7 (publish):
2022-01-17 17:57:35 INFO MQTT: Published
Traceback (most recent call last):
File "/usr/local/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.10/threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "/usr/src/sungather/exports/pvoutput.py", line 88, in publish
self.collected_data[parameter.get('name')] = round(self.collected_data[parameter.get('name')] + inverter.get(parameter.get('register')),3)
KeyError: 'v4'
2022-01-17 17:57:35 DEBUG Processing Time: 1.499220 secs

Also just checking that i need to add ha_discovery: true

  # Publish Registers to MQTT / Home Assistant
  - name: mqtt
    enabled: True                         # [Optional] Default is False
    host: homeassistant                     # [Required] IP or Hostname of MQTT Server 
    # port: 1883                            # [Optional] Default 1883
    # topic: "inverter/{model}/registers"   # [Optional] Default: "inverter/{model}/registers", Variable {model} will be replaced with model number of inverter
    username: mqtt                             # [Optional] Username is MQTT server requires it
    password: mqtt                            # [Optional] Password is MQTT server requires it
    homeassistant: True                     # [Optional] Default False, Publish discovery and sensors for HomeAssistant
    ha_discovery: True
    ha_sensors:                             # [Optional] / [Required] ha_discovery: True, Topics to enable discovery for HA
      - name: "Daily Generation"
        sensor_type: sensor
        register: daily_power_yields
        unit: kWh
        dev_class: energy
        state_class: total_increasing
      - name: "Active Power"
        sensor_type: sensor
        register: total_active_power
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Load Power"
        sensor_type: sensor
        register: load_power
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Meter Power"
        sensor_type: sensor
        register: meter_power
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Export to Grid"
        sensor_type: sensor
        register: export_to_grid
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Import from Grid"
        sensor_type: sensor
        register: import_from_grid
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Temperature"
        sensor_type: sensor
        register: internal_temperature
        unit: °C
        dev_class: temperature
        state_class: measurement
      - name: "Power State"
        sensor_type: binary_sensor
        register: run_state
        dev_class: running
        payload_on: "ON"
        payload_off: "OFF"
daloser commented 2 years ago

Updated to 0.2.5; edited the new config file - all the changes match your example abloe. I am not getting any errors in the terminal; web server working and reporting stats but still no devices/sensors found in HA

bohdan-s commented 2 years ago

My fault, i pushed a old version of the config-example. Sorry I have updated it now, MQTT section should look like this (notice the HA_Discovery and HA_Topics name changes):

Updated to the latest config, now getting

2022-01-17 17:57:35 DEBUG MQTT: Publishing: inverter/SG8KD/registers : {"device_type_code": "SG8K-D", "run_state": "ON", "daily_power_yields": 61.4, "total_power_yields": 2626.9, "internal_temperature": 54.0, "phase_a_voltage": 240.8, "total_active_power": 321, "work_state_1": "Run", "daily_export_energy": 394, "total_export_energy": 36906, "daily_import_energy": 98, "total_import_energy": 9901, "daily_direct_energy_consumption": 220, "total_direct_energy_consumption": 54899, "start_stop": "Start", "export_to_grid": 0, "import_from_grid": 0, "timestamp": "2022-1-17 17:57:33"}
2022-01-17 17:57:35 WARNING PVOutput: v4 configured to use load_power but inverter is not returning this register

Exception in thread Thread-7 (publish):
2022-01-17 17:57:35 INFO MQTT: Published
Traceback (most recent call last):
File "/usr/local/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.10/threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "/usr/src/sungather/exports/pvoutput.py", line 88, in publish
self.collected_data[parameter.get('name')] = round(self.collected_data[parameter.get('name')] + inverter.get(parameter.get('register')),3)
KeyError: 'v4'
2022-01-17 17:57:35 DEBUG Processing Time: 1.499220 secs

Also just checking that i need to add ha_discovery: true

  # Publish Registers to MQTT / Home Assistant
  - name: mqtt
    enabled: True                         # [Optional] Default is False
    host: homeassistant                     # [Required] IP or Hostname of MQTT Server 
    # port: 1883                            # [Optional] Default 1883
    # topic: "inverter/{model}/registers"   # [Optional] Default: "inverter/{model}/registers", Variable {model} will be replaced with model number of inverter
    username: mqtt                             # [Optional] Username is MQTT server requires it
    password: mqtt                            # [Optional] Password is MQTT server requires it
    homeassistant: True                     # [Optional] Default False, Publish discovery and sensors for HomeAssistant
    ha_discovery: True
    ha_sensors:                             # [Optional] / [Required] ha_discovery: True, Topics to enable discovery for HA
      - name: "Daily Generation"
        sensor_type: sensor
        register: daily_power_yields
        unit: kWh
        dev_class: energy
        state_class: total_increasing
      - name: "Active Power"
        sensor_type: sensor
        register: total_active_power
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Load Power"
        sensor_type: sensor
        register: load_power
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Meter Power"
        sensor_type: sensor
        register: meter_power
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Export to Grid"
        sensor_type: sensor
        register: export_to_grid
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Import from Grid"
        sensor_type: sensor
        register: import_from_grid
        unit: W
        dev_class: power
        state_class: measurement
      - name: "Temperature"
        sensor_type: sensor
        register: internal_temperature
        unit: °C
        dev_class: temperature
        state_class: measurement
      - name: "Power State"
        sensor_type: binary_sensor
        register: run_state
        dev_class: running
        payload_on: "ON"
        payload_off: "OFF"

Can you try setting smart_meter: True in the inverter section?

bohdan-s commented 2 years ago

@daloser can you try Configuration > Devices > Mosquitto broker > Configure > Listen to a topic > homeassistant/sensor/inverter/daily_generation/config and see if it outputs anything when you start SunGather?

@rianbk I thought about a config version, but I really dont want to change it again going forward. I am hoping that (unless @rianbk , @dbonnell , @daloser have anything to add) that SunGather is feature complete, and Its just bug fixes.

0.2.6 fixes an issue with 0 values to PVOutput after it looses connectivity.

rianbk commented 2 years ago

Can you try setting smart_meter: True in the inverter section?

Whoops, missed that. All working now. I have also resolved my MQTT issue, turns out that was on my end with the HASS broker integration (all of my MQTT was broken)

rianbk commented 2 years ago

I'll keep this Issue open for now as we have kinda used it as a catch all. But when it looks like everyone is happy I will close it so new issues can be logged separately.

dbonnell commented 2 years ago

Exports failed this morning (SunGather 0.2.5). The console said the whole time it was successfully exporting to pvoutput but failed to export to MQTT. But there was just the single data point in pvoutput at 5:30AM and nothing at all in Grafana until after I restarted just now.

Here's an excerpt from the log from just prior to reconnecting to the inverter at 05:26:44AM and just before the restart at

2022-01-18 05:25:42 WARNING  No data returned for read, 5100:100
                                Modbus Error: [Connection] Failed to connect[ModbusTcpClient(11.11.11.1:502)]
2022-01-18 05:25:52 ERROR    Connection to (11.11.11.1, 502) failed: timed out
2022-01-18 05:25:52 WARNING  No data returned for hold, 4999:10
                                Modbus Error: [Connection] Failed to connect[ModbusTcpClient(11.11.11.1:502)]
2022-01-18 05:25:52 WARNING  Data collection failed, skipped exporting data. Retying in 30 secs
2022-01-18 05:26:22 INFO     Connection: ModbusTcpClient(11.11.11.1:502)
2022-01-18 05:26:32 ERROR    Connection to (11.11.11.1, 502) failed: timed out
2022-01-18 05:26:44 INFO     Inverter: Successfully scraped in 8.906520 secs
2022-01-18 05:26:44 INFO     MQTT: Published
2022-01-18 05:26:44 INFO     PVOutput: Data logged
2022-01-18 05:27:16 INFO     Inverter: Successfully scraped in 1.920390 secs
2022-01-18 05:27:16 ERROR    MQTT: Failed to publish with error: Message publish failed: The connection was lost.
2022-01-18 05:27:16 INFO     PVOutput: Data logged
2022-01-18 05:27:47 INFO     Inverter: Successfully scraped in 1.618416 secs
2022-01-18 05:27:47 ERROR    MQTT: Failed to publish with error: Message publish failed: The client is not currently connected.
...
2022-01-18 08:51:41 INFO     PVOutput: Data logged
2022-01-18 08:52:13 INFO     Inverter: Successfully scraped in 1.718037 secs
2022-01-18 08:52:13 ERROR    MQTT: Failed to publish with error: Message publish failed: The client is not currently connected.
2022-01-18 08:52:13 INFO     PVOutput: Data logged
2022-01-18 08:52:44 INFO     Inverter: Successfully scraped in 1.518619 secs
2022-01-18 08:52:44 ERROR    MQTT: Failed to publish with error: Message publish failed: The client is not currently connected.
...
2022-01-18 09:13:59 INFO     Starting SunGather 0.2.5
2022-01-18 09:13:59 INFO     Loaded config: config.yaml
2022-01-18 09:13:59 INFO     Loaded registers: /mnt/d/work/sungrow/sungather/SunGather/registers.yaml
2022-01-18 09:13:59 INFO     Loading Export: exports\mqtt
2022-01-18 09:13:59 INFO     MQTT: Configured localhost:1883
2022-01-18 09:13:59 INFO     Loading Export: exports\pvoutput
2022-01-18 09:13:59 INFO     PVOutput: Configured
2022-01-18 09:13:59 INFO     Connection: ModbusTcpClient(11.11.11.1:502)
2022-01-18 09:14:00 INFO     Detected Model: SG8K-D
2022-01-18 09:14:01 INFO     Inverter: Successfully scraped in 1.570271 secs
2022-01-18 09:14:01 INFO     MQTT: Published

Here's what I see in pvoutput: image

And here's Grafana: image

bohdan-s commented 2 years ago

@dbonnell yup, saw that myself, pushing 0.2.7 give me 30 mins :)

bohdan-s commented 2 years ago

Sorry, 0.2.7 has been pushed, now connects to PVOutput API, confirms system and respects PVOutput interval status rather than being set manually. Also fixes the 0 values. It will now also join SunGather team, so if you don't want that add join_team: False to the pvoutput config. This will let me see when there are issues with data upload, and how many users without adding any trackers etc...

daloser commented 2 years ago

@daloser can you try Configuration > Devices > Mosquitto broker > Configure > Listen to a topic > homeassistant/sensor/inverter/daily_generation/config and see if it outputs anything when you start SunGather?

@rianbk I thought about a config version, but I really dont want to change it again going forward. I am hoping that (unless @rianbk , @dbonnell , @daloser have anything to add) that SunGather is feature complete, and Its just bug fixes.

0.2.6 fixes an issue with 0 values to PVOutput after it looses connectivity.

updated to 0.2.7; and did as you suggested for the broker to listen to a topic, still nothing in devices/entities. SunGather running with no errors and outputting to webserver. IPs are correct; not sure if i have missed anything else

daloser commented 2 years ago

config.txt

Not sure how to nicely paste the config file, so this is a copy of it as a txt file

bohdan-s commented 2 years ago

@daloser when you added homeassistant/sensor/inverter/daily_generation/config to the listen and restarted SunGather did anything appear under the box in Home Assistant? Otherwise try something like: http://mqtt-explorer.com/ to connect and see if any messages are being published into MQTT

Screen Shot 2022-01-18 at 1 24 06 pm
dbonnell commented 2 years ago

Sorry, 0.2.7 has been pushed, now connects to PVOutput API, confirms system and respects PVOutput interval status rather than being set manually. Also fixes the 0 values. It will now also join SunGather team, so if you don't want that add join_team: False to the pvoutput config. This will let me see when there are issues with data upload, and how many users without adding any trackers etc...

Back in business! Thanks a ton @bohdan-s !

daloser commented 2 years ago

Nothing appeared below the box when configed to listen and restarting SunGather.

When i use MQTT explorer i see this; so it is broadcasting, just not seeing it in HA - shrug :-) image

bohdan-s commented 2 years ago

Can you click on "homeassistant" topic then on the right click the trash can to delete it. That will clear the auto discovery. Then restart SunGather

daloser commented 2 years ago

homeassistant/sensor/inverter/daily_generation/config

we are back in business! Thanks so much for your help!

image

rianbk commented 2 years ago

@bohdan-s for some reason overnight, its disconnected from mqtt, and has a issue pushing to pvoutput logs.txt

dbonnell commented 2 years ago

@bohdan-s for some reason overnight, its disconnected from mqtt, and has a issue pushing to pvoutput logs.txt

I see the same.

2022-01-19 08:36:50 INFO     PVOutput: Data logged
2022-01-19 08:37:22 INFO     Inverter: Successfully scraped in 1.518360 secs
2022-01-19 08:37:22 ERROR    MQTT: Failed to publish with error: Message publish failed: The client is not currently connected.

Based on the error message above, it appears the disconnect results in an exception from the publish() at mqtt.py line# 74, not an MQTT_ERR_NO_CON result code as expected at mqtt.py line#80-82. So that reconnection handling may need to be moved to or duplicated in, the except block at mqtt.py line#83-84. Maybe something like this:

        except Exception as err:
            logging.error(f"MQTT: Failed to publish with error: {err}")
            if err.find("client is not currently connected"):
                logging.warning(f"MQTT: Attempting to reconnect to MQTT")
                mqtt_client.reconnect()
dbonnell commented 2 years ago

Looking at the Paho MQTT docs, there's an on_disconnect callback that can be configured to proactively attempt reconnection before we get to the point that a publish fails but if that reconnect attempt fails, it won't get another disconnect message and try again, so we'd still need to handle that when publishing, anyway.

bohdan-s commented 2 years ago

Same as always, 0.2.8 published, heaps of fixes. Was PVOutput uplaoding every 5 mins, on 5 mins this was causing issues if it failed. Removed most the threading so should be more reliable now.

rianbk commented 2 years ago

Same as always, 0.2.8 published, heaps of fixes. Was PVOutput uplaoding every 5 mins, on 5 mins this was causing issues if it failed. Removed most the threading so should be more reliable now.

Updating and monitoring

daloser commented 2 years ago

0.2.8 Was working up until just after midnight;

2022-01-19 23:05:29 INFO Starting SunGather 0.2.8 2022-01-19 23:05:29 INFO Loaded config: config.yaml 2022-01-19 23:05:30 INFO Loaded registers: /home/pi/SunGather/SunGather/registers.yaml 2022-01-20 00:06:14 WARNING Modbus connection failed: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 8 bytes (0 received) 2022-01-20 00:06:24 WARNING Modbus connection failed: Modbus Error: [Input/Output] No Response received from the remote unit/Unable to decode response 2022-01-20 00:06:34 WARNING Modbus connection failed: Modbus Error: [Input/Output] No Response received from the remote unit/Unable to decode response 2022-01-20 00:06:34 WARNING Data collection failed, skipped exporting data. Retying in 30 secs Traceback (most recent call last): File "sungather.py", line 416, in main() File "sungather.py", line 413, in main time.sleep(scan_interval - process_time) ValueError: sleep length must be non-negative

bohdan-s commented 2 years ago

Ahh ok, thats what i thought, it seems the Modbus connection isn't respecting the timeout value, I'll push 0.2.10 today which will work around this. (As well as PVOutput issues..... again.....)

rianbk commented 2 years ago

0.2.8 Was working up until just after midnight;

2022-01-19 23:05:29 INFO Starting SunGather 0.2.8 2022-01-19 23:05:29 INFO Loaded config: config.yaml 2022-01-19 23:05:30 INFO Loaded registers: /home/pi/SunGather/SunGather/registers.yaml 2022-01-20 00:06:14 WARNING Modbus connection failed: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 8 bytes (0 received) 2022-01-20 00:06:24 WARNING Modbus connection failed: Modbus Error: [Input/Output] No Response received from the remote unit/Unable to decode response 2022-01-20 00:06:34 WARNING Modbus connection failed: Modbus Error: [Input/Output] No Response received from the remote unit/Unable to decode response 2022-01-20 00:06:34 WARNING Data collection failed, skipped exporting data. Retying in 30 secs Traceback (most recent call last): File "sungather.py", line 416, in main() File "sungather.py", line 413, in main time.sleep(scan_interval - process_time) ValueError: sleep length must be non-negative

Can confirm, same issue for me :)

bohdan-s commented 2 years ago

Pushed 0.2.10 just now, @rianbk @daloser thank you for all the testing, hopefully this will stay stable overnight now