Page 13 of 16

Re: Read British Gas Hive Heating temperature

Posted: Friday 02 October 2020 17:10
by homemonitor
How do you get it to work with the new two-factor login? My monitoring stopped working on 30/9.

Re: Read British Gas Hive Heating temperature

Posted: Friday 02 October 2020 17:42
by Rowsdower
My script failed a couple of hours ago. Now when I try to get a session from
https://api.prod.bgchprod.info/omnia/auth/sessions
I get
{
"genericError": {
"error": {
"reason": "GONE",
"message": "Not supported anymore"
}
}
}

I can get an OAuth Bearer Token, using the Authorize button at
https://api.prod.bgchprod.info/omnia/swagger-ui.html

so instead of the header
X-Omnia-Access-Token: <SESSIONID>

you can use
Authorization: Bearer <TOKEN>

but this only lasts a while and I can't find a way to refresh it.

https://oauth.prod.bgchprod.info/oauth2/token
seems to want to play ball, but with no documentation, I can't work out what to pass it, so I always just get an Unauthorized response.
Can anyone who's better at internet protocols than me figure it out?

Re: Read British Gas Hive Heating temperature

Posted: Friday 02 October 2020 20:38
by dgilbert2
My Hive scripts also stopped working at 14:30 today :cry: . My account though does not (yet?) require any two-factor login.

Maybe it will start working again soon!!?? I'm fearing not though!

Re: Read British Gas Hive Heating temperature

Posted: Friday 02 October 2020 21:12
by orionn2o
Another person who's Hive dropped out today at 14:30 after working flawlessly for years :(

I wasn't specifically using a python plugin, just Bash with some Curl scripts.

Started getting the same error "not supported anymore" :(

does this mean I've now got to go get a new heating control system ...

Ive heard EvoHome is pretty good

Re: Read British Gas Hive Heating temperature

Posted: Friday 02 October 2020 21:47
by mark.sellwood
I'm looking to move to something else possibly Nest due to the problems with Hive.
My Hive hub drops off the internet randomity, Hive have admitted its a software issue but will not be fixing it, they have given me 2 options, pay to replace the hub or plug the hub in to a time switch & power cycle it daily.

Re: Read British Gas Hive Heating temperature

Posted: Saturday 03 October 2020 1:59
by Rowsdower
OK, I'm making progress. By using Stream (an iOS network debug tool) to sniff the protocol from the iOS Hive app, I've found that it calls

https://beekeeper-uk.hivehome.com/1.0/c ... resh-token

passing it a token, accessToken and refreshToken

It gets the same items back with new values, and "token" can be used to access the API using

--header 'Authorization: Bearer '$TOKEN

This seems to be working - it's clumsy having to get your initial tokens from Stream, but from a bit more sniffing, it seems like the initial login is a complex challenge/response interaction with AWS. So long as I set a script to refresh my tokens every 30 min though, I hopefully won't have to do this again.

Re: Read British Gas Hive Heating temperature

Posted: Saturday 03 October 2020 11:20
by dgilbert2
Some more clues maybe??

I looked at https://community.smartthings.com/t/hiv ... g/206851/8 and github https://github.com/alyc100/SmartThingsP ... ect.groovy, although a different platform / project, they have managed to get the hive api to work again by changing to https://beekeeper.hivehome.com/1.0/cognito/login.

I don't know though how to get this working on the scripts we use here. eg I've tried changing the login lines as below;

Code: Select all

login=$(curl  -s -k --cookie-jar cookie.jar -g -H "Content-Type: application/vnd.alertme.zoo-6.4+json" \
	-H "Accept: application/vnd.alertme.zoo-6.4+json" -H "Content-Type: 'application/*+json'" \
	-H "X-AlertMe-Client: Hive Web Dashboard" \
	-d '{"sessions":[{"username": "xx@xx", "password": "xx", "devices": false, "products": false}]}' \
	https://beekeeper.hivehome.com/1.0/cognito/login)
...but this produces an error "MALFORMED_REQUEST".

Hopefully someone who understands these scripts better than me can get it working as it does seem possible if you know what your doing ;)

Re: Read British Gas Hive Heating temperature

Posted: Saturday 03 October 2020 12:25
by dgilbert2
FIXED!!!

The login & sessionId sides of the script needs updating as below, which is based on Mike's older version, but it worked for me :)

(Only applicable if your still using MikeF's original V6 script.)

Code: Select all

#!/bin/bash
# Sends current and target temperatures to Domoticz

cd "${0%/*}"

login=$(curl -s -k -g -H "Content-Type: application/json" \
	-H "Accept: application/json"  \
	-d '{"username":"xx@xx","password":"xx"}' \
	https://beekeeper.hivehome.com/1.0/cognito/login)
	
sessionId=$(echo $login | python -c 'import sys, json; print json.load(sys.stdin)["token"]')

Re: Read British Gas Hive Heating temperature

Posted: Saturday 03 October 2020 13:33
by dgilbert2
homemonitor wrote: Friday 02 October 2020 17:10 How do you get it to work with the new two-factor login? My monitoring stopped working on 30/9.
Easiest way to get things working is to turn off two-factor login. In the Hive app go to the three bars in the top corner, Account, My Details and then edit Two Factor authentication to disabled.

Re: Read British Gas Hive Heating temperature

Posted: Saturday 03 October 2020 13:51
by mark.sellwood
I have never setup two-factor login & its showing as disabled but still the Plugin isn't working.

Re: Read British Gas Hive Heating temperature

Posted: Saturday 03 October 2020 13:57
by dgilbert2
mark.sellwood wrote: Saturday 03 October 2020 13:51 I have never setup two-factor login & its showing as disabled but still the Plugin isn't working.
Got ya. Hopefully @imcfarla will update the plugin soon with the revised Hive API login details as detailed above.

Re: Read British Gas Hive Heating temperature

Posted: Saturday 03 October 2020 14:00
by Rowsdower
dgilbert2 wrote: Saturday 03 October 2020 12:25 FIXED!!!

The login & sessionId sides of the script needs updating as below, which is based on Mike's older version, but it worked for me :)

(Only applicable if your still using MikeF's original V6 script.)

Code: Select all

#!/bin/bash
# Sends current and target temperatures to Domoticz

cd "${0%/*}"

login=$(curl -s -k -g -H "Content-Type: application/json" \
	-H "Accept: application/json"  \
	-d '{"username":"xx@xx","password":"xx"}' \
	https://beekeeper.hivehome.com/1.0/cognito/login)
	
sessionId=$(echo $login | python -c 'import sys, json; print json.load(sys.stdin)["token"]')
Good jobs, thanks! This is the final piece of the jigsaw - it annoyed my having to store my login credentials on my IoT devices, but this lets me generate tokens on my laptop, then pass them over for periodic refreshing on the ESP. Thanks!

Re: Read British Gas Hive Heating temperature

Posted: Saturday 03 October 2020 16:26
by orionn2o
brill well done :)

back up and running again phew!

If i could ask, how did you debug this?

Re: Read British Gas Hive Heating temperature

Posted: Saturday 03 October 2020 16:55
by dgilbert2
orionn2o wrote: Saturday 03 October 2020 16:26 ....If i could ask, how did you debug this?
I added "echo $login" to the bash script so that I could see what was going on when manually running it in PuTTY.
I'm sure there are much smarter ways though ;)

Re: Read British Gas Hive Heating temperature

Posted: Sunday 04 October 2020 0:04
by imcfarla
Panic over I have updated both the plugin.py and plugin.urllib.py
both are now version 1.2 and should handle the new login API

Re: Read British Gas Hive Heating temperature

Posted: Sunday 04 October 2020 2:21
by dgilbert2
imcfarla wrote: Sunday 04 October 2020 0:04 Panic over I have updated both the plugin.py and plugin.urllib.py
both are now version 1.2 and should handle the new login API
Where do you download these files from? Thanks

EDIT:
Found them ;) https://github.com/imcfarla2003/domoticz-hive/

Re: Read British Gas Hive Heating temperature

Posted: Sunday 04 October 2020 8:37
by dgilbert2
imcfarla wrote: Sunday 04 October 2020 0:04 Panic over I have updated both the plugin.py and plugin.urllib.py
both are now version 1.2 and should handle the new login API
@imcfaria

I still use the original bash script by MikeF and have found the Logout section no longer works (so have #'ed it out for now). I see the equivalent "def onStop(self)" in your plugin code also has remarks that its not currently working. I would be interested how you manage to fix this in the future so I can go back and update my bash scripts. I guess though this is a "nice to have" for now, to end the session rather than keep asking for new tokens. At least the main parts are all working now :D

Re: Read British Gas Hive Heating temperature

Posted: Sunday 04 October 2020 10:24
by Och
imcfarla wrote: Sunday 04 October 2020 0:04 Panic over I have updated both the plugin.py and plugin.urllib.py
both are now version 1.2 and should handle the new login API
Thank you! :D

My system failed on Friday and I had to rebuild yesterday. It took me a few hours to work out that the Hive plug-in not working was nothing to do with me rebuilding the system. Great to have the plug-in updated so quickly.

Re: Read British Gas Hive Heating temperature

Posted: Sunday 04 October 2020 18:58
by roadsnail
imcfarla wrote: Sunday 04 October 2020 0:04 Panic over I have updated both the plugin.py and plugin.urllib.py
both are now version 1.2 and should handle the new login API
Thank you for the quick fix!

BTW. I am still running a very of version of plugin.urllib.py so I was able to fix my old version by patching GetSessionID from your github version. But in doing so I spotted that you need to add a close curly bracket to the end of line 806, (only in the plugin.urllib.py version), else a syntax error is thrown at execution time.

ie line 806...
payload = {'username':Parameters["Username"], 'password':Parameters["Password"]

becomes
payload = {'username':Parameters["Username"], 'password':Parameters["Password"]}

Thanks again!

Cheers
Chris

Re: Read British Gas Hive Heating temperature

Posted: Sunday 04 October 2020 21:34
by imcfarla
Fixed that now - thanks