Bringing this thread back from the dead as i cannot seem to find a resolution to my problem.
*Domoticz raspberry pi image (domoticz-raspberrypi-sdcard-4834.7z)
*Running Domoticz v3.5637.
*Tellstick duo with service installed
*Dummy + Switch added with the same name as in tellstick.conf
*Added the script below in a new domoticz_main file
When i trigger a switch i get an error:
Code: Select all
2016-09-12 11:52:33.623 User: admin initiated a switch command
2016-09-12 11:52:33.623 (tellstick) Lighting 1 (001)
2016-09-12 11:52:33.738 Executing script: /home/pi/domoticz/scripts/domoticz_main
2016-09-12 11:52:33.760 Error: Error executing script command (/home/pi/domoticz/scripts/domoticz_main). returned: 512
If someone can enlighten me what the problem is i would be greatful.
Brighthead wrote:In the below script I've taken a slightly different path than in the scripts above: Instead of using the device id I use the device name. This means that the script does not need to be changed whenever I add or remove a device from Domoticz. Obviously tellstick.conf needs to be changed so that the devices have the exact same name in tellstick.conf and Domoticz.
I've also implemented basic DIM functionality in addition to just ON and OFF. This setup works perfectly for me. I'm running Domoticz and tdtool on a Raspberry B (256MB) with a USB-connected Tellstick (original).
Please let me know of any improvements you can see.
Note that the script requires BASH rather than SH as some builtin functionality is used.
Code: Select all
#!/bin/bash
startup_path=$1
hardware_id=$2
device_id=$3
status=$4
status2=$5
devname=$6
LOGFILE=<filename of logfile or /dev/null>
echo "startup_path=${startup_path}, hardware_id=${hardware_id}, device_id=${device_id}, status=${status}, status2=${status2}, devname=${devname}" >>$LOGFILE
# This part of the script interfaces with a Tellstick device via tdtool
#
# Requirements: A working Tellstick installation with tdtool and configured tellstick.conf
# All controlled devices needs to be defined with exactly the same name in tellstick.conf and Domoticz.
# The device type in Domoticz can be anything. I use X10 as I am not using that for anything else.
# To identify Tellstick devices a Dummy virtual device needs to be defined in Domoticz. I named it "Tellstick" and Domoticz
# assigned it hardware_id "2" which is what the logic below uses to determine if it is a Tellstick device
# Tellstick Hardware has hardware_id=2
if [ "${hardware_id}" = "2" ] ; then
# tdtool commands are always lowercase whereas Domoticz uses mixed case for status. tdcmd is either "on" or "off" after this
tdcmd=${status2,,}
# if command is to dim device we need to find dimlevel and set that
# Domoticz uses the status "Set Level: [n] %" where n is the dimlevel to use
tmp="${tdcmd%:*}"
if [ "$tmp" = "set level" ] ; then
# Get percentage which is found between : and %
tmp="${tdcmd#*:}"
dimlevel="${tmp//%/}"
# Tellstick dim level are 0-255 so we need to convert percentage
dimlevel=$((dimlevel*255/100))
# Set tdtool command to use
tdcmd="dim"
fi
# Execute Tellstick command
# We need both command and devname set to execute tdtool
if [ "${tdcmd}" != "" ] && [ "${tdcmd}" != "" ] ; then
if [ "${tdcmd}" = "dim" ] ; then
echo "Setting dim level for" $devname "to" $dimlevel >>$LOGFILE
tdtool --dimlevel $dimlevel --dim "$devname" >>$LOGFILE
else
echo "Changing" "$devname" "to" $tdcmd >>$LOGFILE
tdtool --$tdcmd "$devname" >>$LOGFILE
fi
fi
fi
# End of Tellstick section