Page 9 of 16
Re: Read British Gas Hive Heating temperature
Posted: Tuesday 15 May 2018 13:39
by imcfarla
Up until 11:30 yesterday - yes it was
After that it stopped.
Re: Read British Gas Hive Heating temperature
Posted: Tuesday 15 May 2018 13:53
by dgilbert2
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
Re: Read British Gas Hive Heating temperature
Posted: Wednesday 16 May 2018 17:57
by roadsnail
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
Re: Read British Gas Hive Heating temperature
Posted: Monday 25 June 2018 19:34
by Jem101
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?
Re: Read British Gas Hive Heating temperature
Posted: Monday 25 June 2018 21:09
by dgilbert2
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)?
Re: Read British Gas Hive Heating temperature
Posted: Monday 25 June 2018 21:37
by Jem101
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.
Re: Read British Gas Hive Heating temperature
Posted: Tuesday 26 June 2018 0:11
by imcfarla
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.
Re: Read British Gas Hive Heating temperature
Posted: Tuesday 26 June 2018 8:39
by Jem101
Unfortunately I'm getting a syntax error when running this script
Line 31
print r.json()["nodes"]
^
SyntaxError: invalid syntax
Re: Read British Gas Hive Heating temperature
Posted: Friday 29 June 2018 9:30
by Jem101
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?
Re: Read British Gas Hive Heating temperature
Posted: Friday 29 June 2018 10:20
by dgilbert2
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?
Re: Read British Gas Hive Heating temperature
Posted: Friday 29 June 2018 11:12
by Jem101
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
Re: Read British Gas Hive Heating temperature
Posted: Friday 29 June 2018 12:33
by imcfarla
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
Re: Read British Gas Hive Heating temperature
Posted: Friday 29 June 2018 12:37
by imcfarla
Newer versions of domoticz expose more functions to the plugin so localhost access is not needed anymore.
Iain
Re: Read British Gas Hive Heating temperature
Posted: Friday 29 June 2018 21:57
by Jem101
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
Re: Read British Gas Hive Heating temperature
Posted: Friday 29 June 2018 22:38
by imcfarla
Put a line in the script at line 22
print(r.text)
Then run and see what happens
Re: Read British Gas Hive Heating temperature
Posted: Saturday 30 June 2018 9:54
by Jem101
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
Re: Read British Gas Hive Heating temperature
Posted: Saturday 21 July 2018 18:01
by ce007
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.
Re: Read British Gas Hive Heating temperature
Posted: Saturday 21 July 2018 18:16
by MikeF
Have you looked at the python script I produced at the beginning of this thread (and subsequent updates)?
Re: Read British Gas Hive Heating temperature
Posted: Saturday 21 July 2018 19:10
by ce007
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)
Re: Read British Gas Hive Heating temperature
Posted: Monday 23 July 2018 11:14
by MikeF
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).