From df3c7733f3d77e5990271fdeee99b692df854629 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Sat, 16 Dec 2017 02:57:52 +0100 Subject: [PATCH] Add homematic wired support (#214) --- homematic/CHANGELOG.md | 10 +++++ homematic/Dockerfile | 2 +- homematic/config.json | 36 +++++++++++++++--- homematic/hs485d.conf | 11 ++++++ homematic/rfd.conf | 2 - homematic/run.sh | 83 +++++++++++++++++++++++++++++++----------- 6 files changed, 114 insertions(+), 30 deletions(-) create mode 100644 homematic/CHANGELOG.md create mode 100644 homematic/hs485d.conf diff --git a/homematic/CHANGELOG.md b/homematic/CHANGELOG.md new file mode 100644 index 0000000..53d6321 --- /dev/null +++ b/homematic/CHANGELOG.md @@ -0,0 +1,10 @@ +# Changelog + +## 2.29.22-1-p1 + +- Change config logic +- Add support for wired + +## 2.29.22-1-p0 + +- Initial diff --git a/homematic/Dockerfile b/homematic/Dockerfile index 87a3296..567c32c 100644 --- a/homematic/Dockerfile +++ b/homematic/Dockerfile @@ -29,7 +29,7 @@ RUN curl -L -o occu.tar.gz https://github.com/eq-3/occu/archive/${OCCU_VERSION}. ENV HM_HOME=/opt/hm LD_LIBRARY_PATH=/opt/hm/lib:${LD_LIBRARY_PATH} # Update config files -COPY rfd.conf /etc/config +COPY rfd.conf hs485d.conf /etc/config # Setup start script COPY run.sh / diff --git a/homematic/config.json b/homematic/config.json index 8506054..3038651 100644 --- a/homematic/config.json +++ b/homematic/config.json @@ -1,6 +1,6 @@ { "name": "HomeMatic OCCU", - "version": "2.29.22-1-p0", + "version": "2.29.22-1-p1", "slug": "homematic", "description": "HomeMatic central based on OCCU", "url": "https://home-assistant.io/addons/homematic/", @@ -13,12 +13,38 @@ "2001/tcp": 2001 }, "options": { - "type": "CCU2", - "device": "/dev/ttyAMA0" + "rf_enable": true, + "rf": [ + { + "type": "CCU2", + "device": "/dev/ttyAMA0" + } + ], + "wired_enable": false, + "wired": [ + { + "serial": "xy", + "key": "abc", + "ip": "192.168.0.0" + } + ] }, "schema": { - "type": "match(CCU2)", - "device": "match(^/dev/.*$)" + "rf_enable": "bool", + "rf": [ + { + "type": "match(CCU2)", + "device": "match(^/dev/.*$)" + } + ], + "wired_enable": "bool", + "wired": [ + { + "serial": "str", + "key": "str", + "ip": "str" + } + ] }, "image": "homeassistant/{arch}-addon-homeassistant" } diff --git a/homematic/hs485d.conf b/homematic/hs485d.conf new file mode 100644 index 0000000..4107be9 --- /dev/null +++ b/homematic/hs485d.conf @@ -0,0 +1,11 @@ +# TCP Port for XmlRpc connections +Listen Port = 2000 + +Log Destination = None + +Persist Keys = 1 + +Device Description Dir = /opt/hm/firmware/hs485types +Device Files Dir = /data/hs485d +Firmware Dir = /opt/hm/firmware +User Firmware Dir = /data/firmware diff --git a/homematic/rfd.conf b/homematic/rfd.conf index 9baf51f..3209595 100644 --- a/homematic/rfd.conf +++ b/homematic/rfd.conf @@ -12,5 +12,3 @@ Address File = /data/ids Firmware Dir = /opt/hm/firmware User Firmware Dir = /data/firmware Replacemap File = /opt/hm/firmware/rftypes/replaceMap/rfReplaceMap.xml - -[Interface 0] diff --git a/homematic/run.sh b/homematic/run.sh index b19f1a5..9b73aa8 100644 --- a/homematic/run.sh +++ b/homematic/run.sh @@ -3,31 +3,70 @@ set -e CONFIG_PATH=/data/options.json -TYPE=$(jq --raw-output ".type" $CONFIG_PATH) -DEVICE=$(jq --raw-output ".device" $CONFIG_PATH) - -# Update config -if [ "$TYPE" == "CCU2" ]; then - ( - echo "Type = CCU2" - echo "ComPortFile = $DEVICE" - echo "AccessFile = /dev/null" - echo "ResetFile = /sys/class/gpio/gpio18/value" - ) >> /etc/config/rfd.conf -fi +RF_ENABLE=$(jq --raw-output '.rf_enable' $CONFIG_PATH) +RF_DEVICES=$(jq --raw-output '.rf | lenght' $CONFIG_PATH) +WIRED_ENABLE=$(jq --raw-output '.wired_enable' $CONFIG_PATH) +WIRED_DEVICES=$(jq --raw-output '.wired | lenght' $CONFIG_PATH) +WAIT_PIDS=() # Init folder mkdir -p /data/firmware -# Init GPIO -if [ ! -d /sys/class/gpio/gpio18 ]; then - echo 18 > /sys/class/gpio/export - sleep 2 -fi -if [ "$(cat /sys/class/gpio/gpio18/direction)" != "out" ]; then - echo out > /sys/class/gpio/gpio18/direction - sleep 2 +# RF support +if [ "$RF_ENABLE" == "true" ]; then + for (( i=0; i < "$RF_DEVICES"; i++ )); do + TYPE=$(jq --raw-output ".rf[$i].type" $CONFIG_PATH) + + # Update config + if [ "$TYPE" == "CCU2" ]; then + DEVICE=$(jq --raw-output ".rf[$i].device" $CONFIG_PATH) + ( + echo "[Interface $1]" + echo "Type = CCU2" + echo "ComPortFile = $DEVICE" + echo "AccessFile = /dev/null" + echo "ResetFile = /sys/class/gpio/gpio18/value" + ) >> /etc/config/rfd.conf + + + # Init GPIO + if [ ! -d /sys/class/gpio/gpio18 ]; then + echo 18 > /sys/class/gpio/export + sleep 2 + fi + if [ "$(cat /sys/class/gpio/gpio18/direction)" != "out" ]; then + echo out > /sys/class/gpio/gpio18/direction + sleep 2 + fi + fi + done + + # Run RFD + "$HM_HOME/bin/rfd" -c -l 0 -f /opt/hm/etc/config/rfd.conf & + WAIT_PIDS+=($!) fi -# Run RFID -"$HM_HOME/bin/rfd" -c -l 0 -f /opt/hm/etc/config/rfd.conf +# Wired support +if [ "$WIRED_ENABLE" == "true" ]; then + for (( i=0; i < "$WIRED_DEVICES"; i++ )); do + SERIAL=$(jq --raw-output ".wired[$i].serial" $CONFIG_PATH) + KEY=$(jq --raw-output ".wired[$i].key" $CONFIG_PATH) + IP=$(jq --raw-output ".wired[$i].ip" $CONFIG_PATH) + + # Update config + ( + echo "[Interface $1]" + echo "Type = HMWLGW" + echo "Serial Number = $SERIAL" + echo "Encryption Key = $KEY" + echo "IP Address = $IP" + ) >> /etc/config/hs485d.conf + done + + # Run hs485d + "$HM_HOME/bin/hs485d" -g -i 0 -f /opt/hm/etc/config/hs485d.conf & + WAIT_PIDS+=($!) +fi + +# Wait until all is done +wait "${WAIT_PIDS[@]}"