From a31a9328cdb61ba9e3861ab26b54d23d098191cb Mon Sep 17 00:00:00 2001 From: bohdan-s Date: Mon, 20 Dec 2021 11:43:43 +1100 Subject: [PATCH] Add bypass for model detection --- SunGather/config-example.yaml | 5 +++-- SunGather/registers.yaml | 10 ++++++---- SunGather/sungather.py | 29 ++++++++++++++++++----------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/SunGather/config-example.yaml b/SunGather/config-example.yaml index 00ed6f6..c2e5865 100644 --- a/SunGather/config-example.yaml +++ b/SunGather/config-example.yaml @@ -4,9 +4,10 @@ inverter: # slave: 0x01 # Default is 0x01 # timeout: 10 # Default is 10 # scan_interval: 30 # Default is 30 - connection: http # options: modbus, sungrow, http + connection: sungrow # options: modbus, sungrow, http # model: "SG7.0RT" # This is autodected on startup, only needed if detection issues or for testing - smart_meter: True # Default is False, Set to true if inverter supports reading grind / house consumption + # See model list here: https://github.com/bohdan-s/SunGather#supported + # smart_meter: True # Default is False, Set to true if inverter supports reading grind / house consumption # hybrid: False # Default false, if you have a Hybrid (battery) set to True # logging: 30 # 10 = Debug, 20 = Info, 30 = Warnning (default), 40 = Error # level: 1 # 0 = Model and Solar Generation, diff --git a/SunGather/registers.yaml b/SunGather/registers.yaml index 7e84680..33dd28c 100644 --- a/SunGather/registers.yaml +++ b/SunGather/registers.yaml @@ -991,6 +991,8 @@ registers: address: 13018 datatype: "U32" models: ["SH5K-20", "SH3K6", "SH4K6", "SH5K-V13", "SH5K-30", "SH3K6-30", "SH4K6-30", "SH5.0RS", "SH3.6RS", "SH4.6RS", "SH6.0RS", "SH10RT", "SH8.0RT", "SH6.0RT", "SH5.0RT"] + + - hold: - name: "year" level: 0 @@ -1189,13 +1191,13 @@ registers: # address: 5155-5199 scan: # these have to be 1 less than the first register - read: - - start: "4999" + - start: "5000" range: "100" level: 1 - - start: "5099" + - start: "5100" range: "100" level: 1 - - start: "5199" + - start: "5200" range: "100" level: 3 - start: "6099" @@ -1238,7 +1240,7 @@ scan: # these have to be 1 less than the first register level: 1 hybrid: true - hold: -# - start: "4999" +# - start: "4999" # Get current date / time only # range: "7" - start: "4999" range: "10" diff --git a/SunGather/sungather.py b/SunGather/sungather.py index 73c4a45..73302dc 100644 --- a/SunGather/sungather.py +++ b/SunGather/sungather.py @@ -50,8 +50,6 @@ if config.get('exports'): logging.error(f"Failed loading export: {err}" + f"\n\t\t\t Please make sure {export.get('name')}.py exists in the exports folder") - - client_payload = { "host": config['inverter'].get('host', '127.0.0.1'), "port": config['inverter'].get('port', 502), @@ -90,7 +88,7 @@ def load_registers(register_type, start, count=100): if rr.isError(): logging.warning("Modbus connection failed") - return False + return if not hasattr(rr, 'registers'): logging.warning("No registers returned") @@ -186,6 +184,23 @@ def load_registers(register_type, start, count=100): inverter = {} model = None +if config['inverter'].get('model'): + model = config['inverter']['model'] + inverter['device_type_code'] = model + logging.info(f'Bypassing Model Detection, Using config: {model}') +else: + if load_registers("read", 4999, 1): + model = inverter.get('device_type_code') + logging.info(f'Detected Model: {model}') + else: + model = 'unknown' + logging.info(f'Model detection failed, please set model in config.py') + if not config['inverter'].get('model') and model == config['inverter'].get('model'): + logging.info(f'Model specified in config {config["inverter"].get("model")} does not match model reported by inverter {model}') + + + + # Core monitoring loop def scrape_inverter(): """ Connect to the inverter and scrape the metrics """ @@ -248,14 +263,6 @@ def scrape_inverter(): client.close() return True -if load_registers("read", 4999, 1): - model = inverter.get('device_type_code') - logging.info(f'Detected Model: {model}') -if not config['inverter'].get('model'): - config['inverter']['model'] = model -elif not model == config['inverter'].get('model'): - logging.warn(f'Model specified in config {config["inverter"].get("model")} does not match model reported by inverter {model}') - while True: # Scrape the inverter success = scrape_inverter()