mirror of
https://github.com/alexhopeoconnor/SunGather.git
synced 2026-10-23 11:02:10 +10:00
Updated README with HA instructions, imporved docker support, use Inveter time instead of local time by default
This commit is contained in:
+4
-2
@@ -1,11 +1,13 @@
|
|||||||
FROM python:3
|
FROM python:3
|
||||||
|
|
||||||
|
ENV IS_DOCKER True
|
||||||
|
|
||||||
WORKDIR /usr/src/sungather
|
WORKDIR /usr/src/sungather
|
||||||
|
|
||||||
COPY requirements.txt ./
|
COPY requirements.txt ./
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
||||||
|
|
||||||
COPY SunGather/ .
|
COPY SunGather/ .
|
||||||
RUN touch /usr/src/sungather/config.yaml
|
RUN touch /config/config.yaml
|
||||||
|
|
||||||
CMD [ "python", "sungather.py" ]
|
CMD [ "python", "sungather.py" ]
|
||||||
@@ -1,19 +1,20 @@
|
|||||||
inverter:
|
inverter:
|
||||||
host: 192.168.1.100
|
host: 192.168.1.100
|
||||||
# port: 502 # Default for modbus is 502, for http is 8082
|
# port: 502 # Default for modbus is 502, for http is 8082
|
||||||
# slave: 0x01 # Default is 0x01
|
# slave: 0x01 # Default is 0x01
|
||||||
# timeout: 10 # Default is 10
|
# timeout: 10 # Default is 10
|
||||||
# scan_interval: 30 # Default is 30
|
# scan_interval: 30 # Default is 30
|
||||||
connection: sungrow # 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
|
# model: "SG7.0RT" # This is autodected on startup, only needed if detection issues or for testing
|
||||||
# See model list here: https://github.com/bohdan-s/SunGather#supported
|
# 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
|
# smart_meter: True # Default is False, Set to true if inverter supports reading grind / house consumption
|
||||||
|
# use_local_time: False # Default False, Uses Inveter time, if try uses PC time when updating timestamps (e.g. PVOutput)
|
||||||
# hybrid: False # Default false, if you have a Hybrid (battery) set to True
|
# hybrid: False # Default false, if you have a Hybrid (battery) set to True
|
||||||
# logging: 30 # 10 = Debug, 20 = Info, 30 = Warnning (default), 40 = Error
|
# logging: 30 # 10 = Debug, 20 = Info, 30 = Warnning (default), 40 = Error
|
||||||
# level: 1 # 0 = Model and Solar Generation,
|
# level: 1 # 0 = Model and Solar Generation,
|
||||||
# 1 (default) = Useful data, all required for exports,
|
# 1 (default) = Useful data, all required for exports,
|
||||||
# 2 everything your Inverter supports,
|
# 2 everything your Inverter supports,
|
||||||
# 3 Everything from every register
|
# 3 Everything from every register
|
||||||
|
|
||||||
exports:
|
exports:
|
||||||
- name: console # Print Registers to console, good for debugging / troubleshooting
|
- name: console # Print Registers to console, good for debugging / troubleshooting
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import datetime
|
|
||||||
import requests
|
import requests
|
||||||
|
import datetime
|
||||||
|
|
||||||
# Configure PVOutput
|
# Configure PVOutput
|
||||||
class export_pvoutput(object):
|
class export_pvoutput(object):
|
||||||
@@ -63,7 +63,7 @@ class export_pvoutput(object):
|
|||||||
"""
|
"""
|
||||||
at_least_one_of = set(["v1", "v2", "v3", "v4"])
|
at_least_one_of = set(["v1", "v2", "v3", "v4"])
|
||||||
|
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.strptime(inverter.get('timestamp'), "%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
if self.latest_run:
|
if self.latest_run:
|
||||||
# Spread out our publishes over the hour based on the rate limit
|
# Spread out our publishes over the hour based on the rate limit
|
||||||
|
|||||||
+46
-20
@@ -5,12 +5,14 @@ from SungrowModbusWebClient import SungrowModbusWebClient
|
|||||||
from pymodbus.client.sync import ModbusTcpClient
|
from pymodbus.client.sync import ModbusTcpClient
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from version import __version__
|
from version import __version__
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import yaml
|
import yaml
|
||||||
import time
|
import time
|
||||||
|
import os
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format='%(asctime)s %(levelname)-8s %(message)s',
|
format='%(asctime)s %(levelname)-8s %(message)s',
|
||||||
@@ -20,21 +22,34 @@ logging.info(f'Starting SunGather {__version__}')
|
|||||||
|
|
||||||
#opts = sys.getopt(sys.argv[1:],"hi:o:",["ifile=","ofile="])
|
#opts = sys.getopt(sys.argv[1:],"hi:o:",["ifile=","ofile="])
|
||||||
|
|
||||||
|
IS_DOCKER = os.environ.get('IS_DOCKER', False)
|
||||||
|
|
||||||
|
# If we are in docker, get config.py from a easy location to map via volumes
|
||||||
|
if IS_DOCKER:
|
||||||
|
try:
|
||||||
|
config = yaml.safe_load(open('/config/config.yaml'))
|
||||||
|
logging.info(f"Loaded config: /config/config.yaml")
|
||||||
|
except Exception as err:
|
||||||
|
logging.error(f"Failed: Loading config: /config/config.yaml {err}")
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
config = yaml.safe_load(open('config.yaml'))
|
||||||
|
logging.info(f"Loaded config: {os.getcwd()}/config.yaml")
|
||||||
|
except Exception as err:
|
||||||
|
logging.error(f"Failed: Loading config: {os.getcwd()}/config.yaml {err}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config = yaml.safe_load(open('config.yaml'))
|
registers = yaml.safe_load(open('registers.yaml'))
|
||||||
logging.info(f"Loaded config: config.yaml")
|
logging.info(f"Loaded registers: {os.getcwd()}/registers.yaml")
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logging.error(f"Failed: Loading config: config.yaml {err}")
|
logging.error(f"Failed: Loading registers: {os.getcwd()}/registers.yaml {err}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
logging.getLogger().setLevel(config['inverter'].get('logging',30))
|
logging.getLogger().setLevel(config['inverter'].get('logging',30))
|
||||||
|
|
||||||
try:
|
|
||||||
registers = yaml.safe_load(open('registers.yaml'))
|
|
||||||
logging.info(f"Loaded registers: registers.yaml")
|
|
||||||
except Exception as err:
|
|
||||||
logging.error(f"Failed: Loading registers: registers.yaml {err}")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
exports = []
|
exports = []
|
||||||
if config.get('exports'):
|
if config.get('exports'):
|
||||||
@@ -250,23 +265,34 @@ def scrape_inverter():
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
if config['inverter'].get('use_local_time',False):
|
||||||
inverter["timestamp"] = "%s-%s-%s %s:%02d:%02d" % (
|
inverter["timestamp"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
inverter["year"],
|
logging.debug(f'Using Local Computer Time: {inverter.get("timestamp")}')
|
||||||
inverter["month"],
|
|
||||||
inverter["day"],
|
|
||||||
inverter["hour"],
|
|
||||||
inverter["minute"],
|
|
||||||
inverter["second"],
|
|
||||||
)
|
|
||||||
del inverter["year"]
|
del inverter["year"]
|
||||||
del inverter["month"]
|
del inverter["month"]
|
||||||
del inverter["day"]
|
del inverter["day"]
|
||||||
del inverter["hour"]
|
del inverter["hour"]
|
||||||
del inverter["minute"]
|
del inverter["minute"]
|
||||||
del inverter["second"]
|
del inverter["second"]
|
||||||
except Exception:
|
else:
|
||||||
pass
|
try:
|
||||||
|
inverter["timestamp"] = "%s-%s-%s %s:%02d:%02d" % (
|
||||||
|
inverter["year"],
|
||||||
|
inverter["month"],
|
||||||
|
inverter["day"],
|
||||||
|
inverter["hour"],
|
||||||
|
inverter["minute"],
|
||||||
|
inverter["second"],
|
||||||
|
)
|
||||||
|
logging.debug(f'Using Inverter Time: {inverter.get("timestamp")}')
|
||||||
|
del inverter["year"]
|
||||||
|
del inverter["month"]
|
||||||
|
del inverter["day"]
|
||||||
|
del inverter["hour"]
|
||||||
|
del inverter["minute"]
|
||||||
|
del inverter["second"]
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
client.close()
|
client.close()
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user