Close

Apps... and IKEA Tradfri Support!

A project log for Switchboard: Distributed Automation made Easy

A small Python framework for the tinkerer to make distributed automation as simple as possible

josefschneiderjosefschneider 05/17/2017 at 05:490 Comments

Apps are standalone executables that can be configured, launched and terminated by Switchboard. The only requirement for an app is that it support a "--getconf" argument which prints to stdout a JSON representation of the app input arguments. For example, for the swb_system_info app, "--getconf" would return the following:

{"Client port": {"args": ["--client_port", "-cp"], "kwargs": {"help": "Switchboard client listening port"}}}

This allows Switchboard to know that this app has a "--client_port" argument. Switchboard knows what to do with this specific argument and silently populates it with an unused port number. This is followed by a silent "addclient" command so all the swb_system_info inputs are immediately available.

To make it easier to develop python Switchboard apps there are three classes to help you out: ClientApp (as per last log entry), IODataApp which gets a stream of all device value data, and ClientIODataApp in case you need both sets of functionality. All the app arguments are saved in the Switchboard config so that apps can automatically be launched at startup. Switchboard currently comes with a few apps out of the box, which are swb_system_info, swb_dashboard, swb_io_file_save, and... swb_tradfri!

IKEA Tradfri are cheap wireless lightbulbs for which you can control on/off, brightness and colour temperature (for the more expensive models). To get the lightblubs working you need at least one Tradfri LED bulb, one steering device and one network gateway, and you need to set them up through the IKEA Tradfri app. Install the coap-client (instructions in apps/swb_tradfri/README.md) on your Linux machine and you're ready to go:

Enter the gateway IP, the security code and a client alias and voilà! The app automatically detects all the connected devices and creates outputs to control them: we can power on/off and dim a group of bulbs with the group_<group id>_<action>.o outputs, and control each bulb individually with the bulb_<group id>_<bulb id>_<action>.o outputs. So to turn on a bulb, you only need to type:

set tradfri.bulb_0_0_power 1

Discussions