mirror of
https://github.com/aljazceru/addons.git
synced 2026-02-23 05:44:24 +01:00
OpenZWave 0.5.2 (#1489)
* OpenZWave 0.5.2 * Fix typo in code comment * LTW -> LWT * Convert mosquitto.conf dos2unix * Add additional MQTT bridge settings * Change client name to match add-on slug * Extract MQTT logic into a helper * Disable shellcheck SC1091
This commit is contained in:
22
zwave/rootfs/etc/cont-finish.d/mqtt.sh
Normal file
22
zwave/rootfs/etc/cont-finish.d/mqtt.sh
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Ensure upstream MQTT server has the correct OZW status retained on shutdown.
|
||||
# ==============================================================================
|
||||
# shellcheck disable=SC1091
|
||||
source /usr/lib/mqtt_helper.sh
|
||||
|
||||
declare host
|
||||
declare password
|
||||
declare port
|
||||
declare username
|
||||
|
||||
if bashio::services.available "mqtt"; then
|
||||
bashio::log.info "Ensure upstream MQTT server has the correct OZW status"
|
||||
host=$(bashio::services "mqtt" "host")
|
||||
password=$(bashio::services "mqtt" "password")
|
||||
port=$(bashio::services "mqtt" "port")
|
||||
username=$(bashio::services "mqtt" "username")
|
||||
|
||||
mqtt::ensure_ozw_offline_status \
|
||||
"${host}" "${port}" "${username}" "${password}"
|
||||
fi
|
||||
@@ -1,7 +1,10 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Setup mqtt settings
|
||||
# Setup MQTT settings
|
||||
# ==============================================================================
|
||||
# shellcheck disable=SC1091
|
||||
source /usr/lib/mqtt_helper.sh
|
||||
|
||||
declare host
|
||||
declare password
|
||||
declare port
|
||||
@@ -18,6 +21,11 @@ else
|
||||
(
|
||||
echo "connection main-mqtt"
|
||||
echo "address ${host}:${port}"
|
||||
echo "remote_clientid zwave"
|
||||
echo "local_clientid zwave"
|
||||
echo "cleansession true"
|
||||
echo "notifications true"
|
||||
echo "try_private true"
|
||||
) >> /etc/mosquitto.conf
|
||||
|
||||
# Need auth?
|
||||
@@ -33,5 +41,13 @@ else
|
||||
echo "topic # IN OpenZWave/"
|
||||
) >> /etc/mosquitto.conf
|
||||
|
||||
bashio::log.info "Connect to internal MqTT service"
|
||||
# Ensure upstream MQTT server has the right OZW status
|
||||
# Workaround for an incorrect retained OZW status in MQTT
|
||||
# In this case, the LWT is not relayed to the upstream MQTT server.
|
||||
# https://github.com/home-assistant/hassio-addons/issues/1462
|
||||
mqtt::ensure_ozw_offline_status \
|
||||
"${host}" "${port}" "${username}" "${password}"
|
||||
|
||||
|
||||
bashio::log.info "Connected to internal MQTT service"
|
||||
fi
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
##
|
||||
# defaults
|
||||
listener 1883
|
||||
user root
|
||||
|
||||
##
|
||||
# logging
|
||||
log_dest stdout
|
||||
|
||||
##
|
||||
# datastore
|
||||
persistence true
|
||||
persistence_location /data/
|
||||
|
||||
##
|
||||
# auth
|
||||
allow_anonymous false
|
||||
password_file /data/auth.db
|
||||
|
||||
# Dynamic config
|
||||
##
|
||||
# defaults
|
||||
listener 1883
|
||||
user root
|
||||
|
||||
##
|
||||
# logging
|
||||
log_dest stdout
|
||||
|
||||
##
|
||||
# datastore
|
||||
persistence true
|
||||
persistence_location /data/
|
||||
|
||||
##
|
||||
# auth
|
||||
allow_anonymous false
|
||||
password_file /data/auth.db
|
||||
|
||||
# Dynamic config
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
# ==============================================================================
|
||||
# Start OpenZWave service for zwave radio
|
||||
# ==============================================================================
|
||||
# shellcheck disable=SC1091
|
||||
source /usr/lib/mqtt_helper.sh
|
||||
|
||||
export MQTT_PASSWORD
|
||||
export OZW_NETWORK_KEY
|
||||
|
||||
@@ -20,6 +23,12 @@ fi
|
||||
bashio::log.info "Starting OpenZWave..."
|
||||
bashio::net.wait_for 1883
|
||||
|
||||
# Ensure local MQTT server has the right OZW status
|
||||
# Workaround for an incorrect retained OZW status in MQTT
|
||||
# https://github.com/home-assistant/hassio-addons/issues/1462
|
||||
mqtt::ensure_ozw_offline_status \
|
||||
127.0.0.1 1883 ozw "${MQTT_PASSWORD}" "${OZW_INSTANCE}"
|
||||
|
||||
# Send out discovery information to Home Assistant
|
||||
./discovery &
|
||||
|
||||
|
||||
56
zwave/rootfs/usr/lib/mqtt_helper.sh
Normal file
56
zwave/rootfs/usr/lib/mqtt_helper.sh
Normal file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# MQTT helpers for the zwave add-on.
|
||||
# ==============================================================================
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Ensure upstream MQTT server has the correct OZW status retained on shutdown.
|
||||
#
|
||||
# Arguments:
|
||||
# $1 MQTT Server host
|
||||
# $2 MQTT Server port
|
||||
# $3 MQTT Server username
|
||||
# $4 MQTT Server password
|
||||
# $5 OZW Instance ID (optional)
|
||||
# ------------------------------------------------------------------------------
|
||||
function mqtt::ensure_ozw_offline_status() {
|
||||
local host=${1}
|
||||
local port=${2}
|
||||
local username=${3}
|
||||
local password=${4}
|
||||
local ozw_instance=${5:-}
|
||||
local ozw_status
|
||||
|
||||
bashio::log.trace "${FUNCNAME[0]}:" "$@"
|
||||
|
||||
if ! bashio::var.has_value "${ozw_instance}"; then
|
||||
ozw_instance=1
|
||||
if bashio::config.has_value 'instance'; then
|
||||
ozw_instance=$(bashio::config 'instance')
|
||||
fi
|
||||
fi
|
||||
|
||||
ozw_status=$(\
|
||||
mosquitto_sub \
|
||||
--host "${host}" \
|
||||
--port "${port}" \
|
||||
--username "${username}" \
|
||||
--pw "${password}" \
|
||||
-C 1 \
|
||||
-W 3 \
|
||||
--retained-only \
|
||||
--topic "OpenZWave/${ozw_instance}/status/" \
|
||||
)
|
||||
if bashio::var.has_value "${ozw_status}" \
|
||||
&& [[ $(bashio::jq "${ozw_status}" ".Status") != "Offline" ]];
|
||||
then
|
||||
mosquitto_pub \
|
||||
--host "${host}" \
|
||||
--port "${port}" \
|
||||
--username "${username}" \
|
||||
--pw "${password}" \
|
||||
--retain \
|
||||
--topic "OpenZWave/${ozw_instance}/status/" \
|
||||
--message "$(bashio::var.json "Status" "Offline")"
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user