Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error handling, Nightly build #44

Merged
merged 29 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8880a82
added nightly addon
Nov 28, 2023
761b356
fix run.sh
Nov 28, 2023
08eea50
add debug logging option
Nov 28, 2023
29ba244
minor comment change in dockerfile
Nov 28, 2023
6e713f7
use try_publish instead of publish to propagate connection failures i…
Nov 28, 2023
7e7314a
revert change in config.toml
Nov 28, 2023
d1c4337
add debug_logging to home assistant addon options
Nov 28, 2023
fa3953f
fix version in ha addon config.yaml
Nov 28, 2023
7e51ff9
version bump for nightly addon
Nov 28, 2023
c2a2589
add date to nightly build tag
Nov 28, 2023
d06b1f9
update nightly dockerfile
Nov 28, 2023
21a5568
run.sh bugfix
Nov 28, 2023
fc92a0b
bugfix for run.sh
Nov 28, 2023
4719bb1
Merge remote-tracking branch 'origin_orig/main'
Nov 29, 2023
dbf03e0
main addon version bump
Nov 29, 2023
150b698
cargo fmt
Nov 29, 2023
b214f8d
Merge remote-tracking branch 'origin_orig/main'
Nov 30, 2023
b3d45e5
revert source code changes, use env variable for debug logging
Nov 30, 2023
ae02abb
fix dockerfile
Nov 30, 2023
9b29d3a
revert debug logging via cli
Nov 30, 2023
0f8731f
update Dockerfile of nightly addon
Nov 30, 2023
63a60d5
minor bugfix for run.sh
Nov 30, 2023
eda9b16
fix dockerfile
Nov 30, 2023
442030c
update addon changelog
Nov 30, 2023
051b7ed
Merge remote-tracking branch 'origin_orig/main'
Dec 9, 2023
6494716
fix failing docker build
Dec 9, 2023
9eb7624
Merge remote-tracking branch 'origin_orig/main'
Dec 9, 2023
aa27b6c
bump home assistant nightly addon version
Dec 10, 2023
feeed80
Update main addon to latest version
Dec 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/dockerhub-nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Publish multi platform nightly Docker image

on:
push:
branches: ["*"]
pull_request:
branches: ["*"]
workflow_dispatch:

jobs:
push_to_registry:
name: Push nightly Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASS }}

- name: Get current date
id: current_date
run: echo "::set-output name=date::$(date +'%Y%m%d')"

- name: Get the current Git commit hash
id: git_hash
run: echo "GIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ secrets.DOCKER_HUB_NAMESPACE }}/${{ secrets.DOCKER_HUB_REPOSITORY_NIGHTLY }}
tags: |
type=raw,value=nightly-${{ github.ref_name }}-${{ steps.current_date.outputs.date }}
type=raw,value=latest

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: GIT_HASH=${{ env.GIT_HASH }}
5 changes: 5 additions & 0 deletions .github/workflows/dockerhub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASS }}

- name: Get the current Git commit hash
id: git_hash
run: echo "GIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV

- name: Extract metadata (tags, labels) for Docker
id: meta
Expand All @@ -38,3 +42,4 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: GIT_HASH=${{ env.GIT_HASH }}
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# First, we need an image to build the application
FROM rust:slim-bullseye as builder

ARG GIT_HASH
ENV GIT_HASH=$GIT_HASH

WORKDIR /usr/src/hms-mqtt-publish

# The following builds the rust application in two stages:
Expand All @@ -14,14 +17,16 @@ WORKDIR /usr/src/hms-mqtt-publish
# Stage 1: Build the dependencies

COPY ./Cargo.toml ./
# Remove the hms2mqtt dependency from the Cargo.toml file (compiled in second stage)
RUN sed -i s/hms2mqtt.*//g Cargo.toml
RUN mkdir src && \
echo "fn main() {println!(\"hello from dependency build\")}" > src/main.rs && \
cargo build --release


# Stage 2: Build the protobuf files

COPY ./build.rs ./
# Stage 2: Build the application
COPY ./Cargo.toml ./
COPY ./hms2mqtt ./hms2mqtt
COPY ./src ./src
RUN cargo install --path .

Expand Down
19 changes: 19 additions & 0 deletions ha-hoymiles-wifi-addon-nightly/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [v0.4]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't released 0.3 yet. 😀 I can fix the version number as part of the the next release. No need to rush.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I need to do a version bump in the addon, otherwise home assistant won't show that an update exists, so I've been setting the addon versions independently of the releases

Bugfixes and improvements

## [v0.3]
Add debug_logging option

## [v0.2]
Warning: breaking changes! The sensor identifiers have changed
Implemented support for home assistant discovery
Add extra sensors

## [v0.1]
Initial release
16 changes: 16 additions & 0 deletions ha-hoymiles-wifi-addon-nightly/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ARG BUILD_FROM

# Use pre-built image to copy the binary from
FROM dominikandreas/hms-mqtt-publisher-nightly:nightly-main-20231209 AS builder

FROM $BUILD_FROM

# Copy the compiled binary from the builder stage
COPY --from=builder /usr/local/bin/hms-mqtt-publish /usr/local/bin/hms-mqtt-publish

# Copy the run script into the container
COPY run.sh /run.sh
RUN chmod a+x /run.sh

# When the container starts, run the script
CMD [ "/run.sh" ]
33 changes: 33 additions & 0 deletions ha-hoymiles-wifi-addon-nightly/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Home Assistant Add-on

> Note: this is the nightly version of the add-on that is used for testing.

This tool can directly run inside Home Assistant OS as an addon. To get started, add the URL of this repository to the add-on store in Home Assistant and install the add-on. Alternatively, you can also run it stand-alone on any machine that supports rust or docker (see section below).

## Configuration

To set up the add-on, fill in the following configuration parameters:

- `inverter_host`: The hostname or IP address of your inverter.
- `mqtt_broker_host`: The hostname or IP address of your MQTT broker.
- `mqtt_username`: The username for your MQTT broker.
- `mqtt_password`: The password for your MQTT broker. Keep this secret!
- `mqtt_port`: The port of your MQTT broker (default is 1883 for unencrypted MQTT).

## Example configuration

```yaml
inverter_host: "192.168.1.100"
mqtt_broker_host: "core-mosquitto"
mqtt_username: "yourusername"
mqtt_password: "yourpassword"
mqtt_port: 1883
```

## Note of caution
Please note: The tool does not come with any guarantees and if by chance you fry your inverter with a funny series of bits, you are on your own. That being said, no inverters have been harmed during development.

## Known limitations
- One can only fetch updates approximately twice per minute. The inverter firmware seems to implement a mandatory wait period of a little more than 30 seconds. If one makes a request within 30 seconds of the previous one, then the inverter will reply with the previous reading and restart the countdown. It will also not send updated values to S-Miles Cloud if this happens.
- The tools was developed for (and with an) HMS-800W-T2. It may work with the other inverters from the series, but is untested at the time of writing

5 changes: 5 additions & 0 deletions ha-hoymiles-wifi-addon-nightly/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
build_from:
aarch64: ghcr.io/hassio-addons/debian-base:7.2.0
amd64: ghcr.io/hassio-addons/debian-base:7.2.0
armv7: ghcr.io/hassio-addons/debian-base:7.2.0
28 changes: 28 additions & 0 deletions ha-hoymiles-wifi-addon-nightly/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Hoymiles HMS Wifi Addon (Nightly)
version: 'v0.4'
slug: ha-hoymiles-wifi-addon-nightly
description: Publishes telemetry information from Hoymiles HMS-XXXXW-T2 micro-inverters to your home assistant MQTT broker
url: https:/dominikandreas/hms-mqtt-publisher/tree/main/ha-hoymiles-wifi-addon-nightly
init: false
arch: # List of supported architectures.
- armv7
- aarch64
- amd64
startup: application # When the add-on should start.
boot: auto # Boot options, auto or manual.
services: ['mqtt:want']
options: # Default options value for the add-on.
inverter_host: ''
mqtt_broker_host: ''
mqtt_username: ''
mqtt_password: ''
mqtt_port: 1883
debug_logging: false
schema: # Schema validation for the options.
inverter_host: str
mqtt_broker_host: str?
mqtt_username: str?
mqtt_password: str?
mqtt_port: int
debug_logging: bool
Binary file added ha-hoymiles-wifi-addon-nightly/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ha-hoymiles-wifi-addon-nightly/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions ha-hoymiles-wifi-addon-nightly/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/with-contenv bashio

# Enable strict mode for bash (exit on error, error on undefined variable, error if any pipeline element fails)
set -euo pipefail
# Fetch values from the add-on configuration by extracting it from /data/options.json

HA_MQTT_BROKER_HOST=$(bashio::services mqtt "host")
HA_MQTT_USERNAME=$(bashio::services mqtt "username")
HA_MQTT_PASSWORD=$(bashio::services mqtt "password")

INVERTER_HOST=$(bashio::config 'inverter_host')
MQTT_BROKER_HOST=$(bashio::config 'mqtt_broker_host')
MQTT_USERNAME=$(bashio::config 'mqtt_username')
MQTT_PASSWORD=$(bashio::config 'mqtt_password')
MQTT_PORT=$(bashio::config 'mqtt_port')
DEBUG_LOGGING=$(bashio::config 'debug_logging')

# Use bashio::config values if they are defined, otherwise fall back to bashio::services values
MQTT_BROKER_HOST=${MQTT_BROKER_HOST:-$HA_MQTT_BROKER_HOST}
MQTT_USERNAME=${MQTT_USERNAME:-$HA_MQTT_USERNAME}
MQTT_PASSWORD=${MQTT_PASSWORD:-$HA_MQTT_PASSWORD}
DEBUG_LOGGING=${DEBUG_LOGGING:-'false'}


# Check if the required configs are provided
if [[ -z "$INVERTER_HOST" ]]; then
echo "The inverter_host is not configured."
exit 1
fi

if [[ -z "$MQTT_BROKER_HOST" ]]; then
echo "The mqtt_broker_host is not configured."
exit 1
fi

# Create the configuration file
cat <<EOF > ./config.toml
inverter_host = "$INVERTER_HOST"

[home_assistant]
host = "$MQTT_BROKER_HOST"
username = "$MQTT_USERNAME"
password = "$MQTT_PASSWORD"
port = $MQTT_PORT
EOF

# if DEBUG_LOGGING is true, set the RUST_LOG=debug environment variable to enable debug logging
if [[ "$DEBUG_LOGGING" == "true" ]]; then
export RUST_LOG=debug
fi

# Execute the application
/usr/local/bin/hms-mqtt-publish
14 changes: 11 additions & 3 deletions ha-hoymiles-wifi-addon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [v0.1]
Initial release
## [v0.4]
Bugfixes and improvements

## [v0.3]
Add debug_logging option

## [v0.2]
Support auto discovery
Warning: breaking changes! The sensor identifiers have changed
Implemented support for home assistant discovery
Add extra sensors

## [v0.1]
Initial release
2 changes: 1 addition & 1 deletion ha-hoymiles-wifi-addon/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG BUILD_FROM

# Use pre-built image to copy the binary from
FROM dominikandreas/hms-mqtt-publisher-nightly:experimental-output_channels AS builder
FROM dominikandreas/hms-mqtt-publisher-nightly:nightly-main-20231209 AS builder

FROM $BUILD_FROM

Expand Down
8 changes: 5 additions & 3 deletions ha-hoymiles-wifi-addon/config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
name: Hoymiles HMS Wifi Addon
version: '0.2'
version: 'v0.3'
slug: ha-hoymiles-wifi-addon
description: Publishes telemetry information from Hoymiles HMS-XXXXW-T2 micro-inverters to your home assistant MQTT broker
url: https:/dennisosrm/hms-mqtt-publisher/tree/master/ha-hoymiles-wifi-addon
url: https:/dominikandreas/hms-mqtt-publisher/tree/master/ha-hoymiles-wifi-addon
init: false
arch: # List of supported architectures.
- armv7
Expand All @@ -18,9 +18,11 @@ options: # Default options value for the add-on.
mqtt_username: ''
mqtt_password: ''
mqtt_port: 1883
debug_logging: false
schema: # Schema validation for the options.
inverter_host: str
mqtt_broker_host: str?
mqtt_username: str?
mqtt_password: str?
mqtt_port: int
mqtt_port: int
debug_logging: bool
21 changes: 6 additions & 15 deletions ha-hoymiles-wifi-addon/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ MQTT_BROKER_HOST=$(bashio::config 'mqtt_broker_host')
MQTT_USERNAME=$(bashio::config 'mqtt_username')
MQTT_PASSWORD=$(bashio::config 'mqtt_password')
MQTT_PORT=$(bashio::config 'mqtt_port')
DEBUG_LOGGING=$(bashio::config 'debug_logging')

# Use bashio::config values if they are defined, otherwise fall back to bashio::services values
MQTT_BROKER_HOST=${MQTT_BROKER_HOST:-$HA_MQTT_BROKER_HOST}
MQTT_USERNAME=${MQTT_USERNAME:-$HA_MQTT_USERNAME}
MQTT_PASSWORD=${MQTT_PASSWORD:-$HA_MQTT_PASSWORD}
DEBUG_LOGGING=${DEBUG_LOGGING:-'false'}


# Check if the required configs are provided
Expand All @@ -35,28 +37,17 @@ fi
cat <<EOF > ./config.toml
inverter_host = "$INVERTER_HOST"

[home_assistent]
[home_assistant]
host = "$MQTT_BROKER_HOST"
username = "$MQTT_USERNAME"
password = "$MQTT_PASSWORD"
port = $MQTT_PORT
EOF

# Write mqtt broker username if specified
if [[ -n "$MQTT_USERNAME" ]]; then
echo "username = \"$MQTT_USERNAME\"\n" >> ./config.toml
# if DEBUG_LOGGING is true, set the RUST_LOG=debug environment variable to enable debug logging
if [[ "$DEBUG_LOGGING" == "true" ]]; then
export RUST_LOG=debug
fi

# Create the configuration file
cat <<EOF > ./config.toml
inverter_host = "$INVERTER_HOST"

[home_assistant]
host = "$MQTT_BROKER_HOST"
username = "$MQTT_USERNAME"
password = "$MQTT_PASSWORD"
port = $MQTT_PORT
EOF

# Execute the application
/usr/local/bin/hms-mqtt-publish
Loading