Controlling Hive via Domoticz

Hive from British Gas provides an excellent way to control your heating.  Setup is easy, you don’t need any existing home control equipment and the new-look thermostat is beautiful with its mirrored surface, colour display and satisfying prominent knob to twiddle… ahem.

hivetherm

There’s even a geolocation option in the app to remind you to switch off the heating if you leave home unexpectedly.  I thought, however, that it would be nice to immediately ‘stand down’ the heating as the last person in the flat left for the working day.  I have achieved this through Domoticz by modifying an excellent script from the Domoticz Forum (I can’t remember where – so please let me know in comments if you can point me to the thread to give the original poster the credit they deserve).

The following code is used as a LUA script (notice that I’ve set 4 virtual switches for this, one to turn the heating to 15C (our version of ‘off’), one to turn the heating to 20C (we call this ‘normal’), one for 22C (This is a boost to make the flat cosy) and the last switch to time the 22C state so that after half an hour, the heating reverts back to a more sustainable and energy saving temperature).


-- Set Hive thermostat

local HiveURL = 'https://api.hivehome.com/v5/'

local username = ‘email@email.com’

local password = 'passwordstring'

local loginhdr = '--location --data "username=' .. username .. '&password=' .. password .. '" '

local header = '--location -X PUT --data id=1 --data "temperature='

local tempcommand = '/widgets/climate/targetTemperature'

local tempUnit = '&temperatureUnit=C" '

local cookie = 'curl --cookie cookie.jar --cookie-jar cookie.jar '

local login = 'curl --cookie cookie.jar --cookie-jar cookie.jar --location --data "username=<HIVE USERNAME>&password=<HIVE PASSWORD>" https://api.hivehome.com/v5/login'

function round(num, idp)              -- Round number into manageable digits

local mult = 10^(idp or 0)

return math.floor(num * mult + 0.5) / mult

end

function LoginHive(self)

login = cookie .. loginhdr .. HiveURL .. 'login'

os.execute(login)

end

function UploadToHive(self)

upload = cookie .. header .. settemp .. tempUnit .. HiveURL .. "users/" .. username .. tempcommand

os.execute(upload)

end

function LogoutHive(self)

logout = cookie .. HiveURL .. 'logout'

os.execute(logout)

end

commandArray = {}

if devicechanged["TEMP Set to 15"] =='On' then

settemp = '15.0'

print ("Setpoint: " .. settemp .. " C")

commandArray["VAR Heating Boost"] = "Off"

commandArray["TEMP Set to 20"] = "Off"

commandArray["TEMP Set to 22"] = "Off"

LoginHive()

UploadToHive()

LogoutHive()

end

if devicechanged["TEMP Set to 22"] =='On' then

settemp = '23.5'

print ("Setpoint: " .. settemp .. " C")

commandArray["VAR Heating Boost"] = "On"

commandArray["TEMP Set to 20"] = "Off"

commandArray["TEMP Set to 15"] = "Off"

LoginHive()

UploadToHive()

LogoutHive()

end

if devicechanged["TEMP Set to 20"] =='On' then

settemp = '20.0'

print ("Setpoint: " .. settemp .. " C")

commandArray["VAR Heating Boost"] = "Off"

commandArray["TEMP Set to 22"] = "Off"

commandArray["TEMP Set to 15"] = "Off"

LoginHive()

UploadToHive()

LogoutHive()

end

return commandArray

Heating on the whole is managed by the Hive itself, so that fine-tuning to the heating can be done via the thermostat or the Hive app on our mobile devices.

The interface to Domoticz is used to select from the 3 heating operating modes as mentioned above.  The display polls Domoticz to work out which heating option is currently selected and then ‘lights’ that icon up.  This gives positive feedback to the user as to which heating mode has been selected.

glow1

Hive seem to be breaking into the Home Automation market in more ways that just heating.  For example, we have been sent a Hive Plug.  This appears to serve two purposes: the first to extend the radio range of the Hive system (to act like a WiFi extender but purely for the Hive signals) and second to control a device plugged into the Hive Plug.  There is currently no option to do this via the app so I am assuming an update will occur soon to allow users to do this.

hiveplug

Any unneeded heating costs money and energy, so from both the environmental and financial benefits, if this implementation saves 2 hours of heating a week, that is the equivalent of over 4 days of excess heating per year saved.

2 thoughts on “Controlling Hive via Domoticz”

Leave a comment