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

https://github.com/beinnlora/HiveHomeAPI-PHP

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:
curl.cainfo=/etc/ssl/certs/cacert.pem
then download the https://curl.haxx.se/ca/cacert.pem and save to above store.
If on windows, then replace with something like
curl.cainfo="C:\certs\cacert.pem
see stack exchange
http://stackoverflow.com/questions/6400300/https-and-ssl3-get-server-certificatecertificate-verify-failed-ca-is-ok

then in your /conf/script directory, store the script and class
git clone https://github.com/beinnlora/HiveHomeAPI-PHP.git
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
<?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

hive.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.