Read British Gas Hive Heating temperature

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.

Moderator: leecollings

Calzor Suzay
Posts: 145
Joined: Tuesday 08 July 2014 15:10
Target OS: -
Domoticz version: 4.9700
Location: UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by Calzor Suzay »

With Beta 4.10445 with v1 it installs and runs.
Need to check stability but i still see errors

This gets repeated often though:-
2019-02-20 22:59:21.387 Error: CConnection_connect, connect request from 'Hive1' ignored. Transport is connected.
2019-02-20 22:59:22.771 Error: (Hive1): Async Secure Read Exception: 1, stream truncated
mark.sellwood
Posts: 102
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by mark.sellwood »

Keep an eye on memory usage.
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
sach
Posts: 111
Joined: Wednesday 12 October 2016 14:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Read British Gas Hive Heating temperature

Post by sach »

Started receiving these errors today:

2019-04-04 19:09:24.915 Error: (Hive) 'onMessage' failed 'KeyError'.
2019-04-04 19:09:24.915 Error: (Hive) ----> Line 860 in '/home/pi/domoticz/plugins/Hive/plugin.py', function onMessage
2019-04-04 19:09:24.915 Error: (Hive) ----> Line 155 in '/home/pi/domoticz/plugins/Hive/plugin.py', function onMessage
2019-04-04 19:09:24.915 Error: (Hive) ----> Line 496 in '/home/pi/domoticz/plugins/Hive/plugin.py', function UpdateDeviceState


Anyone else or just me?
sach
Posts: 111
Joined: Wednesday 12 October 2016 14:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Read British Gas Hive Heating temperature

Post by sach »

Unfortunately the plugin is unusable for me now. :-(
Worked fine for months and nothing changed but all of a sudden it causes domoticz to crash and misses schedules.
I have zwave TRV's and temperature sensors in every room and Hive is used simply as a relay to switch the boiler on.
Will have to look for another solution.
mark.sellwood
Posts: 102
Joined: Tuesday 04 March 2014 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Surrey, UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by mark.sellwood »

Same with me, I had to stop using it as it consumes all the memory over a few days then crashes domoticz.
I think something must have changed at the Hive end.
3 x Pi, 1 Master, 2 Slaves, 1x Aeotec Z-Stick S2, 4xSP103 PIR, 5xPowerNode 1, 1xSmart Energy Switch Gen5, 4xFGSS101 Smoke Sensor, 2xFGD212, 9xFGS212 , 7xFGS221/2, 1xAD142 , 1xTKB TZ68E , 2xAeotec Multi Sensor, 3 x NodOn CRC-3-1-00.
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by MikeF »

As the OP of this thread,I've produced python scripts to read Hive current and target temperatures, and display these in Domoticz. I installed the Hive plugin a while ago, but I experienced a number of errors, so I stopped using it. I've been using the python script happily (i.e., my RPi is happy!) for several years - I don't have Hive smart plugs or lights, etc., so I've not extended the script to these.

I've posted my latest version below, which may be of use if all you want to do is monitor your Hive heating - it uses the more recent Hive API (https://beekeeper.hivehome.com). To use it, create 2 dummy temperature devices (current, target), and a dummy switch (heating status), and enter the idx's in the script; also enter your Domoticz url and port, and Hive username and password.

ImageImage
Spoiler: show

Code: Select all

#!/usr/bin/env python

import requests
import json
import urllib3
from time import sleep, strftime
from datetime import datetime, timedelta

urllib3.disable_warnings()

# substitute Domoticx idx's below

insideIdx  = 'xxx'	# Hive current temperature
targetIdx  = 'xxx'	# Hive target temperature
heatingIdx = 'xxx'	# Heating status - on / off

# substitute Domoticz url and port below

DomoReadURL   = 'http://<url:port>/json.htm?type=devices&rid='
DomoWriteURL  = 'http://<url:port>/json.htm?type=command&param=udevice&nvalue=0&idx='
DomoSwitchURL = 'http://<url:port>/json.htm?type=command&param=switchlight&idx='

# Hive username and password

username = '<xxx>'
password = '<xxx>'

###

false = False
true = True
timedout = 2880 # minutes: 2 days
debug = True

def domoticzRead(idx, var):
   url = DomoReadURL + idx
   response = requests.get(url)
   jsonData = json.loads(response.text)
   result = jsonData['result'][0][var]
   return result;

def sensorTimedOut(idx):
	datestring = domoticzRead(targetIdx, 'LastUpdate')
	
	def LastUpdate(datestring):
		dateformat = "%Y-%m-%d %H:%M:%S"
		# the below try/except is meant to address an intermittent python bug in some embedded systems
		try:
			result = datetime.strptime(datestring, dateformat)
		except TypeError:
			result = datetime(*(time.strptime(datestring, dateformat)[0:6]))
		return result
		
	return LastUpdate(datestring) + timedelta(minutes=timedout) < datetime.now()

# Hive

# log on to Hive
payload = {'username':username, 'password':password, 'devices':true, 'products':true}
headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
url = 'https://beekeeper.hivehome.com:443/1.0/global/login'
r = requests.post(url, headers=headers, data=json.dumps(payload), verify=False)

#print(json.dumps(r.json(), indent=2))

sessionId = r.json()["token"]
#print sessionId

data = r.json()["products"]
len = len(data)

# find which node has heating data
key = "heating"
heating = False
for i in range(len):
	name = data[i]["state"]["name"]
	type = data[i]["type"]
	if key == type:
		nodeId = data[i]["id"]
		thermostat = i

# get values from Hive
target 	= r.json()["products"][thermostat]["state"]["target"]
temp   	= r.json()["products"][thermostat]["props"]["temperature"]
	
stateHeatingRelay = target > temp
if stateHeatingRelay: 
	heating = "On"
else:
	heating = "Off"

# log out from Hive
headers = {'Content-Type': 'application.json', 'Accept': 'application.json', \
	'X-AlertMe-Client': 'Hive Web Dashboard', 'Authorization': sessionId}
url = 'https://beekeeper-uk.hivehome.com/1.0/auth/logout'
r = requests.delete(url, headers=headers, verify=False)

# Domoticz

# get last values from Domoticz
last_temp	= domoticzRead(insideIdx, 'Temp')
last_target = domoticzRead(targetIdx, 'Temp')
last_heating = domoticzRead(heatingIdx, 'Status')

# change some values
temp = round(temp, 1)

if target < 7.0: target = 7.0

if debug:
	print '       ', 'new','old'
	print 'temp   ', temp, last_temp
	print 'target ', target, last_target
	print 'heating', heating, last_heating

# send values to Domoticz (only send if changed)
if temp != last_temp:
	url = DomoWriteURL + insideIdx + '&svalue=' + str(temp)
	r = requests.get(url)

if (target != last_target) or (sensorTimedOut(targetIdx)):
	url = DomoWriteURL + targetIdx + '&svalue=' + str(target)
	r = requests.get(url)

if heating != last_heating:
	url = DomoSwitchURL + heatingIdx + '&switchcmd=' + heating
	r = requests.get(url)

(Incidentally, this runs under Python 2.7; I haven't tried it under Python 3.x, so I don't know what - if any - changes are needed.)
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by MikeF »

I've just come across what I believe is a bug in the Hive API - looking at the json output, the target value

Code: Select all

target = r.json()["products"][thermostat]["state"]["target"]
is changing one hour later than it should (compared to the schedule). I suspect this bug was introduced on the recent change to BST.

I'll investigate a workaround.
sach
Posts: 111
Joined: Wednesday 12 October 2016 14:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Read British Gas Hive Heating temperature

Post by sach »

Thanks Mike, I will give it a shot.

Don't suppose you could code in hot water support :-)
sach
Posts: 111
Joined: Wednesday 12 October 2016 14:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Read British Gas Hive Heating temperature

Post by sach »

I think i may have solved the errors with the Python plugin by removing the bulbs and just leaving the heating.
I run Zigbee2MQTT and switched one of the bulbs over to it some time ago, but got lazy and left the other bulb on the Hive hub.
I just removed the 2nd bulb so I only have heating and hot water left and the error have stopped appearing in the logs.

This is on the 0.7 version of the plugin.
Will see how it goes for a while but its looking promising :-)
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by MikeF »

I've amended my script to include support for hot water - there are various places in the code where it says 'uncomment for hot water'. Note that I haven't tested this, as i now only have a (combi) heating system (so hot water is on demand), although I still have the Hive 2-channel receiver.

Also, I've included code to get the target temperature by parsing the 'schedule' object, to get round the bug I reported earlier.
Spoiler: show

Code: Select all

#!/usr/bin/env python

import requests
import json
import urllib3
from time import sleep, strftime
from datetime import datetime, timedelta

urllib3.disable_warnings()

# substitute Domoticx idx's below

insideIdx  = 'xxx'	# Hive current temperature
targetIdx  = 'xxx'	# Hive target temperature
heatingIdx = 'xxx'	# Heating status - on / off
# uncomment for hot water
#hotwaterIdx= 'xxx'  # Hot water status - on / off

# substitute Domoticz url and port below

DomoReadURL   = 'http://<url:port>/json.htm?type=devices&rid='
DomoWriteURL  = 'http://<url:port>/json.htm?type=command&param=udevice&nvalue=0&idx='
DomoSwitchURL = 'http://<url:port>/json.htm?type=command&param=switchlight&idx='

# Hive username and password

username = '<xxx>'
password = '<xxx>'

###

false = False
true = True
timedout = 2880 # minutes: 2 days
debug = True

def domoticzRead(idx, var):
   url = DomoReadURL + idx
   response = requests.get(url)
   jsonData = json.loads(response.text)
   result = jsonData['result'][0][var]
   return result;

def sensorTimedOut(idx):
	datestring = domoticzRead(targetIdx, 'LastUpdate')
	
	def LastUpdate(datestring):
		dateformat = "%Y-%m-%d %H:%M:%S"
		# the below try/except is meant to address an intermittent python bug in some embedded systems
		try:
			result = datetime.strptime(datestring, dateformat)
		except TypeError:
			result = datetime(*(time.strptime(datestring, dateformat)[0:6]))
		return result
		
	return LastUpdate(datestring) + timedelta(minutes=timedout) < datetime.now()

# Hive

# log on to Hive
payload = {'username':username, 'password':password, 'devices':true, 'products':true}
headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
url = 'https://beekeeper.hivehome.com:443/1.0/global/login'
r = requests.post(url, headers=headers, data=json.dumps(payload), verify=False)

#print(json.dumps(r.json(), indent=2))

sessionId = r.json()["token"]
#print sessionId

data = r.json()["products"]
len_ = len(data)

# find which node has heating data
key = "heating"
heating = False
for i in range(len_):
	type = data[i]["type"]
	if key == type:
		thermostat = i

# uncomment for hot water
'''
# find which node has hot water data
key = "hotwater"
hotwater = False
for i in range(len_):
	type = data[i]["type"]
	if key == type:
		hotwater = i
'''

# get target from schedule (workaround for current bug)
dow = datetime.today().strftime("%A").lower()
schedule = r.json()["products"][thermostat]["state"]["schedule"][dow]
len_ = len(schedule)
t = datetime.now().strftime("%H:%M")
tm = int(t.split(":")[0]) * 60 + int(t.split(":")[1])
for i in reversed(range(len_)):
	start = schedule[i]["start"]
	if tm >= start:
		target = schedule[i]["value"]["target"]
		break

# get values from Hive
#target 	= r.json()["products"][thermostat]["state"]["target"]
temp   	= r.json()["products"][thermostat]["props"]["temperature"]
# uncomment for hot water
#hotw	= r.json()["products"][hotwater]["state"]["status"].title() # changes 'OFF' to 'Off', etc.

stateHeatingRelay = target > temp
if stateHeatingRelay: 
	heating = "On"
else:
	heating = "Off"

# log out from Hive
headers = {'Content-Type': 'application.json', 'Accept': 'application.json', \
	'X-AlertMe-Client': 'Hive Web Dashboard', 'Authorization': sessionId}
url = 'https://beekeeper-uk.hivehome.com/1.0/auth/logout'
r = requests.delete(url, headers=headers, verify=False)

# Domoticz

# get last values from Domoticz
last_temp	= domoticzRead(insideIdx, 'Temp')
last_target = domoticzRead(targetIdx, 'Temp')
last_heating = domoticzRead(heatingIdx, 'Status')
# uncomment for hot water
#last_hotw	= domoticzRead(hotwaterIdx, 'Status')

# change some values
temp = round(temp, 1)

if target < 7.0: target = 7.0

if debug:
	print '       ', 'new','old'
	print 'temp   ', temp, last_temp
	print 'target ', target, last_target
	print 'heating', heating, last_heating

# send values to Domoticz (only send if changed)
if temp != last_temp:
	url = DomoWriteURL + insideIdx + '&svalue=' + str(temp)
	r = requests.get(url)

if (target != last_target) or (sensorTimedOut(targetIdx)):
	url = DomoWriteURL + targetIdx + '&svalue=' + str(target)
	r = requests.get(url)

if heating != last_heating:
	url = DomoSwitchURL + heatingIdx + '&switchcmd=' + heating
	r = requests.get(url)
	
# uncomment for hot water
#if hotw != last_hotw:
#	url = DomoSwitchURL + hotwaterIdx + '&switchcmd=' + hotw
#	r = requests.get(url)


Calzor Suzay
Posts: 145
Joined: Tuesday 08 July 2014 15:10
Target OS: -
Domoticz version: 4.9700
Location: UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by Calzor Suzay »

MikeF wrote: Tuesday 09 April 2019 18:44 As the OP of this thread,I've produced python scripts to read Hive current and target temperatures, and display these in Domoticz.
Thanks for the update Mike, is the install procedure the same as your original first post?
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by MikeF »

I think the instructions are pretty well given in my post of 9 April, but here goes:

1. Create 2 dummy temperature devices (one for inside, and one for target), and note their IDx's
2. Create 1 dummy switch for heating status, and note its IDx
3. Copy the script from my post of 9 April, and edit the python file with your own values: Hive and Domoticz logins, Domoticz url and IDx's
4. Place the file in the Domoticz script folder
5. Create a crontab which runs the script every x minutes (I run mine every minute); my crontab now looks like this:

Code: Select all

*/1 * * * * sudo python /home/pi/domoticz/scripts/hive2domo.py > /dev/null 2>&1 &
(Sorry for the delay - I've been away.)
Calzor Suzay
Posts: 145
Joined: Tuesday 08 July 2014 15:10
Target OS: -
Domoticz version: 4.9700
Location: UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by Calzor Suzay »

Should of said I had a crack is from old to new and got it working.
Water bit didn't work at the start then realized there was more to un comment throughout the script not just at the top.

All looks good, thanks :)
kevster
Posts: 26
Joined: Tuesday 06 December 2016 23:14
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by kevster »

I ended up using @MikeF 's script. Works perfectly for me for now.

I would of liked to use Hive plugin but dont have any intention of using their bulbs etc. The TRV's look tempting however but it shouldnt take much to add to the scripts as and when. I suspect they will report back a current temp, target and if they are on/off.

Thanks for all the work on this folks !
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by MikeF »

I have now changed over to the Drayton Wiser heating system
- see this thread: viewtopic.php?f=34&t=28585

I’m developing similar scripts there.
sach
Posts: 111
Joined: Wednesday 12 October 2016 14:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Read British Gas Hive Heating temperature

Post by sach »

Anyone still using the Python plugin?
imcfarla
Posts: 64
Joined: Monday 04 December 2017 13:18
Target OS: Linux
Domoticz version:
Contact:

Re: Read British Gas Hive Heating temperature

Post by imcfarla »

Yes but I have redone my heating with Tado thermostats and most of my lights are now lightwaverf. Just a few hive bulbs and an active plug left...
sach
Posts: 111
Joined: Wednesday 12 October 2016 14:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Read British Gas Hive Heating temperature

Post by sach »

That's a shame as the plugin does work really well, but I'm nervous in case it ever stops working and we have no devs working on it.
I'm at a crossroads where I have installed home assistant to try out where Hive works great, in addition to the Ring plugin which Domoticz is missing, however I have spent a lot of time and effort in getting domoticz to where it does everything I need.
I may just be better off getting a zwave boiler switch and sticking with Domoticz. Food for thought...
gyunda
Posts: 2
Joined: Saturday 23 November 2019 11:28
Target OS: -
Domoticz version:
Contact:

Re: Read British Gas Hive Heating temperature

Post by gyunda »

I'll answer my own question - looks like domoticz does not send the servername so any site using SNI will fail.

Helena
imcfarla
Posts: 64
Joined: Monday 04 December 2017 13:18
Target OS: Linux
Domoticz version:
Contact:

Re: Read British Gas Hive Heating temperature

Post by imcfarla »

I have just updated the plugin to work with a few more types of bulbs.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest