Home automation

For the last 2 years I have been using Indigo Domotics and have been very satisfied with that. It’s a very easy way to start building home automation and getting something to work fast for testing an automation concept. However I want to move to some hardware with a smaller footprint instead of my mac mini. So I have decided to try out OpenHAB for Raspberry Pi

The internet of things are coming to a house near you, in a future not so far away any more…

Getting the hardware for OpenHAB

First up I have bought a RapberryPi 2 model b, a Raspberry Pi Universal Power Supply, NOOBS 8GB SD Card and a Wifi/bluetooth USB dongle. Most of it you can get at the raspberry swag shop .

Second up I needed a z-wave modul for my Raspberry Pi. I had a USB dongle for my mac mini – but since that was being used for what I had working already I have decided to try the Raspberry PI Board from z-wave.me.

You will also need a monitor and HDMI cable and maybe a converter to you monitor if it’s using VGA monitor – and of course a mouse and a keyboard.

Oh and while we are at it – if you don’t have Philips HUE – now is the time to get it 🙂

 

Instaling RASPBIAN JESSIE

It is pretty straight forward, fist you need to download the operating system for your Raspberry Pi – you do that from raspberrypi.org.

Being on a mac I used mac tutorial for instaling the operating system on the Raspberry Pi SD card but if you use a windows or linux you can find the on the website as well.

Nice terminal commands to know:

Will take you to the basic setup of the RASPBIAN
$ sudo raspi-config

If you disable the RASPBIAN to boot into the visual userinterface X-server you can enable it by typing
$ startx

 

Making the RaZberry work on my RapberryPi

OK – I ended up starting over and reinstalling Raspian Jessie and using the tutorial from homeautomationforgeeks.com. This also guide you through installing HABmin that gives you a web interface for connecting and configuring z-wave devices.

This guide from homeautomationforgeeks.com tells you how to install OpenHab in a better way

The only thing missing in this tutorial is that you need to make a openhab.cfg file the configurations directory, by copying openhab_default.cfg

You do that from the terminal by typing:
sudo cp /opt/openhab/configurations/openhab_default.cfg /opt/openhab/configurations/openhab.cfg

This guide from homeautomationforgeeks.com tells you how to make z-wave work, now I didn’t want to start out by enabling my multi sensor but instead I started out by playing with my Fibaro smoke sensor – go and see later post.

The two above links from homeautomationforgeeks.com don’t have the enabling og SMB shares – however you can find those guides the makeuseof.com link I have posted earlier. Keep in mind that the installation of OpenHAB now is in the /opt directory and your share definition now must be:


[OpenHAB Home]
comment= OpenHAB Home
path=/opt/openhab
browseable=Yes
writeable=Yes
only guest=no
create mask=0777
directory mask=0777
public=no

You also need a user since the openhab user isn’t uses in the opt installation you need to decide if you want that.
You asign a SMB user  by typing:
sudo smbpasswd -a [username]

So far these sites have been helpfull:
http://raspberrypi.stackexchange.com
https://community.openhab.org 

OpenHAB Designer installation

I am having some problems with making rules work using HABmin, I can make them work but when I want to edit them OpenHAB stops working and I have to reboot. I still need HABmin to handle my z-wave devices though…

OpenHAB Designer is local programming and designing environment and this is why it is a good thing to have SMB enabled for your OpenHab. To make it work you need to either change permissions on the directories OpenHAB Designer needs to access or sign into the share as root after you have given the root user access to the Openhab share…  both solutions have their own security issues and you should change it back when you are in “production”.

Now is a good time to make a backup image of you OpenHAB installation!

Fibaro smoke sensor Configuration i OpenHab

I included my Fibaro Smoke sensor from HABmin by pressing the inclusion button on my smoke sensor – OpenHAB included it but didn’t get the vendor information right away – but after pressing the inclusion button 3 times again it turned up nicely.

In the Items directory I have added this configuration to my default.items file:

Group All
Group Security (All)
Group SmokeSensors "Kitchen" (Security)
Switch Smoke_Sensor_smoke "Smoke detected in kitchen [%s]" (SmokeSensors) { zwave="4:command=sensor_alarm,alarm_type=1" }
Switch Smoke_Sensor_tampered "Smoke sensor kitchen tampered [%s]" (SmokeSensors) { zwave="4:command=sensor_alarm,alarm_type=0" }
Number Smoke_Sensor_battery "Smoke sensor kitchen battery [%s %%]" (SmokeSensors) { zwave="4:command=BATTERY" }
Number Smoke_Sensor_temp "Kitchen temperature [%.1f C]" (SmokeSensors) { zwave="4:command=SENSOR_MULTILEVEL,sensor_type=1" }
DateTime Smoke_Sensor_updated "Last updated [%1$td/%1$tm/%1$tY %1$tH:%1$tM:%1$tS]" (SmokeSensors) { zwave="4:command=info,item=LAST_UPDATE" }

And this configuration to my default.sitemap  file

sitemap default label="Main Menu"
{
Frame label="Kitchen" {
Text item=Smoke_Sensor_smoke
Text item=Smoke_Sensor_tampered
Text item=Smoke_Sensor_battery
Text item=Smoke_Sensor_temp
Text item=Smoke_Sensor_updated
}
}

Finally I have added two rules to notify me on a push notification if the alarm is trickered:


import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

rule “PushoverSmokeSensorInKitchenTampered”
when
Item Smoke_Sensor_tampered changed
then
if (Smoke_Sensor_tampered.state.toString()== “ON”) {
pushover(“Smoke Sensor Tampered”, “NameOnMyiPhoneOnPushoverWebsite”)
}

logInfo(“Smoke_Sensor_tampered changed: “,Smoke_Sensor_tampered.state.toString())
end

 

And …


import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

rule “PushoverSmokeSensorInKitchenTriggered”
when
Item Smoke_Sensor_smoke changed
then
if (Smoke_Sensor_smoke.state.toString()== “ON”) {
pushover(“Smoke detected in kitchen”, 2)
}

logInfo(“Smoke_Sensor_smoke changed: “,Smoke_Sensor_smoke.state.toString())
end

 

 

OpenHAB becoming aware of me… so to speak

I need my home to know if anybody is at home. On my Indigo installation I used to check if our iPhones were visible on the wifi network buy the latency was to long and I would normally get to far inside the house before I was discovered as my and the alarm would be trickered instead. So for OpenHAB I am working on using bluetooth instead.

First of I got hold of a USB bluetooth for my pi – and installed the drivers needed  for it to work and modified the examples on this page: https://github.com/openhab/openhab/wiki/Samples-Tricks I didn’t use the bluetooth binding but used org.openhab.binding.exec to be able to execute command line from OPenHAB

In the OpenHAB Scripts directory I added the bt_check.sh to ping for my iPhones bluetooth MAC address

#!/bin/bash

DEVICES=`l2ping F5:F2:7A:05:CB:7A -c 1`

if [[ $DEVICES = *received* ]]
then
curl –max-time 2 –connect-timeout 2 –header “Content-Type: text/plain” –request PUT –data “ON” http://192.168.1.112:8080/rest/items/TSiPhone/state
echo “Bluetooth pingscript has been executed. Device found” >> /opt/openhab/logs/openhab.log
else
curl –max-time 2 –connect-timeout 2 –header “Content-Type: text/plain” –request PUT –data “OFF” http://192.168.1.112:8080/rest/items/TSiPhone/state
echo “Bluetooth pingscript has been executed. Device not found >> /opt/openhab/logs/openhab.log
fi

In the  Items directory I added the file BlutoothState.items
Switch TSiPhone

In my sitemap file I added this to the file:
Frame label="Bluetooth devices" {

Switch item=TSiPhone label=”TSiPhone” icon=””
}

And finally I added bluetoothPing.rules to the rules directory to trickier the bt_check.sh bluetooth ping script every 30 sek.


import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

rule “BluetoothPingRules”
when
Time cron “0,30 * * * * ?”
then

var String command
command = “/opt/openhab/configurations/scripts/bt_check.sh”
executeCommandLine(command, 20000)

end

…now I need to make it a little more intelligent, first thing is probably to ping me less when it has seen me …

This link was helpfull: https://www.raspberrypi.org/learning/robo-butler/bluetooth-setup/
I used this to install command wassudo apt-get install –no-install-recommends bluetooth