Tag: service

Configure the Telldus Service – Part 2

In part 1 we assured that the service was following best practice in linux be creating a separate ‘telldus’ user and letting the device handle also be owned by that ‘telldus’ user.
Now it is time to configure the light switches for the Telldus service. The light switches are defined in several JSON data structures, one for each light switch. The format is defined by Telldus on the following page.

For example here is the definition from /etc/tellstick.config of two switches from Conrad:

device {
  id = 1
  name = "wallswitch1"  
  protocol = "risingsun"
  model = "selflearning:conrad"
  parameters {
    house = "31942"
    unit = "1"
  }
}
device {
  id = 2
  name = "wallswitch2"  
  protocol = "risingsun"
  model = "selflearning:conrad"
  parameters {  
    house = "32170"
    unit = "15"    
  }
}
The id is a simple identifier increased for each switch. The name is a symbolic name of the switch which is posssible to use in bash commands or when using one of the API to the telldus service. Protocol/model is often easy to find out either by looking at page or googling. The parameters are dependant on the protocol/model but in the case of the risingsun protocol these identifiers are learnt by the switch during the selflearning sequence.

Once the telldus.config file is finished – start or restart the telldus service:

/etc/init.d/telldus restart
[ ok ] Restarting the Telldus TellStick daemon: telldusd.

The command ‘tdtool’ is a command utility communicating with the telldus service. Here are some examples.
List the switches defined above:

> tdtool --list
Number of devices: 2
1 wallswitch1 OFF
2 wallswitch2 OFF
Learn a selflearning-switch the parameters:
> tdtool --learn wallswitchxx
Turning on a switch:
> tdtool --on wallswitch1
Turning off a switch:
> tdtool --off wallswitch1
 

Configure the Telldus Service – Part 1

First stop the service and then create a separate user ‘telldus’ with no login or home directory. The group ‘telldus’ which is connected to the ‘telldus’ user is also created.

/etc/init.d/telldusd stop
adduser --no-create-home --disabled-login --gecos "" telldus

Create the config file of the service daemon: ‘/etc/tellstick.conf’ and add the following two rows:

user = "telldus"
group = "telldus"

Now the service daemon will start up and change process owner to ‘telldus’.

Let’s focus on the tellstick device (in my case the tellstick duo). Connect it to the USB host port of the Raspberry Pi. Verify that it is detected and note the vendor id and product id:

> lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 004: ID 1781:0c31 Multiple Vendors Telldus TellStick Duo

The tellstick is detected which is shown at the last row, and vendor id: 1781/product id: 0c31.

The service daemon needs a device handle in /dev to be able to communicate with the device.

Newer kernels contains the udev subsystem handling plugindevices, making it possible to write a rule like: each time this device is plugged in, then create this type of device handle.

The tellstick device uses the FTDI HW component to make it easy to communicate using serial usb. The FTDI device driver is included with the kernel as a loadable device driver. A loadable device driver is possible to load dynamically by running the command ‘modprobe’.

Next step is to write a udev rule which matches the device (vendor id/product id) and runs the modprobe command as well as writing to /sys/bus/usb-serial/drivers/ftdi_sio/new_id to make the device handle appear.

Start by creating the file ’99-ftdi.rules’ in ‘/etc/udev/rules.d’:

ACTION==”add”, ATTRS{idVendor}==”1781″, ATTRS{idProduct}==”0c31″, RUN+=”/sbin/modprobe ftdi_sio” OWNER=”telldus” GROUP=”telldus” RUN+=”/bin/sh -c ‘echo 1781 0c31 > /sys/bus/usb-serial/drivers/ftdi_sio/new_id'”

This rule loads the FTDI driver and creates the device handle ‘/dev/ttyusb0’ owned by telldus.
Restart udev subsystem (making it reread all the the rules):

> udevadm control --reload

Verify that ‘/dev/ttyUSB0’ appears when inserting the tellstick device.

Finally we update the config file ‘/etc/tellstick.conf’ with the following line pointing out the device handle:

deviceNode = "/dev/ttyUSB0"