From 25a5fbfa9bf93e1ab0595264a8a79ae5bd8edd41 Mon Sep 17 00:00:00 2001 From: Michael Kotten Date: Fri, 3 Jun 2022 08:08:04 +0200 Subject: [PATCH 1/9] installs build tools for arm support --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index d7de0b2..ba9408e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ FROM python:3-slim +RUN apt-get update && apt-get install -y build-essential python3-dev && rm -rf /var/lib/apt/lists/* + RUN useradd sungather WORKDIR /usr/src/sungather From a55bdb3bcbb758e8c0f22343e7ab69b643d56279 Mon Sep 17 00:00:00 2001 From: Michael Kotten Date: Wed, 8 Jun 2022 08:08:39 +0200 Subject: [PATCH 2/9] adds github action to build and push docker image --- .github/workflows/docker-image.yml | 40 +++++++++++++++++++++--------- .gitignore | 4 +++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 2c0da9b..324d79e 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -2,17 +2,33 @@ name: Docker Image CI on: push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - + branches: + - main jobs: - - build: - - runs-on: python:3-slim - + docker: + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Build the Docker image - run: docker build . --file Dockerfile --tag sungather:$(date +%s) + - + name: Checkout + uses: actions/checkout@v2 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + platforms: linux/amd64,linux/arm64,linux/arm/v7 + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/sungather:latest diff --git a/.gitignore b/.gitignore index b77924e..cd33ed3 100644 --- a/.gitignore +++ b/.gitignore @@ -115,3 +115,7 @@ dmypy.json # Pyre type checker .pyre/ + +# Intellij IDEA +.idea +*.iml \ No newline at end of file From 35c65cb86d942f4508b4e907475905752c7f939e Mon Sep 17 00:00:00 2001 From: Michael Kotten Date: Wed, 27 Jul 2022 09:44:01 +0200 Subject: [PATCH 3/9] adds current version as tag for docker push --- .github/workflows/docker-image.yml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 324d79e..4fb1d85 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -6,18 +6,17 @@ on: - main jobs: docker: - if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.x' - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + run: echo "::set-output name=tag::v$(python setup.py --version)" + id: version + - uses: docker/setup-qemu-action@v1 + - uses: docker/setup-buildx-action@v1 - name: Login to DockerHub uses: docker/login-action@v1 @@ -31,4 +30,4 @@ jobs: context: . platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/sungather:latest + tags: ${{ secrets.DOCKER_HUB_USERNAME }}/sungather:${{ steps.version.outputs.tag }},${{ secrets.DOCKERHUB_USERNAME }}/sungather:latest From ade1e592b733fdea5ae64aa1247c6698aafee8d5 Mon Sep 17 00:00:00 2001 From: danielHin Date: Wed, 27 Jul 2022 17:24:56 +0200 Subject: [PATCH 4/9] simplify impoft_from_grid for hybrid * export_power_hybrid gets negative once power is imported from the grid. So no calculation is needed. Basically simplifies the code a bit. --- SunGather/sungather.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/SunGather/sungather.py b/SunGather/sungather.py index a1355b9..285d500 100644 --- a/SunGather/sungather.py +++ b/SunGather/sungather.py @@ -325,10 +325,11 @@ class SungrowInverter(): # Create a registers for Power imported and exported to/from Grid if self.inverter_config['level'] >= 1: + self.latest_scrape["export_to_grid"] = 0 + self.latest_scrape["import_from_grid"] = 0 + if self.validateRegister('meter_power'): try: - self.latest_scrape["export_to_grid"] = 0 - self.latest_scrape["import_from_grid"] = 0 power = self.latest_scrape.get('meter_power', self.latest_scrape.get('export_power', 0)) if power < 0: self.latest_scrape["export_to_grid"] = abs(power) @@ -336,17 +337,15 @@ class SungrowInverter(): self.latest_scrape["import_from_grid"] = power except Exception: pass - # in this case we connected to a hybrid inverter and need to calculate the import differently + # in this case we connected to a hybrid inverter and need to use export_power_hybrid + # export_power_hybrid is negative in case of importing from the grid elif self.validateRegister('export_power_hybrid'): try: - self.latest_scrape['export_to_grid'] = self.latest_scrape.get('export_power_hybrid', 0) - self.latest_scrape['import_from_grid'] = 0 - - # take AC output of the inverter into account as could have a battery attached. - # once the load is higher then the AC output, we import energy from the grid - power = self.latest_scrape.get('load_power_hybrid') - self.latest_scrape('total_active_power') - if power > 0: - self.latest_scrape['import_from_grid'] = power + power = self.latest_scrape.get('export_power_hybrid', 0) + if power < 0: + self.latest_scrape["import_from_grid"] = abs(power) + elif power >= 0: + self.latest_scrape["export_to_grid"] = power except Exception: pass From aeffcbaa850e9e3f0c084b1a9ac5c0b4b4e60625 Mon Sep 17 00:00:00 2001 From: Michael Kotten Date: Wed, 27 Jul 2022 19:06:36 +0200 Subject: [PATCH 5/9] fixes GitHub action --- .github/workflows/docker-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 4fb1d85..eef91eb 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -30,4 +30,4 @@ jobs: context: . platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true - tags: ${{ secrets.DOCKER_HUB_USERNAME }}/sungather:${{ steps.version.outputs.tag }},${{ secrets.DOCKERHUB_USERNAME }}/sungather:latest + tags: ${{ secrets.DOCKERHUB_USERNAME }}/sungather:${{ steps.version.outputs.tag }},${{ secrets.DOCKERHUB_USERNAME }}/sungather:latest From 718ad54d6c41f8df5dc9433b231f1085488d86dc Mon Sep 17 00:00:00 2001 From: danielHin Date: Thu, 28 Jul 2022 10:31:46 +0200 Subject: [PATCH 6/9] add notes where smar_meter is mentioned * smart_meter = true is not needed for hybrid models even a smart_meter is installed (smartmeter is always installed with hybrid ones) * add some notes to usefull registers for hybrid models --- README.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a2b6245..d91708e 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ Set the following in config.yaml under inverters section. * Level: 2 - This should be everything your inverter supports * Level: 3 - This will try every register, you will get lots of 0/65535 responses for registers not supported. -* smart_meter: True - Set to true if you have a smart reader installed, this will return power usage at the meter box, without it you can not calculate house power usage. +* smart_meter: True - (_Only needed for SG* Models_) Set to true if you have a smart meter installed, this will return power usage at the meter box, without it you can not calculate house power usage. Hybrid inverters will provide this by default (load_power_hybrid) ### Useful Registers: This is just a brief list of registers I have found useful @@ -159,19 +159,23 @@ This is just a brief list of registers I have found useful **total_running_time** - Total Hours inverter has been powered on since install **internal_temperature** - Internal temperature of the Inverter **total_active_power** - Current power being generated by the inverter in Watts -**meter_power** - Power usage at the meter box, needs a smart meter installed. +ve means consuming from the grid, -ve means exporting to the grid +**meter_power** - (_SG* Models_)Power usage at the meter box, needs a smart meter installed. +ve means consuming from the grid, -ve means exporting to the grid **load_power** - Power being consumed in total -**export_to_grid** - How much being currently exported to the grid. This is calculated from meter_power if -ve value, returned as a positive value -**import_from_grid** - How much being currently imported from grid. This is calculated from meter_power if +ve value +**load_power_hybrid** - (_SH* Models only_) Power being consumed in total +**export_to_grid** - How much being currently exported to the grid. +For SG* Models this is calculated from meter_power if -ve value, returned as a positive value. (_For Hybrid models export_power_hybrid is used_) +**import_from_grid** - How much being currently imported from grid. This is calculated from meter_power if +ve value (_for hybrid models export_power_hybrid [will be negative when importing from grid] is used) **timestamp** - Last time data was collected, based on Inverters clock by default

(back to top)

## Home Assistant setup -In the SunGather config.yaml you need to set the smart_meter if you have one; +In the SunGather config.yaml you need to set the smart_meter if you have one +_For Hybrid Models smart_meter doesn't need to get enabled_ ``` +# Only for SG* Models smart_meter: True ``` @@ -221,6 +225,8 @@ Solar Panels > Solar Production -> Solar Production (Sungather) ## Tested * SG7.0RT with WiNet-S Dongle * SG10RT with WiNet-S Dongle and Ethernet (Credit: @rark-ha) +* SH6.0RT with WiNet-S Dongle +* SH10RT with WiNet-S Dongle

(back to top)

From 5eec5913b12551cd659ba16d7db36676f9e556d1 Mon Sep 17 00:00:00 2001 From: Michael Kotten Date: Thu, 28 Jul 2022 12:59:40 +0200 Subject: [PATCH 7/9] only push docker image on new tags --- .github/workflows/docker-image.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index eef91eb..b47ca45 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -2,8 +2,8 @@ name: Docker Image CI on: push: - branches: - - main + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' jobs: docker: runs-on: ubuntu-latest From d021daf73643fa650a9dba85a88b582315763bb4 Mon Sep 17 00:00:00 2001 From: Michael Kotten Date: Thu, 28 Jul 2022 14:43:25 +0200 Subject: [PATCH 8/9] Adds automatic releases on tag --- .github/workflows/docker-image.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index b47ca45..0b2af00 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -12,22 +12,23 @@ jobs: - uses: actions/setup-python@v4 with: python-version: '3.x' - - - run: echo "::set-output name=tag::v$(python setup.py --version)" + - run: echo "::set-output name=tag::v$(python setup.py --version)" id: version - uses: docker/setup-qemu-action@v1 - uses: docker/setup-buildx-action@v1 - - - name: Login to DockerHub + - name: Login to DockerHub uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push + - name: Build and push uses: docker/build-push-action@v2 with: context: . platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true tags: ${{ secrets.DOCKERHUB_USERNAME }}/sungather:${{ steps.version.outputs.tag }},${{ secrets.DOCKERHUB_USERNAME }}/sungather:latest + - uses: "marvinpinto/action-automatic-releases@latest" + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + prerelease: false From d7afefcaa0eb8e4168d91f47714a37917fe46f39 Mon Sep 17 00:00:00 2001 From: bohdan-s Date: Fri, 29 Jul 2022 12:45:52 +1000 Subject: [PATCH 9/9] Update docker-image.yml --- .github/workflows/docker-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 0b2af00..67706c9 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -30,5 +30,5 @@ jobs: tags: ${{ secrets.DOCKERHUB_USERNAME }}/sungather:${{ steps.version.outputs.tag }},${{ secrets.DOCKERHUB_USERNAME }}/sungather:latest - uses: "marvinpinto/action-automatic-releases@latest" with: - repo_token: "${{ secrets.GITHUB_TOKEN }}" + repo_token: "${{ secrets.REPO_TOKEN }}" prerelease: false