Tellstick script

Moderator: leecollings

Post Reply
Marius
Posts: 4
Joined: Friday 12 September 2014 8:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Tellstick script

Post by Marius »

Hi,
Can You help me with tellstick workaroud?
I have Domoticz installed on raspberry pi.

My domoticz_main script looks like this:

Code: Select all

#!/bin/sh
set startup_path=%1
set hardware_id=%2
set device_id=%3
set status=%4
set status2=%5
set devname=%6

on="tdtool --on"
off="tdtool --off"

Lamp=1

if [ "$device_id" = 8 ] ; then
   if [ "$status" = "On" ] ; then
      $on $Lamp &
   else [ "$status" = "Off" ] ; then
      $off $Lamp & 
  fi
fi

Idx of a dummy switch is 8 but it doesn't work.

I can turn on and off my lamp from command line.

Any help will be appreciated.
User avatar
Conn-artist
Posts: 21
Joined: Saturday 12 July 2014 12:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8367
Location: 127.0.0.1
Contact:

Re: Tellstick script

Post by Conn-artist »

Hi,

I don't know the hardware nor exactly what you want to do, but perhaps it helps to include the whole path when you call tdtool, unless it's in your $PATH and that variable is known to the script.

I.e. on="/path/too/tdtool --on"

Just my $0.02
--
Martijn
Marius
Posts: 4
Joined: Friday 12 September 2014 8:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Tellstick script

Post by Marius »

No path needed for this.
There is an error in script on wiki page:
http://www.domoticz.com/wiki/Basic_Tell ... h_Domoticz


It should be:

Code: Select all

#!/bin/sh

startup_path=$1
hardware_id=$2
device_id=$3
status=$4
status2=$5
devname=$6

echo "startup_path=${startup_path}, hardware_id=${hardware_id}, device_id=${device_id}, status=${status}, status2=${status2}, devname=${devname}"

on="tdtool --on"
off="tdtool --off"


if [ "$device_id" = 7 ] ; then
 if [ "$status" = "On" ] ; then
      $on 1
else if [ "$status" = "Off" ] ; then
      $off 1
       fi
 fi
fi

now every thing works.
Brighthead
Posts: 2
Joined: Tuesday 11 November 2014 12:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Tellstick script

Post by Brighthead »

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
Pason67
Posts: 1
Joined: Wednesday 20 January 2016 20:53
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Tellstick script

Post by Pason67 »

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.
Works perfect, thanks.

My small addition is a small script to read tellstick sensors.

v.id == xx -> sensor id from telldus

commandArray[1]={['UpdateDevice']='22|0|' .. v.temperature .. ';' .. v.humidity .. ';' .. humStat}
where 22 is the id in domoticz.

Im not a programmer so sorry if code is not perfect.



Code: Select all

commandArray = {}
local file = {}
local f = assert(io.popen("tdtool --list-sensors")) -- runs command
lineTable ={}

sensors={}

for line in f:lines() do
        table.insert(lineTable,line)
 end -- for loop
f:close()

for k,v in pairs(lineTable) do

        t={}
        for w in lineTable[k]:gmatch("%S+") do
                time2=nil
                time2=string.match(w,('%d+:%d+:%d+'))
                if time2 then
                        w='time2=' .. time2
                end

                for k2, v2 in string.gmatch(w, "(.+)=(.+)") do
                        t[k2] = v2
                end
        end
        table.insert(sensors,t)
end

for k,v in pairs(sensors) do

        humStat=0
        if v.humidity then

                hum=tonumber(v.humidity)
                if (hum<=24) then humStat='2' -- dry
                elseif (hum>=61) then humStat='3'-- wet
                elseif (hum>=25 and hum<=60) then humStat='1' -- comfort
                end
        end



        if (tonumber(v.age) < 60) then

                if (v.id == '62') then -- ute
                        commandArray[1]={['UpdateDevice']='22|0|' .. v.temperature .. ';' .. v.humidity .. ';' .. humStat}
                end
                
                if (v.id == '11') then -- inne
                        commandArray[2]={['UpdateDevice']='23|0|' .. v.temperature .. ';' .. v.humidity .. ';' .. humStat}
                end

                if (v.id == '42') then -- källare
                        commandArray[3]={['UpdateDevice']='25|0|' .. v.temperature .. ';' .. v.humidity .. ';' .. humStat}
                end
        end
end


return commandArray
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: Tellstick script

Post by Nautilus »

Hi,

very interesting! :)

Can you explain a bit what the above script does in each step? I'm currently using mqtt / node red to fetch sensor data from Telldus Live to Domoticz, but there's some reliability issues with node red (keeps crashing quite often) so I'd be interested in finding another way. I'm able to use the Telldus-provided tdtool.py example to retrieve sensor data from Telldus Live: tdtool.py --list-sensors will list all sensors and last update time and tdtool.py --sensor-data ZYX will output the sensor info - two lines in following format:

Code: Select all

pi@raspberrypi ~/domoticz/scripts $ /usr/bin/python tdtool.py --sensor-data XYZ
Autotalli	temp		19.7	2016-06-05 00:30:05
Autotalli	humidity	61	2016-06-05 00:30:05
But I'd need some help to understand how I would scrape the needed temp and humidity values from the output and update it to Domoticz... 8-)
Rivvern
Posts: 6
Joined: Thursday 08 September 2016 10:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Tellstick script

Post by Rivvern »

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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest