diff --git a/tellstick/Dockerfile b/tellstick/Dockerfile new file mode 100644 index 0000000..310e607 --- /dev/null +++ b/tellstick/Dockerfile @@ -0,0 +1,27 @@ +ARG BUILD_FROM +FROM $BUILD_FROM + +ENV LANG C.UTF-8 + +# Install Telldus library for TellStick (using same approach as in hassio docker installation) +RUN apk add --no-cache \ + confuse libftdi1 libstdc++ jq socat \ + && apk add --no-cache --virtual .build-dependencies \ + cmake build-base gcc doxygen confuse-dev argp-standalone libftdi1-dev git \ + && ln -s /usr/include/libftdi1/ftdi.h /usr/include/ftdi.h \ + && mkdir -p /usr/src \ + && cd /usr/src \ + && git clone -b master --depth 1 https://github.com/telldus/telldus \ + && cd telldus/telldus-core \ + && sed -i "/\/a \#include \" common/Socket_unix.cpp \ + && cmake . -DBUILD_LIBTELLDUS-CORE=ON -DBUILD_TDADMIN=OFF -DBUILD_TDTOOL=ON -DGENERATE_MAN=OFF -DFORCE_COMPILE_FROM_TRUNK=ON -DFTDI_LIBRARY=/usr/lib/libftdi1.so \ + && make \ + && make install \ + && apk del .build-dependencies \ + && rm -rf /usr/src/telldus + +# Copy data for add-on +COPY run.sh / +RUN chmod a+x /run.sh + +CMD [ "/run.sh" ] diff --git a/tellstick/config.json b/tellstick/config.json new file mode 100644 index 0000000..0aee192 --- /dev/null +++ b/tellstick/config.json @@ -0,0 +1,37 @@ +{ + "name": "Tellstick", + "version": "0.1", + "slug": "tellstick", + "description": "Telldus Tellstick daemon and tools.", + "url": "https://home-assistant.io/addons/tellstick/", + "startup": "services", + "boot": "auto", + "devices": ["/dev/bus/usb:/dev/bus/usb:rwm"], + "options": { + "devices": [ + { + "id": 1, + "name": "Example device", + "protocol": "everflourish", + "model": "selflearning-switch", + "house": "A", + "unit": "1" + } + ] + }, + "schema": { + "devices": [ + { + "id": "int(1,)", + "name": "str", + "protocol": "match(arctech|brateck|everflourish|fuhaote|hasta|ikea|kangtai|risingsun|sartano|silvanchip|upm|waveman|x10|yidong)", + "model": "match(codeswitch|bell|selflearning-switch|selflearning-dimmer|selflearning|ecosavers|kp100)?", + "house": "str?", + "code": "str?", + "unit": "str?", + "fade": "str?" + } + ] + }, + "image": "homeassistant/{arch}-addon-tellstick" +} diff --git a/tellstick/run.sh b/tellstick/run.sh new file mode 100644 index 0000000..82cb263 --- /dev/null +++ b/tellstick/run.sh @@ -0,0 +1,66 @@ +#!/bin/bash +set -e + +CONFIG_PATH=/data/options.json +DEVICES=$(jq --raw-output '.devices | length' $CONFIG_PATH) + +echo "[Info] Initialize the tellstick configuration" + +# User access +echo "user = \"root\"" > /etc/tellstick.conf +echo "group = \"plugdev\"" >> /etc/tellstick.conf +echo "ignoreControllerConfirmation = \"false\"" >> /etc/tellstick.conf + +# devices +for (( i=0; i < "$DEVICES"; i++ )); do + DEV_ID=$(jq --raw-output ".devices[$i].id" $CONFIG_PATH) + DEV_NAME=$(jq --raw-output ".devices[$i].name" $CONFIG_PATH) + DEV_PROTO=$(jq --raw-output ".devices[$i].protocol" $CONFIG_PATH) + DEV_MODEL=$(jq --raw-output ".devices[$i].model // empty" $CONFIG_PATH) + ATTR_HOUSE=$(jq --raw-output ".devices[$i].house // empty" $CONFIG_PATH) + ATTR_CODE=$(jq --raw-output ".devices[$i].code // empty" $CONFIG_PATH) + ATTR_UNIT=$(jq --raw-output ".devices[$i].unit // empty" $CONFIG_PATH) + ATTR_FADE=$(jq --raw-output ".devices[$i].fade // empty" $CONFIG_PATH) + + ( + echo "" + echo "device {" + echo " id = $DEV_ID" + echo " name = \"$DEV_NAME\"" + echo " protocol = \"$DEV_PROTO\"" + + if [ ! -z "$DEV_MODEL" ]; then + echo " model = \"$DEV_MODEL\"" + fi + + if [ ! -z "$ATTR_HOUSE" ] || [ ! -z "$ATTR_CODE" ] || [ ! -z "$ATTR_UNIT" ] || [ ! -z "$ATTR_FADE" ]; then + echo " parameters {" + + if [ ! -z "$ATTR_HOUSE" ]; then + echo " house = \"$ATTR_HOUSE\"" + fi + if [ ! -z "$ATTR_CODE" ]; then + echo " code = \"$ATTR_CODE\"" + fi + if [ ! -z "$ATTR_UNIT" ]; then + echo " unit = \"$ATTR_UNIT\"" + fi + if [ ! -z "$ATTR_FADE" ]; then + echo " fade = \"$ATTR_FADE\"" + fi + + echo " }" + fi + + echo "}" + ) >> /etc/tellstick.conf +done + +echo "[Info] Run telldusd & socat" + +# Expose the unix socket to internal network +socat TCP-LISTEN:50800,reuseaddr,fork UNIX-CONNECT:/tmp/TelldusClient & +socat TCP-LISTEN:50801,reuseaddr,fork UNIX-CONNECT:/tmp/TelldusEvents & + +# Run telldus-core daemon +exec /usr/local/sbin/telldusd --nodaemon < /dev/null