This app will be deprecated soon in favor of: https://github.com/otonchev/homefrog

"If the temperature in the room drops below 10C, Turn the fan heater On,
 If the fan heater is Turned On then Turn the oil heater Off.
 If the temperature outside exceeds 25C and it is Sunday, Turn a device
 On.
 Obtain temperature readings every 5th minute and store them in a MySQL
 database.
 Monitor air quality in an environment by measuring the dust
 concentration(PM2.5) and store the result into a MySQL database."

project web: http://otonchev.github.io/smarthomeproject_kanin/

The SmartHomeProject installation

The SmartHomeProject "Kanin"

This is the open-source project Kanin which will help you automate your lighting/heating system and thus significantly cut electricity costs. All you need to do in order to set up the project at your home is connecting a couple of hardrware devices and installing the SmartHomeProject software.

Example installation: http://ogy.noip.me:3456/scripts/web_api.py

Hardware:

Minimum hardware required for the installation:

  1. A Linux computer, preferably a Raspberry Pi development board.

  2. Hardware devices based on desired setup

Example scenario: Monitoring air temperature and controlling heaters For this setup the following devices are required:

2.1. 1-Wire Digital Thermometer network(DoIt yourself), 2 options are supported:

2.2. USB-stick radio frequency transmitter, For the moment the Telldus stick is only supported, More information here: www.telldus.se

2.3. A set of wall-plug socket receivers, self-learning or regular ones

Total cost for a complete installation with 10-15 temperature sensors all around the house is about 100 eur.

Software:

The SmartHomeProject application is open source and is quite easily extensible by PLUGINS. Plugins are implemented in C/GObject and share a common interface. The application controls them in an uniform way. Implementing new plugins is easy, just follow the templates.

Existing plugins for the moment:

"telldus" for emitting radio frequency signals and thus turning on/off wall-plug sockets. (read at the end for info on how to set it up)

"grovedust" for monitoring the air quality in an environment by measuring the dust concentration(Particulate matter PM2.5) with the Grove Dust sensor(Shinyei PPD42NS). Works on Raspberry Pi.

"ds1820digitemp" for obtaining readings from the 1-Wire Serial network (digitemp needs to be installed and running, read at the end)

"raspberrygpio" for reading sensors directly attached to the GPIO (w1-gpio and w1-therm kernel modules need to be loaded)

"dayschedule" for triggering events based on Day and Time

"mysql" for storing data generated by plugins into a MySQL database

"dummy" is a dummy plugin to be able to create configurations where actions are not of an interest. For example when monitoring sensors and answering queuries about readings.

Plugins currently under development:

"sendmail" for sending data generated by plugins over an e-mail

Plugins structure:

  +---------------+                                +---------------+
  | <<interface>> |                                | <<interface>> |
  |    OneWire    |                                |     Radio     |
  +---------------+                                +---------------+
         ^          +---------+<------------------------+ ^
         |          |ShpPlugin|<--------------------+   | |
         |______    +---------+<------------+       |   | |
                |     ^   ^                 |       |   | |
                |     |   |                 |       |   | |
          +------------+ +--------------+ +--------+|+----------+
          |ShpBase1wire| |ShpDayschedule| |ShpMysql|||ShpTelldus|
          +------------+ +--------------+ +--------+|+----------+
                 ^^                                 |
                 ||                           +------------+
                 |+-----------+   OneWire<----|ShpGroveDust|
                 |            |               +------------+
    +-----------------+ +----------------+
    |ShpDs1820digitemp| |ShpRaspberrygpio|
    +-----------------+ +----------------+

Each rule is normally a combination of plugins, for example "If the temperature outside exceeds 25C and it is Sunday, Turn a device On" will be internally represented as a group(ShpGroup) of 3 plugins(ShpPlugin) linked with each other using pads(ShpPad):

+----------------------------------------------------------+
| group0                                                   |
| +----------------------+              +----------------+ |
| |                +-----|              |-----+          | |
| | ds1820digitemp | pad |--------------| pad | telldus  | |
| |                +-----|              |-----+          | |
| +----------------------+              |                | |
|                                       |                | |
| +----------------------+              |                | |
| |                +-----|              |-----+          | |
| | dayschedule    | pad |--------------| pad |          | |
| |                +-----|              |-----+          | |
| +----------------------+              +----------------+ |
|                                                          |
+----------------------------------------------------------+

Another example is monitoring temperature in a room and logging measurements so that later they can be visualised:

    +----------------------------------------------------------+
    | group1                                                   |
    | +----------------------+         +---------------------+ |
    | |                +-----|         |-----+               | |
    | | dayschedule    | pad |---------| pad | mysql         | |
    | |                +-----|         |-----+               | |
    | +----------------------+         +---------------------+ |
    |                                                          |
    +----------------------------------------------------------+

Unlimited number of groups can be configured and run simultaneously.

To Download, Build and Run the application:

git clone https://github.com/otonchev/smarthomeproject_kanin.git kanin
cd kanin

only first time you need to type:

aclocal
autoconf
automake --add-missing

and then:

./configure
make
G_MESSAGES_DEBUG=all \
    ./src/shp /home/pi/project/kanin/src/shp.config

Note that setting DISPLAY=:0 before running the application may be necessary in some cases in order for the DBus stuff to work.

DISPLAY=:0 G_MESSAGES_DEBUG=all \
    ./src/shp /home/pi/project/kanin/src/shp.config

Configuration file can be changed while the application is running, in order for the new configuration to take effect the following command must be issued:

gdbus call --session -d com.shp.Shp -o /com/shp/Shp \
    -m com.shp.Shp.ReloadConfig

DBus Interfaces:

com.shp.Radio:

Devices can be Manually Turned On and Off and their status checked over DBus while the application is running.

This command will turn off device 2 using "telldus" module:

pi@raspberrypi ~ $ gdbus call --session -d com.shp.Radio \
    -o /com/shp/Radio -m com.shp.Radio.TurnOff 2 "telldus0"

This command will turn on device 2 using "telldus" module:

pi@raspberrypi ~ $ gdbus call --session -d com.shp.Radio \
    -o /com/shp/Radio -m com.shp.Radio.TurnOn 2 "telldus0"

This command will show whether a device is turned on or off:

pi@raspberrypi ~ $ gdbus call --session -d com.shp.Radio \
    -o /com/shp/Radio -m com.shp.Radio.GetStatus 2 "telldus0"

Return values:

          -1 - some error has occured
           1 - device is turned on
           0 - device is turned off
           2 - device's status is unknown

com.shp.OneWire:

Sensor readings can be obtained over DBus with the following command:

gdbus call --session -d com.shp.OneWire -o /com/shp/OneWire \
    -m com.shp.OneWire.GetReading 1 "ds1820digitemp0"

where "1" is the device id, in this case the id from the Digitemp configuration file which is part of the digitemp installation. When running sensors directly connected to GPIO this must be the device name on the disk(see somewhere below).

com.shp.Shp:

To get a list of all supported properties by a particular plugin:

gdbus call --session -d com.shp.Shp -o /com/shp/Shp \
    -m com.shp.Shp.GetPluginSpec "telldus"

To get a list of all supported plugins:

gdbus call --session -d com.shp.Shp -o /com/shp/Shp \
    -m com.shp.Shp.GetPluginList

To force the application re-load the configuration file after an update:

gdbus call --session -d com.shp.Shp -o /com/shp/Shp \
    -m com.shp.Shp.ReloadConfig

The configuration file:

The configuration file must specify where plugins(.so files) are located on the disk, look at the 'PluginDir' parameter below. By default all plugins will be compiled in src/plugins/.libs/

The example below configures 4 events:

  1. IF temperature in the Living room drops below 15C THEN turn Heater On
  2. IF temperature in the Living room goes above 20C THEN turn Heater Off
  3. IF day of week is Tuesday, Thursday or Saturday and time is 13:25 THEN turn Lamp On
  4. IF day of week is Tuesday, Thursday or Saturday and time is 16:25 THEN turn Lamp Off
  5. Obtain temperature readings from Living room every 5 minutes and store them into a MySQL database. Note that according to the given example a MySQL database should be created first and in the following manner:

    mysql -h localhost -u root -ppass CREATE DATABASE SensorReadings; use SensorReadings; CREATE TABLE SensorReadings (SensorReading FLOAT, ID VARCHAR(60), \ Time TIMESTAMP);

The 'config-dir' folder is where the digitemp config file needed by the 'ds1820digitemp' plugin is placed.

>vi /home/pi/project/kanin/src/shp.config

[program]
PluginDir=/home/pi/kanin/src/plugins/.libs/

# All action configurations used by the application

[conf0]
Name=Temperature Living Room less than 15C
Plugin=ds1820digitemp
config-dir=/home/pi/digitemp/
device-id=2
trigger=15.0
descending=1
id=ds1820digitemp20

[conf1]
Name=Temperature Living Room greater than 20C
    Plugin=ds1820digitemp
config-dir=/home/pi/digitemp/
device-id=2
trigger=20.0
descending=0
id=ds1820digitemp21

[conf2]
Name=Heater Living Room On
Plugin=telldus
device-id=1
set-on=1
id=telldus20

[conf3]
Name=Heater Living Room Off
Plugin=telldus
device-id=1
set-on=0
id=telldus21

[conf4]
Name=Lamp Living Room On
Plugin=telldus
device-id=2
set-on=1
id=telldus22

[conf5]
Name=Lamp Living Room Off
Plugin=telldus
device-id=2
set-on=0
id=telldus23

[conf6]
Name=Tuesday, Thursday and Saturday at 13:25
Plugin=dayschedule
hour=13
minutes=25
monday=0
tuesday=1
wednesday=0
thursday=1
friday=0
saturday=1
sunday=0
id=dayschedule20

[conf7]
Name=Tuesday, Thursday and Saturday at 16:25
Plugin=dayschedule
hour=16
minutes=25
monday=0
tuesday=1
wednesday=0
thursday=1
friday=0
saturday=1
sunday=0
id=dayschedule21

[conf8]
Name=Temperature Living Room
Plugin=ds1820digitemp
config-dir=/home/pi/digitemp/
device-id=2
interval=300
id=ds1820digitemp22

[conf9]
Name=Store temperature
Plugin=mysql
database=SensorReadings
table=SensorReadings
wsername=root
password=pass
id=mysql20

# A set of rules for action configurations

[rule0]
If=0
Then=2

[rule1]
If=1
Then=3

[rule2]
If=6
Then=4

[rule3]
If=7
Then=5

[rule4]
If=8
Then=9

Web Interface And Android App:

The web interface is a bit basic for now. It is possible to obtain sensor readings/device status, turning devices on and off plus creating and updating configurations. Check web/README for more information.

Web interface: https://github.com/otonchev/smarthomeproject_kanin/blob/master/images/web.png Plotting temperatures: https://github.com/otonchev/smarthomeproject_kanin/blob/master/images/plot.png

web interface web interface

Installing the Telldus stick on Raspberry Pi(for the "telldus" module):

sudo vi /etc/apt/sources.list

and add:

deb http://download.telldus.com/debian/ stable main

sudo apt-key adv --fetch-keys \
    http://download.telldus.se/debian/telldus-public.key
sudo apt-get update
sudo apt-get install -y telldus-core libftdi1
sudo apt-get install -y libtelldus-core-dev

then run:

sudo /etc/init.d/telldusd status

to verify that it is up and running.

Then add some devices and try to turn them on and off:

vi /etc/tellstick.conf

user = "nobody"
group = "plugdev"
deviceNode = "/dev/tellstick"
ignoreControllerConfirmation = "false"
device {
    id = 1
    name = "Livingroom1"
    controller = 1
    protocol = "risingsun"
    model = "codeswitch"
    parameters {
        house = "2"
        unit = "1"
    }
}
device {
    id = 2
    name = "Livingroom2"
    controller = 1
    protocol = "risingsun"
    model = "codeswitch"
    parameters {
        house = "2"
        unit = "2"
    }
}
controller {
    id = 1
    type = 1
    serial = "A4004GCS"
}

Restart telldusd:
sudo /etc/init.d/telldusd restart

pi@raspberrypi ~ $ tdtool --on 2
pi@raspberrypi ~ $ tdtool --off 2

Setting up digitemp (for the "ds1820digitemp" module):

Install digitemp and run:

digitemp_DS9097 -w -s /dev/ttyUSB0 
DigiTemp v3.6.0 Copyright 1996-2007 by Brian C. Lane
GNU General Public License v2.0 - http://www.digitemp.com
Turning off all DS2409 Couplers
.....
Devices on the Main LAN
1038860A020800C2 : DS1820/DS18S20/DS1920 Temperature Sensor
10EE9F7402080086 : DS1820/DS18S20/DS1920 Temperature Sensor
1065800A0208003A : DS1820/DS18S20/DS1920 Temperature Sensor
10D3DB74020800D7 : DS1820/DS18S20/DS1920 Temperature Sensor
1007770A02080060 : DS1820/DS18S20/DS1920 Temperature Sensor

And create digitemp.conf

pi@raspberrypi ~/digitemp $ vi digitemp.conf
TTY /dev/ttyUSB0
READ_TIME 1000
LOG_TYPE 1
LOG_FORMAT "Room %s: %.1C C"
CNT_FORMAT "%b %d %H:%M:%S Sensor %s #%n %C"
HUM_FORMAT "%b %d %H:%M:%S Sensor %s C: %.2C F: %.2F H: %h%%"
SENSORS 5
ROM 0 0x10 0x38 0x86 0x0A 0x02 0x08 0x00 0xC2
ROM 1 0x10 0xEE 0x9F 0x74 0x02 0x08 0x00 0x86
ROM 2 0x10 0x65 0x80 0x0A 0x02 0x08 0x00 0x3A
ROM 3 0x10 0xD3 0xDB 0x74 0x02 0x08 0x00 0xD7
ROM 4 0x10 0x07 0x77 0x0A 0x02 0x08 0x00 0x60

pi@raspberrypi ~/digitemp $ digitemp_DS9097 -c \
    /home/pi/digitemp/digitemp.conf -a -q
0 14.8
1 13.5
2 17.3
3 17.4
4 17.4

Note that the configure file shown above must be modified with device ids matching your devices and placed in the "PluginConfigDir" directory. This is important since the "ds1820digitemp" module will need it.

GPIO directly (for the "raspberrygpio" module):

sudo modprobe w1-gpio pullup=1
sudo modprobe w1-therm

and:

ls -l /sys/bus/w1/devices

to see all the temperature sensors.

And finally:

cat /sys/bus/w1/devices/<sensor_id>/w1_slave

to read temperature.

Roadmap:

What follows:

  1. Improve Web interface
  2. Android application

About:

Feel free to send comments/suggestions/patches to: otonchev@gmail.com Greetings!