Tag: json

Defining a Configuration Schema File for the Switches

There are a number of switches in the house, most of them controlling lamps but also other things like the printer for example. Most of the switches are of the brand ‘Nexa’ and selflearning which makes it easy to control using the tellstick.
A new switch has to be configured in two different ways. The first configuration file is the tellstick.conf used by the telldus service daemon. In this configuration file, the id is specified as well as the name and the protocol of the switch. It is quite easy to find the protocol name of the 433 MHz communication by looking into wikis/forums of telldus.
The second configuration file is the one defining the on/off intervals of the switches. First of all having a separate file defining the intervals gives the possibility to differ between intervals at normal occasion and trip/vacation.
The format of the configuration file is json-format since it is very easy to read directly into a python program. In more detail it is a list of all switches where each switch has a structure containing a textual description, the device id in telldus, and the schema/interval defined as either always (on), never (on), sun, night, or : 

   "text" : "textual description e.g. lamp in working room",
   "name" : "device id in telldusd",   "schema" : schema either "always", "never", "sun", "night", ":"

The schema/interval sun is defined as turning switch on 40 minutes before sunset and then turning it off at a defined bed time which is one o´clock at night.

Here is an excerpt from the existing normal.json of the house:

        "text" : "Prydnadslampa 1",
        "name" : "wallswitch3",
        "schema" : "sun"
        "text" : "Pappas sänglampa",
        "name" : "wallswitch4",
        "schema" : "always"
        "text" : "Linneas sofflampa",
        "name" : "wallswitch5",
        "schema" : "night"

In vacation.json the second switch above, the schema is changed from ‘always’ to ‘sun’ to give an illusion of somebody in the bedroom (does it fool anybody? – probably not).

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