27 Commits
1.1.1 ... 2.1.3

Author SHA1 Message Date
d9b1000665 publish cache retained
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:46:39 +01:00
7794fabaf3 publish cache 4
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:41:39 +01:00
6e6ff4c229 publish cache 3
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:39:53 +01:00
dc2175c298 publish cache 2
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:38:01 +01:00
6d8c5c25db publish cache
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:34:52 +01:00
ca08059e13 add car feedback 6
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:26:52 +01:00
6796bdd905 add car feedback 5
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:24:12 +01:00
6c208e32bf add car feedback 4
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:22:49 +01:00
d2ee8a80c2 add car feedback 3
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:20:13 +01:00
5e0127b571 add car feedback 2
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:17:25 +01:00
311d4cf555 add car feedback
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-06 14:15:03 +01:00
ad043b5921 add raw output 3
Some checks failed
ci/woodpecker/tag/woodpecker Pipeline failed
2025-12-05 15:00:22 +01:00
7c90962de1 add raw output 2
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-05 14:58:46 +01:00
3a4cd499a5 add raw output
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-05 14:44:24 +01:00
6e50654d00 lower case
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-05 13:45:00 +01:00
e820aa2000 fix in ci 2025-12-05 13:36:19 +01:00
8e60802a7a fix configuration
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-05 13:33:55 +01:00
2f87ec6d37 test ci 10
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-05 13:31:41 +01:00
3290982be1 test ci 9
Some checks failed
ci/woodpecker/tag/woodpecker Pipeline failed
2025-12-05 13:28:23 +01:00
e96e361414 test ci 8
Some checks failed
ci/woodpecker/tag/woodpecker Pipeline failed
2025-12-05 13:24:48 +01:00
87ec74dd0e test ci 7
Some checks failed
ci/woodpecker/tag/woodpecker Pipeline failed
2025-12-05 13:23:01 +01:00
a067be9d9e test ci 6
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-05 13:21:31 +01:00
190021bb84 test ci 5
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-12-05 13:18:21 +01:00
2842b3e4ec test ci 4
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-12-05 13:16:36 +01:00
cf62f384ac test ci 3
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-12-05 13:14:30 +01:00
5496c5e94e test ci 2 2025-12-05 13:14:00 +01:00
4405f5f7e7 test ci 1
Some checks failed
ci/woodpecker/tag/namespace Pipeline was successful
ci/woodpecker/tag/config Pipeline failed
ci/woodpecker/tag/build Pipeline was successful
2025-12-05 12:37:21 +01:00
11 changed files with 133 additions and 113 deletions

69
.woodpecker.yml Normal file
View File

@@ -0,0 +1,69 @@
when:
event:
- tag
variables:
- &NAMESPACE 'homea-ctrl-1'
steps:
build:
image: plugins/kaniko
settings:
registry:
from_secret: local_registry
username:
from_secret: local_username
password:
from_secret: local_password
repo: ${FORGE_NAME}/${CI_REPO}
auto_tag: true
dockerfile: Dockerfile
when:
ref:
exclude:
- refs/tags/*-configchange
namespace:
image: quay.io/wollud1969/k8s-admin-helper:0.3.4
environment:
KUBE_CONFIG_CONTENT:
from_secret: kube_config
NAMESPACE: *NAMESPACE
commands:
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
- export KUBECONFIG=/tmp/kubeconfig
- kubectl create namespace $NAMESPACE || echo "Namespace $NAMESPACE already exists"
when:
ref:
exclude:
- refs/tags/*-configchange
configuration:
image: quay.io/wollud1969/k8s-admin-helper:0.3.4
environment:
KUBE_CONFIG_CONTENT:
from_secret: kube_config
NAMESPACE: *NAMESPACE
commands:
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
- export KUBECONFIG=/tmp/kubeconfig
- kubectl create configmap pv-controller-config
--from-file=config.yaml=config/config.yaml
--namespace=$NAMESPACE
--dry-run=client -o yaml | kubectl apply -f -
deploy:
image: quay.io/wollud1969/k8s-admin-helper:0.3.4
environment:
KUBE_CONFIG_CONTENT:
from_secret: kube_config
NAMESPACE: *NAMESPACE
IMAGE: "${FORGE_NAME}/${CI_REPO}:${CI_COMMIT_TAG}"
commands:
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
- export KUBECONFIG=/tmp/kubeconfig
- cat deployment/install-yml.tmpl | sed "s,%IMAGE%,$IMAGE,g" | kubectl apply -n $NAMESPACE -f -
when:
ref:
exclude:
- refs/tags/*-configchange

View File

@@ -1,19 +0,0 @@
when:
event: [tag]
ref:
exclude:
- refs/tags/*-configchange
steps:
build:
image: plugins/kaniko
settings:
registry:
from_secret: local_registry
username:
from_secret: local_username
password:
from_secret: local_password
repo: ${FORGE_NAME}/${CI_REPO}
auto_tag: true
dockerfile: Dockerfile

View File

@@ -1,22 +0,0 @@
when:
event: [tag]
depends_on:
- namespace
steps:
apply_configuration:
image: quay.io/wollud1969/k8s-admin-helper:0.3.4
environment:
KUBE_CONFIG_CONTENT:
from_secret: kube_config
NAMESPACE: "homea-ctrl-1"
commands:
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
- export KUBECONFIG=/tmp/kubeconfig
- kubectl create configmap pv-controller-config
--from-file=config.yaml=config/config.yaml
--namespace=$NAMESPACE
--dry-run=client -o yaml | kubectl apply -f -
- kubectl apply -f deployment/configmap.yaml -n $NAMESPACE

View File

@@ -1,15 +0,0 @@
when:
event: [tag]
steps:
create_namespace:
image: quay.io/wollud1969/k8s-admin-helper:0.3.4
environment:
KUBE_CONFIG_CONTENT:
from_secret: kube_config
NAMESPACE: "homea-ctrl-1"
commands:
- printf "$KUBE_CONFIG_CONTENT" > /tmp/kubeconfig
- export KUBECONFIG=/tmp/kubeconfig
- kubectl create namespace $NAMESPACE || echo "Namespace $NAMESPACE already exists"

View File

@@ -1,36 +1,23 @@
FROM python:latest
FROM python:3.14-alpine
LABEL Maintainer="Wolfgang Hottgenroth wolfgang.hottgenroth@icloud.com"
LABEL ImageName="registry.hottis.de/dockerized/pv-controller"
LABEL HubImageName="wollud1969/pv-controller"
LABEL HubImageName="wn/pv-controller"
ARG APP_DIR="/opt/app"
ARG APP_USER="app"
ENV CFG_FILE ""
ENV MQTT__BROKER ""
ENV MQTT__PORT "1883"
ENV MQTT__METERPUBLISHTOPIC "IoT/PV/Values"
ENV MQTT__METERPUBLISHPERIOD "15"
ENV MQTT__RELAISSUBSCRIBETOPIC "IoT/PV/Cmd"
ENV MODBUS__GATEWAY ""
RUN \
apt update && \
pip3 install loguru && \
pip3 install pymodbus && \
pip3 install paho-mqtt
RUN \
mkdir -p ${APP_DIR} && \
useradd -d ${APP_DIR} -u 1000 user
COPY ./src/pv_controller/*.py ${APP_DIR}/
USER 1000:1000
WORKDIR ${APP_DIR}
COPY ./src/pv_controller/requirements.txt requirements.txt
COPY ./src/pv_controller/*.py ${APP_DIR}/
RUN addgroup -g 10001 -S ${APP_USER} && \
adduser -u 10001 -S ${APP_USER} -G ${APP_USER} && \
pip install --no-cache-dir -r requirements.txt
USER ${APP_USER}
CMD ["python", "pvc.py"]

View File

@@ -1,31 +1,14 @@
global:
scan_interval: 1
scan_interval: 0.25
log_level: INFO
mqtt:
broker: 172.16.2.16
broker: emqx01-anonymous-cluster-internal.broker.svc.cluster.local
port: 1883
modbus:
gateway: 172.16.2.42
# REGISTERS = [
# { "slave":2, "addr":0x0048, "type":"input", "attr": "importEnergyActive", "name":"Import active energy", "unit":"kWh", "adaptor": floatAdaptor },
# { "slave":2, "addr":0x004c, "type":"input", "attr": "importEnergyReactive", "name":"Import reactive energy", "unit":"kVAh", "adaptor": floatAdaptor },
# { "slave":2, "addr":0x004a, "type":"input", "attr": "exportEnergyActive", "name":"Export active energy", "unit":"kWh", "adaptor": floatAdaptor },
# { "slave":2, "addr":0x004e, "type":"input", "attr": "exportEnergyReactive", "name":"Export reactive energy", "unit":"kVAh", "adaptor": floatAdaptor },
# { "slave":2, "addr":0x0012, "type":"input", "attr": "powerApparent", "name":"Apparent Power", "unit":"W", "adaptor": floatAdaptor },
# { "slave":2, "addr":0x000c, "type":"input", "attr": "powerActive", "name":"Active Power", "unit":"W", "adaptor": floatAdaptor },
# { "slave":2, "addr":0x0018, "type":"input", "attr": "powerReactive", "name":"Reactive Power", "unit":"W", "adaptor": floatAdaptor },
# { "slave":2, "addr":0x0058, "type":"input", "attr": "powerDemandPositive", "name":"PositivePowerDemand", "unit":"W", "adaptor": floatAdaptor },
# { "slave":2, "addr":0x005c, "type":"input", "attr": "powerDemandReverse", "name":"ReversePowerDemand", "unit":"W", "adaptor": floatAdaptor },
# { "slave":2, "addr":0x001e, "type":"input", "attr": "factor", "name":"Factor", "unit":"-", "adaptor": floatAdaptor },
# { "slave":2, "addr":0x0024, "type":"input", "attr": "angle", "name":"Angle", "unit":"degree", "adaptor": floatAdaptor },
# { "slave":2, "addr":0x0000, "type":"input", "attr": "voltage", "name":"Voltage", "unit":"V", "adaptor": floatAdaptor },
# { "slave":2, "addr":0x0006, "type":"input", "attr": "current", "name":"Current", "unit":"A", "adaptor": floatAdaptor },
# { "slave":1, "addr":0x0001, "type":"holding", "attr": "state", "name":"State", "unit":"-", "adaptor": onOffAdaptor },
# ]
input:
- name: pv_control
@@ -140,10 +123,11 @@ output:
- name: pv_control
publish_topic: IoT/PV/Control/State
scan_rate: 1
raw_output: true # use only for output device with only one register, name this register 'output'
slave_id: 1
registers:
- address: 0x0001
attribute: state
attribute: output
name: State
unit: "-"
register_type: holding
@@ -153,10 +137,11 @@ output:
enabled: true
publish_topic: IoT/Car/Control/State
scan_rate: 1
raw_output: true # use only for output device with only one register, name this register 'output'
slave_id: 5
registers:
- address: 0x0001
attribute: state
attribute: output
name: State
unit: "-"
register_type: holding
@@ -245,3 +230,17 @@ output:
register_type: input
data_type: float32
adaptor: floatAdaptor
- name: car_feedback
enabled: true
publish_topic: IoT/Car/Feedback/State
scan_rate: 1
raw_output: true # use only for output device with only one register, name this register 'output'
slave_id: 7
registers:
- address: 0x0010
attribute: output
name: State
unit: "-"
register_type: holding
data_type: int32
adaptor: onOffAdaptor

View File

@@ -2,9 +2,11 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: pv-controller
namespace: homea
labels:
app: pv-controller
annotations:
reloader.stakater.com/auto: "true"
reloader.stakater.com/configmap: "pv-controller-config"
spec:
replicas: 1
selector:
@@ -17,7 +19,15 @@ spec:
spec:
containers:
- name: pv-controller
image: %IMAGE
envFrom:
- configMapRef:
name: pv-controller
image: %IMAGE%
env:
- name: CFG_FILE
value: /config/config.yaml
volumeMounts:
- name: pv-controller-config
mountPath: /config/config.yaml
subPath: config.yaml
volumes:
- name: pv-controller-config
configMap:
name: pv-controller-config

View File

@@ -9,7 +9,7 @@ def floatAdaptor(i):
return float(f"{i:0.2f}") if i else 0.0
def onOffAdaptor(i):
return bool(i)
return 'on' if bool(i) else 'off'
@@ -49,12 +49,13 @@ class FromDevices(AbstractMqttPublisher):
payload[registers.attribute] = value
payload['status'] = "Ok"
payload['cnt'] = cnt
payloadStr = json.dumps(payload) if not device.raw_output else str(payload['output'])
self.publish_with_cache(device.publish_topic, payloadStr)
logger.debug(f"mqtt message sent: {device.publish_topic} -> {payloadStr}")
except Exception as e:
logger.error(f"Caught exception: {str(e)}")
payload['cnt'] = cnt
payloadStr = json.dumps(payload)
self.client.publish(device.publish_topic, payloadStr)
logger.debug(f"mqtt message sent: {device.publish_topic} -> {payloadStr}")
self.killEvent.wait(timeout=float(self.config.global_.scan_interval))

View File

@@ -25,6 +25,8 @@ class AbstractMqttPublisher(threading.Thread):
logger.info(f"mqtt client id: {client_id}")
self.client = mqtt.Client(client_id=client_id, userdata=self)
self.cache = {}
# consider this flag in the localLoop
self.killBill = False
self.killEvent = threading.Event()
@@ -62,3 +64,10 @@ class AbstractMqttPublisher(threading.Thread):
def onMessage(self, topic, payload):
logger.warning("mqtt unexpected message received: {} -> {}".format(topic, str(payload)))
def publish_with_cache(self, topic, payload):
if topic in self.cache and self.cache[topic] == payload:
logger.debug(f"mqtt message unchanged, not publishing: {topic} -> {payload}")
return
self.cache[topic] = payload
self.client.publish(topic, payload, retain=True)

View File

@@ -24,7 +24,7 @@ class ToDevices(AbstractMqttPublisher):
continue
if device.register_type != 'coil':
raise Exception(f"Unsupported register type {device.register_type} for input device {device.name}")
value = payload == b'On'
value = payload == b'on'
self.modbusHandler.writeCoil(device.slave_id, device.address, value)
except Exception as e:
logger.error(f"Caught exception in onMessage: {str(e)}")

View File

@@ -24,6 +24,7 @@ class OutputConfig(BaseModel):
enabled: bool = Field(default=True)
scan_rate: Optional[int] = Field(default=60)
publish_topic: str
raw_output: Optional[bool] = Field(default=False)
slave_id: int
registers: List[RegisterConfig]
@@ -50,7 +51,7 @@ class ModbusConfig(BaseModel):
class GlobalConfig(BaseModel):
"""Global settings"""
scan_interval: int
scan_interval: float
log_level: str