Skip to content
Isak Öberg edited this page Jun 5, 2014 · 9 revisions

Intro

The idea is to use a raspberry pi as a gateway for a rf24 arduino network that automate and monitor my house. I use code form http://www.mysensors.org for the ardunio network. This repository contains the code needed to collect, store, view and mange the ardunio network. From the start I hade the intention was to build the control ui arround the gateway. Today I moved away from that idea and will use Openhab for as frontend. I started to code some to support Domoticz but will not continue doing that since that API provided Domoticz is not good as of today.

Note this code is far from finished, it work to some extent but missing features and is under development during the few hour I have to spare. All python coders try not to cry your eys out, it's the first time I try to do something in python.

Note this is far from a next-next-finished installation. You must be able to code and get around a linux system

In the future I will add config examples for openhab.

Screenshots

over here you have the screenshoots

Chooses I made…

  • Beer - I like beer and a few were consumed...
  • Python – haven’t written a line of code before in Python. Choose python because I can learn something and the first idea was to integrate a module in to tatologger. I use tatologger for graphing my ground heat pump, sorry it's in swedish but google translate will help you out.
  • Tornado – was looking for something threaded that I could easily push info to and from. It's a threaded webserver written in python

Installation

This can be done much smolder but that’s for the futher. On the Raspberry Pi install the standard Raspbain – wheezy release

Clone the program from github:

git clone https://github.com/wbcode/ham.git

Install the python tornado, serial packages, and some others that I don't remember:

sudo apt-get install python-tornado python-serial python-requests python-rrdtool

Run

Get all the files from github and configure the config file and put it all in one directory. Then run the gateway program.

sudo python Gateway.py

Understanding the configuration in msgw.conf

[config]    
port = /dev/ttyACM0									# Serial port where the mysensor gateway is connected
baudrate = 115200    								# Default for my sensor
unit = M             								# (I/M) Metric or Imperial (I/M)
inclusion-mode = true   							# (true/false) If new sensors should be added automatically
rrd = true           								# (true/false) Enable store info in rrf files. You have to configure rrds session and create the files.
domoticz = true      								# (true/false) Enable Domoticz integration. Configure domoticzs session below
domoticz_url = http://10.10.11.119:8080/json.htm 	# Url to the Domoticz json API
openhab = true       								# (true/false) Enable Openhab integration. Configure Openhab session below
openhab_url = http://10.10.11.119:9090/rest/items/ 	# Url to the Openhab rest API

[httpd]
ip = 10.10.11.126    								# Listening IP for this gateway program.
port = 8000          								# Listening port for this gateway program.

 # Remove all id:s except 0;0, new sensor will be added automatically
[childIds]           								# ChildId = AltID <typeid> |  <;sketch name; sketch version> 
0 = 0;0              								# Gateway address have to be here
1 = 10;255;Humidity;1.0 							# Remove id, new sensor will be added automatically
2 = 10;0;7 											# Remove id, new sensor will be added automatically
3 = 10;1;6 											# Remove id, new sensor will be added automatically
4 = 11;255;Relay;1.0 								# Remove id, new sensor will be added automatically
5 = 11;3;3 											# Remove id, new sensor will be added automatically
6 = 11;4;3 											# Remove id, new sensor will be added automatically
7 = 12;255;Motion Sensor;1.0 						# Remove id, new sensor will be added automatically
8 = 12;0;1 											# Remove id, new sensor will be added automatically
9 = 13;255;Door01;1.0 								# Remove id, new sensor will be added automatically
10 = 13;3;0 										# Remove id, new sensor will be added automatically
11 = 14;255;RFIDandRGB;1.0 							# Remove id, new sensor will be added automatically
12 = 14;0;20 										# Remove id, new sensor will be added automatically
13 = 14;1;20 										# Remove id, new sensor will be added automatically

#You have to configure this section to map childid to the specific idx and type in Domoticz
[domoticz]     										# ChildId = idx;value type in Domoticz
2 = 3;nvalue   										# ChildId 2 is idx item 3 and value is stored in the nvalue parameter in Domoticz.
3 = 4;svalue   										# ChildId 3 is idx item 4 and value is stored in the svalue parameter in Domoticz.
													# You will have to dig deep in Domoticz to know how to interact with it.

#You have to configure this section to map childid to the specific rrd file
[rrds]         										# ChildId = filename of rrd file;DS name in rrd
2 = d10s1;hum  										# ChildId 2 should store info in d10s1.rrd using the DS value hum
3 = d10s0;temp 										# ChildId 3 should store info in d10s0.rrd using the DS value temp

#You have to configure this section to map childid to the specific Openhab itemname
[openhab]                  							# ChildId = Openhab itemname
2 = Humidity_FV_Mancave    							# ChildId maps to itemname Humidity_FV_Mancave in Openhab
3 = Temperature_FV_Mancave 							# ChildId maps to itemname Temperature_FV_Mancave in Openhab
5 = Relay1_FV_Mancave      							# ChildId maps to itemname Relay1_FV_Mancave in Openhab
6 = Relay2_FV_Mancave      							# ChildId maps to itemname Relay2_FV_Mancave in Openhab
8 = Motion_PIR1_FV_Mancave 							# ChildId maps to itemname Motion_PIR1_FV_Mancave in Openhab
10 = Motion_Door1_FV_Mancave 						# ChildId maps to itemname Motion_Door1_FV_Mancave in Openhab
12 = Info_Text_FV_Mancave 							# ChildId maps to itemname Info_Text_FV_Mancave in Openhab
13 = RGB_FV_Mancave 								# ChildId maps to itemname RGB_FV_Mancave in Openhab

Get Openhab to talk to the gateway

This can be done in two ways. Either you use build a rule or use the http binding. I have found the http binding a bit buggy.

Rule example in Openhab

This is configured in the rule file in openhab

rule "Set RGB value"
when
	Item RGB_FV_Mancave changed
then
	//you need to send com?oh=<item-name-in-openhab>&type=<item-type-in-openhab>&state=<the state you want ro send.>  
	sendHttpGetRequest("http://10.10.11.126:8000/com?oh=RGB_FV_Mancave&type=ColorItem&state="+  RGB_FV_Mancave.state)  
end

Example using the http binding

This is configured in the item file in openhab, All should be on one row.

Switch Relay1_FV_Mancave 	"Relay 1" 		(Relays, FV_Mancave) { http=">[ON:GET:http://10.10.11.126:8000/com?oh=Relay1_FV_Mancave&type=SwitchItem&state=%2$s] >[OFF:GET:http://10.10.11.126:8000/com?oh=Relay1_FV_Mancave&type=SwitchItem&state=%2$s]" }

Same as above but with line break to make it easier to read.

Switch Relay1_FV_Mancave 	"Relay 1" 		(Relays, FV_Mancave) 
{ http=">[ON:GET:http://10.10.11.126:8000/com?oh=Relay1_FV_Mancave&type=SwitchItem&state=%2$s] 
>[OFF:GET:http://10.10.11.126:8000/com?oh=Relay1_FV_Mancave&type=SwitchItem&state=%2$s]" }

Example reload configuraton from openhab.

In item file

Switch Gateway_reload_config "Reload Gateway config"

In rule file

rule "Reload Gateway Config" 
when
	Item Gateway_reload_config changed 
then
	if (Gateway_reload_config.state == ON) {
		sendHttpGetRequest("http://10.10.11.126:8000/com?op=reloadconfig")
		Thread::sleep(5000) 
		Gateway_reload_config.state = OFF
	}
end