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

General refactoring #11

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 52 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Docker Image CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:

runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# - name: Login to GitHub Container Registry
# uses: docker/login-action@v2
# with:
# registry: ghcr.io
# username: ${{ github.repository_owner }}
# password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push (standalone)
uses: docker/build-push-action@v3
with:
cache-from: type=gha
cache-to: type=gha,mode=max
file: standalone.Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: |
santam/wms-mqtt:latest
Copy link
Author

@santam85 santam85 Jan 25, 2023

Choose a reason for hiding this comment

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

This will need changing, can be parameterized with repo secrets or workflow parameters

# - name: Build and push (addon)
# uses: docker/build-push-action@v3
# with:
# cache-from: type=gha
# cache-to: type=gha,mode=max
# file: Dockerfile
# platforms: linux/amd64,linux/arm64,linux/arm/v7
# push: true
# tags: |
# santam/wms-mqtt-addon:latest
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
node_modules
*.log
33 changes: 17 additions & 16 deletions warema-bridge/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
FROM node:18-alpine as builder

## Install build toolchain, install node deps and compile native add-ons
RUN apk add --no-cache python3 make g++ linux-headers

WORKDIR app

COPY package-lock.json .
COPY package.json .

# rebuild from sources to avoid issues with prebuilt binaries (https://github.com/serialport/node-serialport/issues/2438
RUN npm ci --omit=dev && npm rebuild --build-from-source

ARG BUILD_FROM=hassioaddons/base:edge
# hadolint ignore=DL3006
FROM ${BUILD_FROM}
FROM ${BUILD_FROM} as app

# Set shell
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Setup base
# hadolint ignore=DL3003
RUN \
apk add --no-cache --virtual .build-deps python3 make g++ linux-headers
RUN \
apk add --no-cache npm

# Copy root filesystem
COPY rootfs/srv/package-lock.json /srv
COPY rootfs/srv/package.json /srv

WORKDIR /srv

RUN npm ci

RUN apk del --no-cache --purge .build-deps && rm -rf /root/.npm /root/.cache
## Copy built node modules and binaries without including the toolchain
COPY --from=builder app/node_modules ./srv/node_modules

COPY rootfs/ /
COPY warema-bridge/ /

# # Build arguments
# ARG BUILD_ARCH
Expand Down
105 changes: 105 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# addon-warema-wms

This Home Assistant addon allows to control Warema WMS equipment.
In order to use this addon you'll need a Warema WMS stick (https://www.warema.com/en/control-systems/radio-systems/supplementary-components/)

### Installation
### Configuration

MQTT_SERVER
: MQTT server url (ie: http://localhost:1883)

MQTT_USER
: Username for MQTT server authentication

MQTT_PASSWORD
: Password for MQTT server authentication

IGNORED_DEVICES
: A comma-separated list of device ids to exclude from the results of network scanning. Any excluded device will not show up in Home assistant, and the integration will ignore any status or position updates coming from it.

FORCE_DEVICES
: A comma-separated list of devices to monitor for status and position updates. The devices included in this list will be added to Home assistant even
if the automatic scanning process can't detect them. Their online status will be updated whenever they are in range. You can specify a particular device type for the forced devices
using the format `DEVICE_ID:DEVICE_TYPE` for each device in the list. In case no type is specified, type 25 is assumed (radio-controlled motor). For a list of supported device types check https://www.npmjs.com/package/warema-wms-venetian-blinds.

POLLING_INTERVAL
: Default value: 30000. Time interval in ms between each request to all devices to report their position and state.

MOVING_INTERVAL
: Default value: 1000. Minimum value: 100, Time interval between each request to a moving device to report position and state.
This applies only to covers being opened or closed, for the duration of the operation or until stopped. Set to 0 to disable.

WMS_CHANNEL, WMS_KEY, WMS_PAN_ID
: Use these parameters to configure the WMS network your devices are connected to. In order to discover the parameters, start the addon with a `PAN_ID` equal to
`FFFFF`, and follow the instructions described at the WMS network parameter discovery section ([here](#wms-discovery)).

WMS_SERIAL_PORT
: Default value: `/dev/ttyUSB0`. Device path for the WMS Usb Key.

LOG_LEVEL
: Default value: `info`. Log level, one of `[error, warn, info , http , verbose , debug , silly]` (in increasing order).

### <a name="wms-discovery"></a>WMS Network parameters discovery
In order to control WMS devices, the addon must be configured with the network parameters, which can be discovered through
a brief process. You can initiate this process by starting the add-on with default parameters, or run it standalone with
a command similar to the following:
```shell
docker run -it -e WMS_PAN_ID=FFFF -e WMS_SERIAL_PORT=/dev/ttyUSB0 santam/wms-mqtt
```

When the `panId` configuration env parameter is set to `"FFFF"`, the stick will enter discovery mode and print out
instructions on the console on how to retrieve your network configuration using a remote.

You will see something resembling the following:
```
--------------------------------------------------------------------------------
Starting getting network parameters...
- Open the battery case of the WMS Handheld transmitter.
- Select the channel using the (+) button.
Notice: If an unassigned channel is selected, press the (+) button for 5 s.
As soon as the LED flashes, all channels can be selected by
pressing the (+) button again
- Press the learn button in the battery case of the WMS Handheld
transmitter for approx. 5 s. LEDS go green; the transmission LED flashes.
For several seconds, the WMSHand-held transmitter plus scans the operating
range for devices.
- Each time when scanning stops with red LED perform steps:
1) When you press the control button (A), you can check WHICH target device
was just found.
2) If you can *not* see the output
"*** Waving and Hello!"
on the screen after pressing (A) another device than the WMS Stick has
been found. Press the (C) button to switch to the next receiver.
3) If you can see the output
"*** Waving and Hello!"
on the screen after pressing (A) then the WMS Stick has been found.
Press the STOP button to assign the WMS Stick to the channel. After
pressing STOP the network parameters are displayed on the screen.
- Press Ctrl-C to abort.
```
Once the remote is in "learning mode", and you pressed the (A) button to identify devices, you should start seeing messages like:
```
*** Stick scanned by SNR 123456.
*** Stick scanned by SNR 123456.
*** Stick scanned by SNR 123456.
*** *** Waving and Hello! (requested from SNR 123456)
*** *** Waving and Hello! (requested from SNR 123456)
```
Use these logs to make sure you are using the right network channel for the intended devices.
Once you are happy that (most of) your devices are discovered, by pressing the "stop" button on the remote, you should finally be able to see the network parameters:
```
*** WMS Network parameters successfully detected:
Channel: 17
PanId: 1A2B
Key: 0123456789ABCDEF0123456789ABCDEF
- Write down and remember the network parameters.
- Briefly press the learn button on the back of WMS Handheld transmitter to
stop the scanning process.
- Press Ctrl-C to stop program.
--------------------------------------------------------------------------------
```
At this point you have all the configuration needed to setup the addon. You'll need to add these configuration parameters to the
environment variables. The process for doing so changes depending on how you are running the addon.

You'll have to restart the addon container with the new configuration to reinitialize the WMS stick using the correct parameters.
Loading