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.
imcfarla
Posts: 51
Joined: Monday 04 December 2017 14:18
Target OS: Linux
Domoticz version:
Contact:

Re: Read British Gas Hive Heating temperature

Post by imcfarla » Tuesday 15 May 2018 13:39

Up until 11:30 yesterday - yes it was

After that it stopped.

dgilbert2
Posts: 53
Joined: Wednesday 16 August 2017 8:08
Target OS: Raspberry Pi
Domoticz version: 4.9728
Location: UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by dgilbert2 » Tuesday 15 May 2018 13:53

They seem to be tinkering with the API a fair bit over the last few weeks, before that it "just worked" for months and months with the scripts in this thread :(

roadsnail
Posts: 20
Joined: Wednesday 08 November 2017 21:42
Target OS: Raspberry Pi
Domoticz version: 3.8922
Location: The awesome county of Suffolk, UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by roadsnail » Wednesday 16 May 2018 17:57

imcfarla wrote:
Tuesday 15 May 2018 13:39
Up until 11:30 yesterday - yes it was

After that it stopped.
Yep, same here. Thanks dgilbert2/imcfarla, all working again
_______________________________________________________________________________________________
Pi3, Z-Wave: no-name sigma dongle, Danfoss Z-trv's, aeotec hem, d-link siren, heiman door contacts. Hive heating ctrl, esp8266 based sensors, hue hub +Ikea

Jem101
Posts: 95
Joined: Saturday 02 May 2015 21:26
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Bexleyheath, SE London, UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by Jem101 » Monday 25 June 2018 19:34

Have Hive changed the API again? It might just be my installation but I'm getting the following in the log on startup

Code: Select all

2018-06-25 18:25:44.230 (Hive Devices) Deleting Session
2018-06-25 18:25:44.411 (Hive Devices) HTTP Error 405: Method Not Allowed
2018-06-25 18:25:44.200 Status: (Hive Devices) Stop directive received.
2018-06-25 18:25:44.317 Status: (Hive Devices) Exiting work loop.
2018-06-25 18:25:44.600 Status: (Hive Devices) Stopping threads.
2018-06-25 18:25:44.600 Status: (Hive Devices) Stopped.
2018-06-25 18:25:47.607 Status: (Hive Devices) Started.
2018-06-25 18:25:48.092 (Hive Devices) Starting
2018-06-25 18:25:48.092 (Hive Devices) DomoticzVersion Available
2018-06-25 18:25:48.092 (Hive Devices) TimedOut available
2018-06-25 18:25:48.092 (Hive Devices) Creating Session
2018-06-25 18:25:48.038 Status: (Hive Devices) Entering work loop.
2018-06-25 18:25:48.039 Status: (Hive Devices) Initialized version 0.5.1(Dev), author 'imcfarla,MikeF and roadsnail'
2018-06-25 18:25:48.250 Error: (Hive Devices) 'onStart' failed 'HTTPError'.
2018-06-25 18:25:48.250 Error: (Hive Devices) ----> Line 572 in /home/pi/domoticz/plugins/Hive/plugin.py, function onStart
2018-06-25 18:25:48.250 Error: (Hive Devices) ----> Line 51 in /home/pi/domoticz/plugins/Hive/plugin.py, function onStart
2018-06-25 18:25:48.250 Error: (Hive Devices) ----> Line 348 in /home/pi/domoticz/plugins/Hive/plugin.py, function GetSessionID
2018-06-25 18:25:48.250 Error: (Hive Devices) ----> Line 163 in /usr/lib/python3.5/urllib/request.py, function urlopen
2018-06-25 18:25:48.250 Error: (Hive Devices) ----> Line 472 in /usr/lib/python3.5/urllib/request.py, function open
2018-06-25 18:25:48.250 Error: (Hive Devices) ----> Line 582 in /usr/lib/python3.5/urllib/request.py, function http_response
2018-06-25 18:25:48.250 Error: (Hive Devices) ----> Line 510 in /usr/lib/python3.5/urllib/request.py, function error
2018-06-25 18:25:48.250 Error: (Hive Devices) ----> Line 444 in /usr/lib/python3.5/urllib/request.py, function _call_chain
2018-06-25 18:25:48.250 Error: (Hive Devices) ----> Line 590 in /usr/lib/python3.5/urllib/request.py, function http_error_default


At first I thought that despite these messages, it was actually still working, but own closer inspection I haven't had an update to the thermostat current or target temperature since the evening of 22nd June.

I have tried using the plugin.py python plugin as well as the plugin.new.py version with similar results.

Anyone else or is it just my set up?
I firmly believe in having an open mind - although not so open that your brain falls out!

- sometimes attributed to Carl Sagan, but the original quote is much older than that

dgilbert2
Posts: 53
Joined: Wednesday 16 August 2017 8:08
Target OS: Raspberry Pi
Domoticz version: 4.9728
Location: UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by dgilbert2 » Monday 25 June 2018 21:09

It does't help your question as I still use the original script where you have to manually find the node numbers, but this is still working from my side.

In my case I have noticed that the Philips Hue integration does cause the nodes to change every time you add a new lamp, but the "new" script should be able to find the new node.

Have you just upgraded to the new Domoticz V4.9700 (stable)?

Jem101
Posts: 95
Joined: Saturday 02 May 2015 21:26
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Bexleyheath, SE London, UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by Jem101 » Monday 25 June 2018 21:37

Not the latest stable but the latest beta which (if the version numbers are accurate) is slightly ahead of the 4.9700 release.

What I did do though was a complete rebuild of my RPi 3 with Stretch after a recent update completely hosed my earlier Jessie-based installation. I used to get a seg fault error with some Python plugins but I have recently changed some hardware meaning that I do longer needed a particular plugin which never worked at all with Stretch. The Hive plugin doesn't give the same immediate fall-over error, just the ones I've mentioned and the fact that it isn't returning any values.

As an aside, I too have some Hue lamps and also have the not updating the lamp status issue, so whether they are related or not is a bit of a question.
I firmly believe in having an open mind - although not so open that your brain falls out!

- sometimes attributed to Carl Sagan, but the original quote is much older than that

imcfarla
Posts: 51
Joined: Monday 04 December 2017 14:18
Target OS: Linux
Domoticz version:
Contact:

Re: Read British Gas Hive Heating temperature

Post by imcfarla » Tuesday 26 June 2018 0:11

Can you run the script found here?
https://raw.githubusercontent.com/imcfa ... ct_json.py

This will hopefully complete and give some information about your setup.
If you could run it twice with a few hours in between then we should see some change in temp etc.

Jem101
Posts: 95
Joined: Saturday 02 May 2015 21:26
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Bexleyheath, SE London, UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by Jem101 » Tuesday 26 June 2018 8:39

Unfortunately I'm getting a syntax error when running this script

Line 31
print r.json()["nodes"]
^
SyntaxError: invalid syntax
I firmly believe in having an open mind - although not so open that your brain falls out!

- sometimes attributed to Carl Sagan, but the original quote is much older than that

Jem101
Posts: 95
Joined: Saturday 02 May 2015 21:26
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Bexleyheath, SE London, UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by Jem101 » Friday 29 June 2018 9:30

I'm guessing that this is just something odd about my system then as nobody else seems to be reporting issues.

If I run
python3 collect_json.py
I get the syntax error above

If I put parentheses around the print statement (or if i just run python collect_json.py)

I get a different error

File "collect_json.py", line 6, in <module>
import requests
ImportError: No module named requests

Which does indicate something is missing in my installation.

This is a brand new clean built Stretch install, all the raspbian updates have been done,
Python3 (python3 --version reports as 3.5.3) is installed in /usr/bin/python3

Anything else I need to do?
I firmly believe in having an open mind - although not so open that your brain falls out!

- sometimes attributed to Carl Sagan, but the original quote is much older than that

dgilbert2
Posts: 53
Joined: Wednesday 16 August 2017 8:08
Target OS: Raspberry Pi
Domoticz version: 4.9728
Location: UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by dgilbert2 » Friday 29 June 2018 10:20

A bit of a wild card, but when you did a fresh install, under Domoticz settings is the "Local Networks (no username/password):" still setup, ie the IP address of your PI?

Jem101
Posts: 95
Joined: Saturday 02 May 2015 21:26
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Bexleyheath, SE London, UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by Jem101 » Friday 29 June 2018 11:12

I had been caught out by this once before so I did double check and yes the IP subnet is in the local networks settings not requiring authentication.

However even if this was wrong, I could see how it would prevent Domoticz from interacting with Hive but I cannot even get the separate collect_json python script to run interactively (which just talks to the Hive APIs and returns and prints out the values - which makes me think that the issue us actually with my python installation but I'm not sure what I need to do to check it and fix it.

John
I firmly believe in having an open mind - although not so open that your brain falls out!

- sometimes attributed to Carl Sagan, but the original quote is much older than that

imcfarla
Posts: 51
Joined: Monday 04 December 2017 14:18
Target OS: Linux
Domoticz version:
Contact:

Re: Read British Gas Hive Heating temperature

Post by imcfarla » Friday 29 June 2018 12:33

I think you are missing the python requests module.
Depending on Python 2 or 3 you will need to install either python3-requests or python-requests

sudo apt install python-requests
or
sudo apt install python3-requests

Should get you what you need.

I have updated the collect_json.py script as I had forgotten to apply the sessionId changes needed. Please download and try again
https://github.com/imcfarla2003/domotic ... ct_json.py

Iain

imcfarla
Posts: 51
Joined: Monday 04 December 2017 14:18
Target OS: Linux
Domoticz version:
Contact:

Re: Read British Gas Hive Heating temperature

Post by imcfarla » Friday 29 June 2018 12:37

Newer versions of domoticz expose more functions to the plugin so localhost access is not needed anymore.

Iain

Jem101
Posts: 95
Joined: Saturday 02 May 2015 21:26
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Bexleyheath, SE London, UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by Jem101 » Friday 29 June 2018 21:57

Thanks for your help Iain

I've installed the requests module and downloaded the new collect_json.py script. I have also deleted the Hive plugin hardware from domoticz and re-added it, this naturally deleted my virtual thermostat and thermometer sensors. When I re-add the Hive plugin, I still get the same errors in the Domoticz log, it creates a virtual thermometer for the outside temperature based on the post code but it does not create the thermostat or the two current and target temperature thermometer devices.

If I run python3 collect_json.py <username>, <password>

I get

Traceback (most recent call last):
File "collect_json.py", line 23, in <module>
sessionId = r.json()["sessions"][0]['sessionId']
KeyError: 'sessions'

John
I firmly believe in having an open mind - although not so open that your brain falls out!

- sometimes attributed to Carl Sagan, but the original quote is much older than that

imcfarla
Posts: 51
Joined: Monday 04 December 2017 14:18
Target OS: Linux
Domoticz version:
Contact:

Re: Read British Gas Hive Heating temperature

Post by imcfarla » Friday 29 June 2018 22:38

Put a line in the script at line 22
print(r.text)

Then run and see what happens

Jem101
Posts: 95
Joined: Saturday 02 May 2015 21:26
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Bexleyheath, SE London, UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by Jem101 » Saturday 30 June 2018 9:54

And sometimes it's the simplest little things that's the issue!

Added the extra print line in and ran it, got the following

{"errors":[{"code":"USERNAME_PASSWORD_ERROR","title":"Username or password not specified or invalid","links":[]}]}
Traceback (most recent call last):
File "collect_json.py", line 24, in <module>
sessionId = r.json()["sessions"][0]['sessionId']
KeyError: 'sessions'

Well that's odd, unless I don't need to put quotes around the username and password parameters, so I try again without the quote marks and get

{"errors":[{"code":"ACCOUNT_LOCKED","title":"Account was locked","links":[]}]}
Traceback (most recent call last):
File "collect_json.py", line 24, in <module>
sessionId = r.json()["sessions"][0]['sessionId']
KeyError: 'sessions'

Account locked? How did that happen, so I go direct to the HiveHome web site and try to log in, sure enough, 'Account disabled due to too many login attempts'.

So request a password reset, OK, website login now works so change the password in your plugin, disable and reenable it and bingo, virtual devices all created and updated, no errors etc.

Just to check, I reran your collect_json script with the correct details and sure enough it returned all the raw json data.

So not sure how the too many login attempts happened - probably me messing about trying to get this to work, but all OK now.

Many, many thanks for all your help.

John
I firmly believe in having an open mind - although not so open that your brain falls out!

- sometimes attributed to Carl Sagan, but the original quote is much older than that

ce007
Posts: 2
Joined: Saturday 21 July 2018 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Read British Gas Hive Heating temperature

Post by ce007 » Saturday 21 July 2018 18:01

Hi all, don't know if anyone is still monitoring this thread

I would like to extract basic info from my hive (without then using domoticz) such as current temperature, target temperature and time

I ran the collect_json.py script and it all works fine.

My question is; is there any code that will let me parse the raw json data to just print the bits I need to a log file on my pi?

As you probably guessed, java and python noob

Best regards,

Chris.

MikeF
Posts: 227
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V4.9700
Location: UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by MikeF » Saturday 21 July 2018 18:16

Have you looked at the python script I produced at the beginning of this thread (and subsequent updates)?

ce007
Posts: 2
Joined: Saturday 21 July 2018 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Read British Gas Hive Heating temperature

Post by ce007 » Saturday 21 July 2018 19:10

Many thanks for the reply Mike

I tried the following code, which was the python code with the bits that relate to Domoticz cut out (and obv with my Hive credentials in)

I got an error message;

Traceback (most recent call last):
File "test.py", line 44, in <module>
sessionId = r.json()["token"]
KeyError: 'token'

I don't know if I chopped out something important or there is another reason this won't work?

Chris


#!/usr/bin/env python

'''
Python script to send data from Hive to Domoticz.

Replace XXX's with your values.
'''

import requests
import json

# Hive

# log on to Hive
# Replace with your Hive user id and password
payload = {'username':'XXX', 'password':'YYY'}
headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
url = 'https://beekeeper-uk.hivehome.com/1.0/gateway/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

headers = {'Content-Type': 'application/vnd.alertme.zoo-6.2+json', 'Accept': 'application/vnd.alertme.zoo-6.2+json', \
'X-AlertMe-Client': 'swagger', 'X-Omnia-Access-Token': sessionId}
url = 'https://api.prod.bgchprod.info:443/omnia/nodes'
r = requests.get(url, headers=headers, verify=False)

#print(json.dumps(r.json()["nodes"][2], indent=2))

# read node (Note: node number may be different / may change if new Hive devices added)
nodeId=r.json()["nodes"][2]["id"]
#print nodeId

# get values from Hive
temp = r.json()["nodes"][2]["attributes"]["temperature"]["reportedValue"]
targetTemp = r.json()["nodes"][2]["attributes"]["targetHeatTemperature"]["reportedValue"]
heating = r.json()["nodes"][2]["attributes"]["stateHeatingRelay"]["reportedValue"]

# log out from Hive
headers = {'Content-Type': 'application/vnd.alertme.zoo-6.1+json', 'Accept': 'application/vnd.alertme.zoo-6.2+json', \
'X-AlertMe-Client': 'Hive Web Dashboard', 'X-Omnia-Access-Token': sessionId}
url = 'https://api.prod.bgchprod.info:443/omnia/auth/sessions/' + sessionId
r = requests.delete(url, headers=headers, verify=False)

MikeF
Posts: 227
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V4.9700
Location: UK
Contact:

Re: Read British Gas Hive Heating temperature

Post by MikeF » Monday 23 July 2018 11:14

Try changing the line starting 'url =' to:

Code: Select all

url = 'https://beekeeper.hivehome.com/1.0/global/login'
Also, to make your code more readable in this forum, can you surround it with the code tag - click on the </> button above the text box (even better, use spoiler first, to hide / unhide the code).

Post Reply

Who is online

Users browsing this forum: dozen, Pimmeh and 1 guest