Skip to content

Commit

Permalink
Z-Way version from 4.1.3
Browse files Browse the repository at this point in the history
The following changes are made in this version:

Update of the Z-Way version from 4.1.3
Fixed a problem with remote access, if you have ID 197811, it will be replaced with a new one. Also, at the first launch, a new unique ID will be obtained
An additional port input field has been added, this field is required if you are going to use an additional adapter in Z-Way, for example ZigBee or EnOcean or Z-Station.
The image size has been reduced, now it is not based on the virtual environment of Raspberry Pi from balena, now we use the debian image from home assistant, everything now works in the hassio environment
We also switched to the s6-overlay launch system, for better compatibility with the Home Assistant
Removed useless ports 1883 and 8883, which interfered with the mqtt broker
Added a field with a choice of logging level, disabled by default so as not to torment the microSD memory card, if you need logs, just specify the value 0
  • Loading branch information
PoltoS authored May 14, 2024
2 parents a47fa5e + 98ad741 commit c304c29
Show file tree
Hide file tree
Showing 14 changed files with 581 additions and 168 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Builder

env:
BUILD_ARGS: "--test"
MONITORED_FILES: "config.yaml Dockerfile Dockerfile.aarch64 Dockerfile.armhf run.sh"
MONITORED_FILES: "config.yaml Dockerfile Dockerfile.aarch64 Dockerfile.armhf rootfs/etc/cont-init.d/z-way-server-init rootfs/etc/cont-init.d/zbw_connect-init rootfs/etc/services.d/zbw_connect/run rootfs/etc/services.d/zbw_connect/finish rootfs/etc/services.d/z-way-server/run rootfs/etc/services.d/z-way-server/finish"

on:
push:
Expand Down Expand Up @@ -100,12 +100,12 @@ jobs:

- name: Build ${{ matrix.addon }} add-on
if: steps.check.outputs.build_arch == 'true'
uses: home-assistant/builder@2024.01.0
uses: home-assistant/builder@2024.03.5
with:
args: |
${{ env.BUILD_ARGS }} \
--${{ matrix.arch }} \
--target /data/${{ matrix.addon }} \
--image "${{ steps.check.outputs.image }}" \
--docker-hub "ghcr.io/${{ github.repository_owner }}" \
--addon
--addon
22 changes: 10 additions & 12 deletions zwave_me_server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM ubuntu:focal

ENV branch=ubuntu
ENV distro=focal
FROM ghcr.io/home-assistant/amd64-base-debian:bullseye

WORKDIR /opt/z-way-server

ENV DEBIAN_FRONTEND=noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Block zbw key request
RUN mkdir -p /etc/zbw/flags && touch /etc/zbw/flags/no_connection

RUN apt-get update && \
apt-get install -qqy --no-install-recommends \
Expand All @@ -14,19 +14,17 @@ RUN apt-get update && \

RUN wget -q -O - https://storage.z-wave.me/Z-Way-Install |bash
RUN rm -f /opt/z-way-server/automation/storage/*
RUN sed -i 's|"config": "config"|"config": "configs/config"|g' /opt/z-way-server/automation/defaultConfigs/config.json

RUN useradd -rm -d /home/support -s /bin/bash -g root -G sudo -u 1000 support
RUN useradd -rm -d /home/support -s /bin/bash -g root -G sudo -u 1000 support
RUN echo 'support:razberry' | chpasswd

RUN echo "ha" > /etc/z-way/box_type

RUN wget -O /opt/z-way-server/automation/classes/AutomationController.js https://raw.githubusercontent.com/Z-Wave-Me/home-automation/1c5ad7bb95453b5bb7749ad2d1e5907d6949ccc3/classes/AutomationController.js
# Unblock zbw
RUN rm /etc/zbw/flags/no_connection

COPY run.sh .
RUN chmod a+x run.sh
COPY rootfs/ /

EXPOSE 8083
EXPOSE 8883

CMD /opt/z-way-server/run.sh
ENTRYPOINT ["/init"]
24 changes: 13 additions & 11 deletions zwave_me_server/Dockerfile.aarch64
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
FROM balenalib/rpi-raspbian
FROM ghcr.io/home-assistant/aarch64-base-debian:bullseye

WORKDIR /opt/z-way-server

ENV DEBIAN_FRONTEND=noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Block zbw key request
RUN mkdir -p /etc/zbw/flags && touch /etc/zbw/flags/no_connection

RUN apt-get update && \
apt-get install -qqy --no-install-recommends \
ca-certificates curl \
wget procps gpg iproute2 openssh-client openssh-server sudo logrotate jq

RUN wget -q -O - https://storage.z-wave.me/RaspbianInstall |bash
RUN sudo dpkg --add-architecture armhf

RUN wget -q -O - https://storage.z-wave.me/Z-Way-Install |bash
RUN rm -f /opt/z-way-server/automation/storage/*
RUN sed -i 's|"config": "config"|"config": "configs/config"|g' /opt/z-way-server/automation/defaultConfigs/config.json

RUN useradd -rm -d /home/support -s /bin/bash -g root -G sudo -u 1000 support
RUN useradd -rm -d /home/support -s /bin/bash -g root -G sudo -u 1000 support
RUN echo 'support:razberry' | chpasswd

RUN echo "ha" > /etc/z-way/box_type

RUN wget -O /opt/z-way-server/automation/classes/AutomationController.js https://raw.githubusercontent.com/Z-Wave-Me/home-automation/1c5ad7bb95453b5bb7749ad2d1e5907d6949ccc3/classes/AutomationController.js
# Unblock zbw
RUN rm /etc/zbw/flags/no_connection

COPY run.sh .
RUN chmod a+x run.sh
COPY rootfs/ /

EXPOSE 8083
EXPOSE 8084
EXPOSE 8883

CMD /opt/z-way-server/run.sh
ENTRYPOINT ["/init"]
24 changes: 13 additions & 11 deletions zwave_me_server/Dockerfile.armhf
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
FROM balenalib/rpi-raspbian
FROM ghcr.io/home-assistant/armhf-base-debian:bullseye

WORKDIR /opt/z-way-server

ENV DEBIAN_FRONTEND=noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Block zbw key request
RUN mkdir -p /etc/zbw/flags && touch /etc/zbw/flags/no_connection

RUN apt-get update && \
apt-get install -qqy --no-install-recommends \
ca-certificates curl \
wget procps gpg iproute2 openssh-client openssh-server sudo logrotate jq

RUN wget -q -O - https://storage.z-wave.me/RaspbianInstall |bash
RUN sudo dpkg --add-architecture armhf

RUN wget -q -O - https://storage.z-wave.me/Z-Way-Install |bash
RUN rm -f /opt/z-way-server/automation/storage/*
RUN sed -i 's|"config": "config"|"config": "configs/config"|g' /opt/z-way-server/automation/defaultConfigs/config.json

RUN useradd -rm -d /home/support -s /bin/bash -g root -G sudo -u 1000 support
RUN useradd -rm -d /home/support -s /bin/bash -g root -G sudo -u 1000 support
RUN echo 'support:razberry' | chpasswd

RUN echo "ha" > /etc/z-way/box_type

RUN wget -O /opt/z-way-server/automation/classes/AutomationController.js https://raw.githubusercontent.com/Z-Wave-Me/home-automation/1c5ad7bb95453b5bb7749ad2d1e5907d6949ccc3/classes/AutomationController.js
# Unblock zbw
RUN rm /etc/zbw/flags/no_connection

COPY run.sh .
RUN chmod a+x run.sh
COPY rootfs/ /

EXPOSE 8083
EXPOSE 8084
EXPOSE 8883

CMD /opt/z-way-server/run.sh
ENTRYPOINT ["/init"]
55 changes: 30 additions & 25 deletions zwave_me_server/config.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
name: Z-Wave.Me Add-on
startup: services
version: 4.1.0
version: v4.1.3
slug: zwave_me_server
description: 'Z-Wave.Me Z-Way add-on for Home Assistant'
startup: services # Determines when the add-on should start
arch:
- amd64
- aarch64
- armhf
url: https://github.com/z-wave-me/ha-z-wave-me-addon/
- armhf # Architectures the add-on can run on
init: false
host_network: true
host_dbus: true
uart: true
hassio_api: true

url: https://github.com/z-wave-me/ha-z-wave-me-addon/ # Add-on repository URL
image: "ghcr.io/z-wave-me/{arch}-ha-z-wave-me-addon" # Docker image for the add-on
ports:
8083/tcp: 8083
8084/tcp: 8084
8883/tcp: 8883
8083/tcp: 8083 # Main ports to forward
ports_description:
8083/tcp: Z-Way UI # Description for main ports
webui: http://[HOST]:[PORT:8083] # Add-on interface URL

options:
device: /dev/ttyAMA0
configjson_device_replace: false
remote_access: true
remote_support_access: false
zbw_password: razberry
local_ip: homeassistant.local
device: /dev/ttyAMA0 # Main device for connection
additional_devices: "" # Additional devices for connection
configjson_device_replace: false # Device configuration replacement
remote_access: true # Remote access to the add-on
remote_support_access: false # Remote support access
zbw_password: razberry # Access password
log_level: 6
schema:
device: device(subsystem=tty)
configjson_device_replace: bool?
remote_access: bool?
remote_support_access: bool?
zbw_password: str
local_ip: str
webui: http://[HOST]:[PORT:8083]
ports_description:
8083/tcp: Z-Way UI
8084/tcp: Webif UI
8883/tcp: MQTT server port (use port 8883 in the MQTT app)
image: "ghcr.io/z-wave-me/{arch}-ha-z-wave-me-addon"
device: device(subsystem=tty) # Schema for the main device
additional_devices: str # Schema for additional devices
configjson_device_replace: bool? # Schema for device configuration replacement
remote_access: bool? # Schema for remote access
remote_support_access: bool? # Schema for remote support access
zbw_password: str # Schema for password
log_level: int(0,6)
101 changes: 101 additions & 0 deletions zwave_me_server/rootfs/etc/cont-init.d/z-way-server-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/with-contenv bashio

bashio::log.info "Preparing Z-Way server to start..."

# Default config path
defCJ=/opt/z-way-server/automation/defaultConfigs/config.json

bashio::log.info "Checking and updating default config path..."

# Change device path in /defailtConfig/config.json
if [ -f "$defCJ" ]; then
jq --arg device "$(bashio::config 'device')" '.instances[0].params.port = $device' $defCJ > $defCJ.tmp && mv $defCJ.tmp $defCJ
bashio::log.info "Device path in default config updated."
else
bashio::log.warning "Default config not found."
fi

bashio::log.info "Processing folders and files for external /data directory..."

# Folders and files that we need to copy to the external /data directory
paths="/opt/z-way-server/automation/storage /opt/z-way-server/automation/userModules /opt/z-way-server/htdocs/smarthome/user/skin /opt/z-way-server/htdocs/smarthome/user/icons /etc/zbw"
for path in $paths; do
# Сheck the presence of the /data/ folder and the original server directories.
if [ -e $path -a ! -e /data/$path ]; then
# Make folders from the path variable with the exception of the last folder in the path
mkdir -p /data/`dirname $path`
# Moving files and folders from the standard directory to the /data folder
mv $path /data/$path
bashio::log.info "Moved ${path} to /data${path}."
else
rm -rf $path
bashio::log.info "Removed existing ${path}."
fi
# Creating symlinks to the objects that we moved
ln -sf /data$path $path
bashio::log.info "Created symlink for ${path}."
done

bashio::log.info "Processing default config directory..."

# Change default config directory to configs/config for compatility with Docker, HA and Hub
if [ -e /opt/z-way-server/config -a ! -e /data/opt/z-way-server/configs/config ]; then
# Change config path in defaultConfigs/config.json from config to configs/config
jq '.instances[0].params.config = "configs/config"' $defCJ > $defCJ.tmp && mv $defCJ.tmp $defCJ
# Make configs folder in external /data folder
mkdir -p /data/opt/z-way-server/configs/
# Move config folder from default docker image to external folder
mv /opt/z-way-server/config/ /data/opt/z-way-server/configs/
bashio::log.info "Moved default config directory."
else
# Jut remove config folder from docker image dirrectory
rm -rf /opt/z-way-server/config/
bashio::log.info "Removed existing default config directory."
fi

# Make simlinks
ln -sf /data/opt/z-way-server/configs/ /opt/z-way-server/
bashio::log.info "Created symlink for default config directory."

bashio::log.info "Setting local IP..."
echo "$(hostname -I | awk '{print $1}')" > /opt/z-way-server/automation/localIP.json


bashio::log.info "Processing user configjson file..."

# User configjson file path (using the known location)
userCJPath="/data/opt/z-way-server/automation/storage/configjson-"*.json

if [ ! -z "$(ls -A $userCJPath)" ]; then
bashio::log.info "User configjson file found: $(ls -A $userCJPath)"

# Get the value of configjson_device_replace option
replaceOption=$(bashio::config 'configjson_device_replace')

# If force device selection is enabled (replaceOption is not empty)
if [ -n "$replaceOption" ]; then
jq --arg device "$(bashio::config 'device')" '.instances[0].params.port = $device' $userCJPath > $userCJPath.tmp && mv $userCJPath.tmp $userCJPath
bashio::log.info "Device path in user config updated."

# Read and log the updated port value
updatedPort=$(jq -r '.instances[0].params.port' $userCJPath)
bashio::log.info "Updated port in configjson: $updatedPort"
else
bashio::log.info "Force device selection is disabled. Skipping port update."
fi
else
bashio::log.warning "User configjson file not found. This is expected on the first start."
fi

# Check if the logging level is a number between 0 and 6
if [[ "$(bashio::config 'log_level')" =~ ^[0-6]$ ]]; then
bashio::log.info "Setting log level to $(bashio::config 'log_level')"

# Use sed to modify the logging level in the config.xml file
sed -i "s|<log-level>.*</log-level>|<log-level>$(bashio::config 'log_level')</log-level>|" /opt/z-way-server/config.xml

else
bashio::log.error "Invalid log level: $(bashio::config 'log_level'). It should be a number between 0 and 6."
fi

bashio::log.info "Initialization script completed."
36 changes: 36 additions & 0 deletions zwave_me_server/rootfs/etc/cont-init.d/zbw_connect-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/with-contenv bashio

bashio::log.info "Preparing Z-Way server to start..."

echo "$(hostname -I | awk '{print $1}')" > /etc/zbw/local_ips
echo "$(bashio::addon.port 8083)" > /etc/zbw/local_port

# Check if remote access for support enable
if $(bashio::config 'remote_support_access'); then
touch /etc/zbw/flags/forward_ssh
elif [ -f "/etc/zbw/flags/forward_ssh" ]; then
rm /etc/zbw/flags/forward_ssh
fi

# Change support user default password
if [ -n "$(bashio::config 'zbw_password')" ]; then
echo "support:$(bashio::config 'zbw_password')" | chpasswd
fi

# If remote access enable start zbw_connect
if $(bashio::config 'remote_access'); then
if [ -f "/etc/zbw/userid" ]; then
userid=$(cat /etc/zbw/userid)
# Little fix for repair remote access on old instalation
if [ "$userid" = "191581" ]; then
bashio::log.info "Found problematic Remote Access ID. Reset it to get a new one."
wget 'http://find.z-wave.me/zbw_new_user?box_type=ha' -O /tmp/zbw_connect_setup.run && sudo bash /tmp/zbw_connect_setup.run -y
fi
fi

if [ -f "/etc/zbw/flags/no_connection" ]; then
rm /etc/zbw/flags/no_connection
fi
else
touch /etc/zbw/flags/no_connection
fi
22 changes: 22 additions & 0 deletions zwave_me_server/rootfs/etc/services.d/z-way-server/finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/with-contenv bashio

bashio::log.info "Stopping z-way-server..."

# Check if the PID file exists
if [ -f /var/run/z-way-server.pid ]; then
# Fetch the PID from the PID file
PID=$(cat /var/run/z-way-server.pid)

# Kill the process using the PID
kill $PID

# Wait for the process to terminate
wait $PID

# Remove the PID file
rm /var/run/z-way-server.pid

bashio::log.info "z-way-server has been stopped successfully!"
else
bashio::log.warning "z-way-server is not running or PID file is missing."
fi
Loading

0 comments on commit c304c29

Please sign in to comment.