Friday, 13 January 2017

Hive Home OpenHAB2

display hive home temperatures in OpenHAB2
I started on a crude PHP class to return Hive current temperature and setpoint to OpenHAB2

Make sure PHP>=5.6 is installed and working, along with CURL and SSL certificates

I had to configure php.ini to add the line:
then download the and save to above store.
If on windows, then replace with something like
see stack exchange

then in your /conf/script directory, store the script and class
git clone
cd /opt/openhab2/conf/scripts
chown openhab:openhab HiveHomeAPI-PHP
cd HiveHomeAPI-PHP
chown openhab:openhab

then create a new php script for, e.g current temperature in your /conf/scripts/HiveHomeAPI-PHP directory,
nano currenttemp.php
/*example code - replace your credentials below with your hivehome details*/
include ("class.hivehome.php");
$hive = new HiveHome("hiveusername", "hivepw");
print $hive->getCurrentTemperature()."\n";
//print "Target Temp: ".$hive->getCurrentTemperature()."\n";
set ownership and permissions
sudo chown openhab:openhab currenttemp.php
sudo chmod +x currenttemp.php

then create a new Item in your /conf/items

Number Temperature_Hive "Temperature [%.1f °C]" <temperature> (gHiveTemps1) [ "CurrentTemperature" ] {exec="<[php /opt/openhab2/conf/scripts/HiveHomeAPI-PHP/currenttemp.php:60000:REGEX((.*?))]"}

then add it to your sitemap.

Wednesday, 2 November 2016


Paper UI: Extensions-->bindings--> add MQTT Broker
Create/edit the file /opt/openhab2/conf/Services/mqtt.cfg

Sample mqtt.cfg

//client ID - unique string - anything

//username - your ADAFRUIT IO username

//password is your AIO KEY

//other items can be left alone

Sample ITEM definition, for a NUMBER feed from the Adafruit feed key "templogger1"

Number temperaturelog "temperature [%.1f]" {mqtt="<[adafruit:myusername/feeds/templogger1:state:default]"}

note that compared to the demo in the  documentation, there is no leading / on the topic. This caused me a big headache!


Text item=temperaturelog label="Adafruit temperature feed"

There is an issue with the system remembering old MQTT broker settings. You can clear out all previous MQTT settings via the openhab2 Karaf console:
Adjust your mqtt.conf as needed, then in the console
config:edit org.openhab.mqtt

restart openhab2

Tuesday, 1 November 2016

Lighwaverf OpenHAB 2 (And amazon echo dot)

Ubuntu 14.04LTS x64
Java 1.8.0_111
Openhab2 2.0.0b4 2.0.0 -SNAPSHOT build #560 offline manual install, as per
(therefore my openhab2 is installed under /opt/openhab2) - adjust where necessary. 1.x compatibility was already enabled in this release

1 - create file opt/openhab2/conf/Services/openhab.cfg and populate with the sample lighwaverf binding configuration as per
I left alone - the default IP using the broadcast address worked for me.

2 - copy the lighwaverf binding jar (version 1.9.0) from snapshot build (link below), into /opt/openhab2/addons/
When I copied the .jar file over, my lightwave hub immediately started blinking saying "add app?", so I clicked YES.
The default settings for looking for the device on the broadcast IP worked!
Depending on how you copied the file over (I used filezilla from my windows machine to the linux server) You might have to check permissions are set properly; I configured it as per manual install to run under user:group openhab, and changed owner of conf/services/openhab.cfg and addons/opt.xxxx.lighwavexxxx.jar to openhabuser&group

3 - create an Openhab "Item" in /opt/openhab2/conf/Items (I appended the demo.items file) - one line for each of your switches/dimmers etc - this is where you need to customise your individual device/switch/dimmer/mood. here's a sample switch in room 2, device 3: (sudo nano /opt/openhab2/conf/Items/demo.items)
Switch LWRF_light1 "bedside light" { lightwaverf="room=2,device=3,type=SWITCH" }

4 - create a switch in a Sitemap, so you can control it from the GUI:
Switch item=LWRF_light1 label="Bedside Light"

that's it - check the events.log or log:tail command

The above creates the OpenHAB lightwaverf switch

You also need to create a Hue Switch in OpenHAB that can be detected by the Amazon Echo
(the Amazon Echo OpenHAB bridge turns your OpenHAB into an emulated Philips Hue system, which Echo then detects/controls)
Then you can link the Lightwaverf switch to the Hue switch using a Rule (or probably some more elegant method)
updated guide below:
1) install OpenHAB2 somewhere on your home network
From the PaperUI interface to openHAB2
2) Install Amazon Echo Bridge (Philips Hue emulation)
Extensions–>Misc–>Hue Emulation
(further reading)
3) Install Lighwaverf binding 1.9.0 (not fantastically userfriendly at the moment in openHAB2) see
4) Create an Item in OpenHAB conf/items, that will control the Lightwaverf switch
Switch LWRF_light1 “bedside light” { lightwaverf=”room=2,device=3,type=SWITCH” }
5) Create an emulated HUE Item in OpenHAB, that Echo can control – see e.g.
Switch HUE_LWRF_light1 “bedside light Echo” [ "Switchable" ]
6) create a rule in /opt/openhab2/conf/rules (e.g. demo.rules), to update your lightwaverf switch state when you update the Echo/hue switch
**there will probably be a more elegant way of doing this, using bindings or something **
// ECHO TO LIGHTWAVE – when Amazon Echo switch is updated, also update the lightwaverf switch
rule “LWRF bedside light”
Item HUE_LWRF_light1 received command
println (“command”)
sendCommand(LWRF_light1, receivedCommand)
7) Turn on Pairing in OpenHAB (Configuration–>Services–Hue Emulation–>Start
8) Ask alexa “Alexa, discover devices”. It will then discover the new HUE switch, that you control using the description you gave to the item (e.g. “Bedsite light”)
9) Create a switch in your openhab Sitemap, if you also want to control via your openHAB gui. Create it for the HUE switch rather than the LWRF switch and it will mirror the commands sent via Echo.
Switch item=HUE_LWRF_light1 label=”Bedside Light”

Monday, 31 October 2016

find my iphone using amazon dash button openhab

Using Amazon Dash Button and OpenHab2 to find my iphone

2.0.0-SNAPSHOP build #560
instructions as per

follow install pcap4j, including permissions for running as non-root:

then for the java path I did
whereis java
then ls -l /usr/bin/java
ls -l /etc/alternatives/java

setcap cap_net_raw,cap_net_admin=eip /usr/lib/jvm/java-8-oracle/jre/bin/java

started openHAB script
sudo su -s /bin/bash -c '/opt/openhab2/' openhab

let it run 15 mins - check GUI ok, then restarted it

on my router, I noted down all current DHCP leases, then followed the dash button setup until the point of choosing button, then stopped, then looked for new DHCP lease and found the MAC address AC-63-BE-XX-XX-XX, gave it a fixed IP assignment then blocked it in the router firewall for WAN access.

enable amazon dash binding in Paper UI - click install

when happy, press the button and the Dash button appears as a Thing in inbox!
click the tick in the Inbox to add the dash button as a Thing.
make a note of the CHANNEL that the dashbutton publishes its events to, something like

Now you can just add a rule in /opt/openhab2/conf/rules
sudo nano dashbuttons.rules

rule "Dash button pressed" when Channel "amazondashbutton:dashbutton:ac-63-be-xx-xx-xx:press" triggered then
println("The Dash button has been pressed") end

change owner to openhab as per the install guide,

sudo chown openhab:openhab dashbuttons.rules

What got me was that the usual approach of Thing < -- bind with channel --> Item isn't followed. The dash button is a pure Thing with channel trigger - no Item to bind to - no Item State/Command to run in a rule

Discussion here:

Now, get the PHP 'find my iphone' library
as per
(adapted for OH2)
cd /opt/openhab2/conf/scripts
sudo git clone git://
sudo cp PHP-FindMyiPhone/class.findmyiphone.php .
UPDATE Jan 2017 - ensure you use version of pull request 12th Jan 2017 or later as API has changed.

You may also need to install/configure PHP for SSL certificates

edit php.ini and add/uncomment line

then download the and save to above store.
If on windows, then replace with something like

sudo wget --no-check-certificate
sudo wget --no-check-certificate
sudo wget --no-check-certificate

#Edit listiclouddevices.php with your iCloud username (email) and password

cd /opt/openhab2/c
sudo nano listiclouddevices.php

#Run it to find your deviceID
#DeviceID will be something like Eu4EGWK1Yt5+2JtKM7YNA++hxNtDw4ZzZuwT9BLxYcL2d7FaULCJMuHYVNSUzmXV<
php ./listiclouddevices.php

#Edit turnoniphone.php, turnoffiphone.php
#with username, password and deviceID
sudo nano turnoniphone.php
sudo nano turnoffiphone.php

#Run scripts to test
php ./turnoniphone.php
php ./turnoffiphone.php

Permissions are a sticky point.
After creating php scripts, I changed all files in openhab2 to be owner:openhab, group openhab
for the manual install, this is
sudo chown -hR openhab:openhab /opt/openhab2

I also added my linux user to the group openhab, for ease of editing:
sudo usermod -a -G openhab myusername

Sunday, 30 October 2016

Openhab2 beginner's guide

my own hints for starting from scratch with openhab2 - not a step-by-step guide!

openhab2 installation location  (ubuntu 14.04)

depends on whether you manually install or install from repo:

openhab 1 bindings in openhab2?
in 2.0.0.B4+ (and probably earlier) the 1.x compatibility binding is already enabled.
Copy your 1.x .jar file into /opt/openhab2/addons.
Create/edit /opt/openhab2/conf/Services/openhab.cfg and add your 1.x binding configuration there
check the Karaf log or openhab.log for any issues.

lightwaverf binding openhab2

SEE DEDICATED POST LATER IN BLOG - requires nightly build 1.9.0 of addon.

get openhab1 lightwaverf binding from github
copy the openhab binding lightwaverf into /usr/share/openhab2/addons
I did this via filezilla local sftp to my linux box, having first done:
#add my username to the openhab group  (replace myusername as needed)
sudo usermod -a -G openhab myusername
# give the openhab group permissins to the addons folder
sudo chmod g+rws usr/share/openhab2/addons

then I can unzip on windows the 1.8.3 - move the lightwaverf jar across to usr/share/openhab2/addons

at this point, my lightwaverf hub asked immediately to authorise the app - I did nothing else - no config yet!

in /etc/openhab2/services, create file openhab.cfg
copy the supplied lightwaverf config into it, i.e. from

now I'm stuck - not available in bindings in Paper UI - error in log about lightwaverf missing addBinding method...

openhab2 console

- for checking the 1.x compatibility layer is installed - it was by defulat

More up-to-date openhab1 binding for lightwaverf available from openhab nightly build:

Monday, 5 September 2016

Multiple LoRa clients on one frequency - how to synchronise multiple LoRa transmitters using GPS

Implementing a time division multiple access scheme for single channel non-LoRaWAN access network, we need to synchronise each transmitter's TX window in order to maximise channel capacity.

We start by working out the TX window length (based on payload, LoRa parameters, receiver gain recovery rate etc). 12 bytes of data allows us lat/long to ~10m precision. vBat to 8 bit resolution plus plus other bytes for general purpose flags.

We then use the Semtech LoRa calculator program to determine a tradeoff between on-air time and SNR margin .
* We want maximum SNR to get the best range.
* We want to minimise on-air time as our trackers are moving, and we want to squeeze as many trackers onto one radio channel as possible.
* We want to minimise bandwidth if possible, are our trackers will have greatly varying temperatures and supply voltages/currents so frequency stability might not be great.
* we want our receiver to be able to recover its AGC circuitry and have sufficient processing power/message buffering queue to be able to pick out successive transmissions (if too closely spaced and densely transmitted, the limiting factor might be our receiver, not our transmitters)

We then decide how often we want to receive position updates - a tradeoff in refresh rate and remote battery life.

We then work out how tight a timing/synchronising loop we can achieve using the available hardware (48MHz onboard clock, GPS PPS synchronisation driving hardware interrupts

We can then design our TDMA scheme around these parameters.

For me, 30 second position updates is more than adequate. I would want to fit around 100 devices on one radio channel.
Rounding numbers up gives us 120 devices transmitting once every 30 seconds, or one transmission every 250 milliseconds.

Monday, 22 August 2016

traccar-web with custom offline maps

traccar-web interface to
* allows URL sign-on and better mobile interface

quick and dirty method - replace opensteetmap tile url with local tilestache server tiles

get file-roller (archive manager):

sudo apt-get install gnome-common
sudo apt-get install yelp

git clone

install and traccar-web as per their respective installers - confirm working.

On linux system you can open /opt/traccar/traccar-web.war with archive manager, edit files then re-pack quite easily. (installed default in ubuntu 12.0.4 

We are concentrating on the mobile interface
change any references to CDN cloudflare css or js libraries to point to "js/{name of js" or "css/{name..." as required.
then download and add the css or js file to the traccar-web.war/js/ or /css within the archive and re-pack the grml file