Skip to content

Commit

Permalink
Merge branch 'release/0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ledermann committed Jul 15, 2024
2 parents ccc73e0 + 11ff323 commit 308b873
Show file tree
Hide file tree
Showing 47 changed files with 2,564 additions and 818 deletions.
15 changes: 10 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
.dockerignore
.env
.env.*
.git
.github
.gitignore
.env.*
.env
.rspec
.rubocop.yml
.vscode
coverage
docker-compose.yml
test
Rakefile
Dockerfile
coverage
Guardfile
Rakefile
spec
178 changes: 149 additions & 29 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,37 +1,158 @@
##### MQTT Broker credentials

##### MQTT Broker credentials
MQTT_HOST=my-mqtt-broker.local
MQTT_PORT=1883
MQTT_SSL=false
MQTT_USERNAME=my-username
MQTT_PASSWORD=my-password
MQTT_USERNAME=my-mqtt-username
MQTT_PASSWORD=my-mqtt-password

##### MQTT Topics
##### Mappings

# Example 1: For ioBroker with SENEC adapter
#
MQTT_TOPIC_HOUSE_POW=senec/0/ENERGY/GUI_HOUSE_POW
MQTT_TOPIC_GRID_POW=senec/0/ENERGY/GUI_GRID_POW
MQTT_TOPIC_BAT_CHARGE_CURRENT=senec/0/ENERGY/GUI_BAT_DATA_CURRENT
MQTT_TOPIC_BAT_FUEL_CHARGE=senec/0/ENERGY/GUI_BAT_DATA_FUEL_CHARGE
MQTT_TOPIC_BAT_POWER=senec/0/ENERGY/GUI_BAT_DATA_POWER
MQTT_TOPIC_BAT_VOLTAGE=senec/0/ENERGY/GUI_BAT_DATA_VOLTAGE
MQTT_TOPIC_CASE_TEMP=senec/0/TEMPMEASURE/CASE_TEMP
MQTT_TOPIC_CURRENT_STATE=senec/0/ENERGY/STAT_STATE_Text
MQTT_TOPIC_MPP1_POWER=senec/0/PV1/MPP_POWER/0
MQTT_TOPIC_MPP2_POWER=senec/0/PV1/MPP_POWER/1
MQTT_TOPIC_MPP3_POWER=senec/0/PV1/MPP_POWER/2
MQTT_TOPIC_INVERTER_POWER=senec/0/ENERGY/GUI_INVERTER_POWER
MQTT_TOPIC_WALLBOX_CHARGE_POWER=senec/0/WALLBOX/APPARENT_CHARGING_POWER/0
# You can define multiple mappings. Each mapping is defined by multiple environment variables.
# Each variables starts with the MAPPING_X_ prefix, where X is a number starting from 0.
#
# A mapping defines how to get data from an MQTT message and where to write it to in InfluxDB.
# At least if requires the topic name, the measurement name, the field name and the data type.
# It allows to handle positive and negative values differently, and allows to handle JSON payloads.
#
# Allowed environment variables for each mapping are:
#
# - MAPPING_X_TOPIC: the MQTT topic to subscribe to
# - MAPPING_X_MEASUREMENT: the name of the InfluxDB measurement to write to
# - MAPPING_X_MEASUREMENT_POSITIVE: the name of the InfluxDB measurement to write to for positive values (optional)
# - MAPPING_X_MEASUREMENT_NEGATIVE: the name of the InfluxDB measurement to write to for negative values (optional)
# - MAPPING_X_FIELD: the name of the InfluxDB field to write to
# - MAPPING_X_FIELD_POSITIVE: the name of the InfluxDB field to write to for positive values (optional)
# - MAPPING_X_FIELD_NEGATIVE: the name of the InfluxDB field to write to for negative values (optional)
# - MAPPING_X_TYPE: the data type of the field. It can be one of integer, float, string or boolean
# - MAPPING_X_JSON_KEY: the key in the JSON payload to extract the value from (optional, only for JSON payloads)
# - MAPPING_X_JSON_PATH: the JSONPath in the JSON payload to extract the value from (optional, only for JSON payloads)
# - MAPPING_X_JSON_FORMULA: a formula to calculate the value from the JSON payload (optional, only for JSON payloads)
#
#
# Here are some examples of mappings:
#
# Basic mapping:
# MAPPING_0_TOPIC=senec/0/ENERGY/GUI_INVERTER_POWER
# MAPPING_0_MEASUREMENT=PV
# MAPPING_0_FIELD=inverter_power
# MAPPING_0_TYPE=float
#
# Mapping with positive and negative values:
# MAPPING_1_TOPIC=senec/0/ENERGY/GUI_GRID_POW
# MAPPING_1_MEASUREMENT_POSITIVE=PV
# MAPPING_1_MEASUREMENT_NEGATIVE=PV
# MAPPING_1_FIELD_POSITIVE=grid_import_power
# MAPPING_1_FIELD_NEGATIVE=grid_export_power
# MAPPING_1_TYPE=float
#
# Mapping with simple JSON payload (using JSON_KEY):
# MAPPING_2_TOPIC=my/little/nuclear/plant
# MAPPING_2_JSON_KEY=radiation_level
# MAPPING_2_MEASUREMENT=nuclear_power_plant
# MAPPING_2_FIELD=radiation_level
# MAPPING_2_TYPE=float
#
# This extracts a value from a payload like `{"radiation_level": 90.5, "reactivity": 0.7}`. In this example, it returns the value of the key `radiation_level`, which is 90.5.
#
# Mapping with complex JSON payload (using JSON_PATH):
# MAPPING_3_TOPIC=go-e/ATTR
# MAPPING_3_JSON_PATH=$.ccp[2]
# MAPPING_3_MEASUREMENT=WALLBOX
# MAPPING_3_FIELD=power
# MAPPING_3_TYPE=float
#
# This extracts value from a payload like `{"ccp": [1,2,42,3]}`. In this example, it returns the value at the index 2 (third element) of the array `ccp`, which is 42.
#
# For JSONPath specification (the `$.` notation) see here:
# https://goessner.net/articles/JsonPath/
#
# Mapping with JSON payload and formula:
# MAPPING_4_TOPIC=my/little/nuclear/plant
# MAPPING_4_JSON_KEY=radiation_level
# MAPPING_4_MEASUREMENT=nuclear_power_plant
# MAPPING_4_FIELD=radiation_level
# MAPPING_4_TYPE=float
#
# MAPPING_5_TOPIC=my/little/nuclear/plant
# MAPPING_5_JSON_KEY=reactivity
# MAPPING_5_MEASUREMENT=nuclear_power_plant
# MAPPING_5_FIELD=reactivity
# MAPPING_5_TYPE=float
#
# MAPPING_6_TOPIC=my/little/nuclear/plant
# MAPPING_6_JSON_FORMULA="round({reactivity} * {radiation_level}) + 42"
# MAPPING_6_MEASUREMENT=nuclear_power_plant
# MAPPING_6_FIELD=danger_level
# MAPPING_6_TYPE=float
#
# For a payload like `{"radiation_level": 90.5, "reactivity": 0.7}` it calculates a `danger_level` as `round(0.7 * 90.5) + 42`, which is 105.
#
# Please note:
# - The curly braces are used to reference specific values in the JSON payload. You can use a simple key or a JSONPath
# to reference the value to use
# - The same topic is used for multiple mappings, but different json_keys (or json_formula) are used.
#
# For operators allowed in formulas see here:
# https://github.com/rubysolo/dentaku?tab=readme-ov-file#built-in-operators-and-functions

# Example 2: For evcc
# MQTT_TOPIC_HOUSE_POW=evcc/site/homePower
# MQTT_TOPIC_GRID_POW=evcc/site/gridPower
# MQTT_TOPIC_BAT_FUEL_CHARGE=evcc/site/batterySoc
# MQTT_TOPIC_BAT_POWER=evcc/site/batteryPower
# MQTT_TOPIC_INVERTER_POWER=evcc/site/pvPower
# MQTT_TOPIC_WALLBOX_CHARGE_POWER=evcc/loadpoints/1/chargePower
# MQTT_FLIP_BAT_POWER=true
MAPPING_0_TOPIC=senec/0/ENERGY/GUI_INVERTER_POWER
MAPPING_0_MEASUREMENT=PV
MAPPING_0_FIELD=inverter_power
MAPPING_0_TYPE=integer
#
MAPPING_1_TOPIC=senec/0/ENERGY/GUI_HOUSE_POW
MAPPING_1_MEASUREMENT=PV
MAPPING_1_FIELD=house_power
MAPPING_2_TYPE=integer
#
MAPPING_2_TOPIC=senec/0/ENERGY/GUI_GRID_POW
MAPPING_2_MEASUREMENT_POSITIVE=PV
MAPPING_2_MEASUREMENT_NEGATIVE=PV
MAPPING_2_FIELD_POSITIVE=grid_import_power
MAPPING_2_FIELD_NEGATIVE=grid_export_power
MAPPING_2_TYPE=integer
#
MAPPING_3_TOPIC=senec/0/PV1/POWER_RATIO
MAPPING_3_MEASUREMENT=PV
MAPPING_3_FIELD=grid_export_limit
MAPPING_3_TYPE=float
#
MAPPING_4_TOPIC=senec/0/ENERGY/GUI_BAT_DATA_POWER
MAPPING_4_MEASUREMENT_POSITIVE=PV
MAPPING_4_MEASUREMENT_NEGATIVE=PV
MAPPING_4_FIELD_POSITIVE=battery_charging_power
MAPPING_4_FIELD_NEGATIVE=battery_discharging_power
MAPPING_4_TYPE=integer
#
MAPPING_5_TOPIC=senec/0/ENERGY/GUI_BAT_DATA_FUEL_CHARGE
MAPPING_5_MEASUREMENT=PV
MAPPING_5_FIELD=battery_soc
MAPPING_5_TYPE=float
#
MAPPING_6_TOPIC=senec/0/WALLBOX/APPARENT_CHARGING_POWER/0
MAPPING_6_MEASUREMENT=PV
MAPPING_6_FIELD=wallbox_power
MAPPING_6_TYPE=integer
#
MAPPING_7_TOPIC=somewhere/HEATPUMP/POWER
MAPPING_7_MEASUREMENT=HEATPUMP
MAPPING_7_FIELD=power
MAPPING_7_TYPE=integer
#
MAPPING_8_TOPIC=senec/0/TEMPMEASURE/CASE_TEMP
MAPPING_8_MEASUREMENT=PV
MAPPING_8_FIELD=case_temp
MAPPING_8_TYPE=float
#
MAPPING_9_TOPIC=senec/0/ENERGY/STAT_STATE_Text
MAPPING_9_MEASUREMENT=PV
MAPPING_9_FIELD=system_status
MAPPING_9_TYPE=string
#
MAPPING_10_TOPIC=senec/0/ENERGY/STAT_STATE_Ok
MAPPING_10_MEASUREMENT=PV
MAPPING_10_FIELD=system_status_ok
MAPPING_10_TYPE=boolean

##### InfluxDB credentials
INFLUX_HOST=localhost
Expand All @@ -40,4 +161,3 @@ INFLUX_PORT=8086
INFLUX_TOKEN=my-token
INFLUX_ORG=my-org
INFLUX_BUCKET=my-bucket
INFLUX_MEASUREMENT=my-measurement
67 changes: 53 additions & 14 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,59 @@ MQTT_USERNAME=my-username
MQTT_PASSWORD=my-password

# MQTT Topics
MQTT_TOPIC_HOUSE_POW=senec/0/ENERGY/GUI_HOUSE_POW
MQTT_TOPIC_GRID_POW=senec/0/ENERGY/GUI_GRID_POW
MQTT_TOPIC_BAT_CHARGE_CURRENT=senec/0/ENERGY/GUI_BAT_DATA_CURRENT
MQTT_TOPIC_BAT_FUEL_CHARGE=senec/0/ENERGY/GUI_BAT_DATA_FUEL_CHARGE
MQTT_TOPIC_BAT_POWER=senec/0/ENERGY/GUI_BAT_DATA_POWER
MQTT_TOPIC_BAT_VOLTAGE=senec/0/ENERGY/GUI_BAT_DATA_VOLTAGE
MQTT_TOPIC_CASE_TEMP=senec/0/TEMPMEASURE/CASE_TEMP
MQTT_TOPIC_CURRENT_STATE=senec/0/ENERGY/STAT_STATE_Text
MQTT_TOPIC_MPP1_POWER=senec/0/PV1/MPP_POWER/0
MQTT_TOPIC_MPP2_POWER=senec/0/PV1/MPP_POWER/1
MQTT_TOPIC_MPP3_POWER=senec/0/PV1/MPP_POWER/2
MQTT_TOPIC_INVERTER_POWER=senec/0/ENERGY/GUI_INVERTER_POWER
MQTT_TOPIC_WALLBOX_CHARGE_POWER=senec/0/WALLBOX/APPARENT_CHARGING_POWER/0
MAPPING_0_TOPIC=senec/0/ENERGY/GUI_INVERTER_POWER
MAPPING_0_MEASUREMENT=PV
MAPPING_0_FIELD=inverter_power
MAPPING_0_TYPE=integer
#
MAPPING_1_TOPIC=senec/0/ENERGY/GUI_HOUSE_POW
MAPPING_1_MEASUREMENT=PV
MAPPING_1_FIELD=house_power
MAPPING_1_TYPE=integer
#
MAPPING_2_TOPIC=senec/0/ENERGY/GUI_GRID_POW
MAPPING_2_MEASUREMENT_POSITIVE=PV
MAPPING_2_MEASUREMENT_NEGATIVE=PV
MAPPING_2_FIELD_POSITIVE=grid_import_power
MAPPING_2_FIELD_NEGATIVE=grid_export_power
MAPPING_2_TYPE=integer
#
MAPPING_3_TOPIC=senec/0/PV1/POWER_RATIO
MAPPING_3_MEASUREMENT=PV
MAPPING_3_FIELD=grid_export_limit
MAPPING_3_TYPE=float
#
MAPPING_4_TOPIC=senec/0/ENERGY/GUI_BAT_DATA_POWER
MAPPING_4_MEASUREMENT_POSITIVE=PV
MAPPING_4_MEASUREMENT_NEGATIVE=PV
MAPPING_4_FIELD_POSITIVE=battery_charging_power
MAPPING_4_FIELD_NEGATIVE=battery_discharging_power
MAPPING_4_TYPE=integer
#
MAPPING_5_TOPIC=senec/0/ENERGY/GUI_BAT_DATA_FUEL_CHARGE
MAPPING_5_MEASUREMENT=PV
MAPPING_5_FIELD=battery_soc
MAPPING_5_TYPE=float
#
MAPPING_6_TOPIC=senec/0/WALLBOX/APPARENT_CHARGING_POWER/0
MAPPING_6_MEASUREMENT=PV
MAPPING_6_FIELD=wallbox_power
MAPPING_6_TYPE=integer
#
MAPPING_7_TOPIC=somewhere/HEATPUMP/POWER
MAPPING_7_MEASUREMENT=HEATPUMP
MAPPING_7_FIELD=power
MAPPING_7_TYPE=integer
#
MAPPING_8_TOPIC=senec/0/TEMPMEASURE/CASE_TEMP
MAPPING_8_MEASUREMENT=PV
MAPPING_8_FIELD=case_temp
MAPPING_8_TYPE=float
#
MAPPING_9_TOPIC=senec/0/ENERGY/STAT_STATE_Text
MAPPING_9_MEASUREMENT=PV
MAPPING_9_FIELD=system_status
MAPPING_9_TYPE=string

# InfluxDB credentials
INFLUX_HOST=localhost
Expand All @@ -27,4 +67,3 @@ INFLUX_PORT=8086
INFLUX_TOKEN=my-token
INFLUX_ORG=my-org
INFLUX_BUCKET=my-bucket
INFLUX_MEASUREMENT=my-measurement
2 changes: 1 addition & 1 deletion .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.6.0
uses: dependabot/fetch-metadata@v2.2.0
with:
github-token: '${{ secrets.PAT }}'

Expand Down
29 changes: 21 additions & 8 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ jobs:
test:
runs-on: ubuntu-latest

env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
CI: true

steps:
- name: Checkout the code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
Expand All @@ -31,7 +35,13 @@ jobs:
run: bundle exec rubocop

- name: Run tests
run: bundle exec rake test
run: bundle exec rake spec

- name: Send test coverage to CodeClimate
uses: paambaati/codeclimate-action@v8.0.0
if: ${{ env.CC_TEST_REPORTER_ID }}
with:
coverageCommand: true

build:
runs-on: ubuntu-latest
Expand All @@ -40,13 +50,13 @@ jobs:

steps:
- name: Checkout the code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
Expand All @@ -61,29 +71,32 @@ jobs:
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}

- name: Build and push
uses: docker/build-push-action@v4
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
provenance: false
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
cache-from: type=gha
cache-to: type=gha,mode=max
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
Loading

0 comments on commit 308b873

Please sign in to comment.