[OBSOLETE] - Hive (Connect) V3.2c (British Gas Hive)

Looks like Hive might have moved it behind 2FA??? Not sure it’s a quick fix, but thanks!

Ah apologies! It was meant as a reply to your comment a week or so back, relating to the TRVs and webcore.

I’m not sure on this problem, as 2fa can be disabled…

Sorry!

@Alyc100 any ideas on this? Seems Auth with hive returns 403 forbidden again :frowning:

I’ll look into it

EDIT: It looks like the authentication API has been shut off by Hive. Apparently there is a 2FA authentication API that does work. Won’t be ready in a day as I have a day job but give me a week and hopefully I can update the code.

EDIT 2: Looking into it there is one approach I’m hoping will work. Hive have an https://oauth.hivehome.com/login URL that IFTTT seems to use. I’m hoping that the authentication mechanism used by my Neato smart app can be ported over. The other approach which I think is unfeasible based on the short shelf life the Groovy IDE might have is to code the AWS Cognito authentication into the app to allow 2FA. This is the approach the HomeAssistant integration has taken.

3 Likes

@Alyc100
Appreciate you looking into it. Totally understand about having the day job too.

Btw, I used to work with your bro. I’m still at the same place but he moved on a while ago. Small world.

Someone integrate the door and window sensors and motion sensors managed to get the thermostat workingTook me a few goes but I did manage to get it going the code for the old thermostat doesn’t work properly anymore and it knocks it off the hive Took me a few goes but I did manage to get it going the code for the old thermostat doesn’t work properly anymore and it knocks it off the hive there any way of integrating this into the code in the next version update

Is there a link to the code you’re talking about?

1 Like

OK. I have a solution. Not as elegant as before though and requires generating initial tokens externally which then uses a Beekeeper token refresh API to refresh tokens going forward. I’ve posted instructions below and will update the main post too. Update the Smart App to v3.2 which is now in Github. My instructions are for OS X Terminal as that’s what I have, Windows syntax might be different.

Credit goes to Hive Community Forum and Matthew Price2 for finding a solution to generating Hive Tokens using CLI. https://community.hivehome.com/s/question/0D55I00000bWVqzSAG/has-the-hive-api-changed-im-getting-a-not-supported-anymore-error

First you need to generate tokens for your Hive account. Make sure 2FA is DISABLED in your Hive account.

  1. You need a computer where you can run node.js.
  2. Install node.js if you haven’t already. https://nodejs.org/en/
  3. Check nodejs is installed. In a terminal (or Command Line) run
    node -v
    you should see a version number appear which means it’s installed.
  4. Run ‘npm init’ and keep pressing ENTER to create a package.json file. You should type YES when prompted 'Is this OK? (yes) ’ to complete.
  5. Run ‘npm install amazon-user-pool-srp-client --save
  6. Run ’npm install axios --save
  7. Download index.js from https://www.dropbox.com/s/f9zphtaomgaqwoa/index.js?dl=0 and replace the index.js already present in ‘node_modules/amazon-user-pool-srp-client’ with downloaded one. On OS X, my node-modules folder was located in my Home directory.
  8. Edit the index.js and add your Hive user email and password at your end of the file and save. It should be obvious which lines you need to edit to do this.
  9. Set the environment for the index.js script:

OS X/UNIX/Linux - In the amazon-user-pool-srp-client directory run
export CognitoUserPoolUsers=eu-west-1_SamNfoWtf CognitoUserPoolClientWeb=3rl4i0ajrmtdm8sbre54p9dvd9’.

Windows Powershell - In the amazon-user-pool-srp-client directory run
$env:CognitoUserPoolUsers = ‘eu-west-1_SamNfoWtf’ and then
$env:CognitoUserPoolClientWeb = ‘3rl4i0ajrmtdm8sbre54p9dvd9’

  1. Run ‘node index.js > HiveTokens.json’ to generate your token file.

Now you need to paste the token values into the Hive(Connect) app.

  1. Open the HiveTokens.json file in a text editor.
  2. Edit the Hive(Connect) smart app in the Smartthings IDE
  3. In the Smartthings Hive code at line 105, you should see

def hiveTokenString = 'PASTE HiveToken.json content into here'

NOTE: Would have ideally had this in App Settings, but the tokens are too long Smartthings IDE doesn’t like them.
4. Copy the contents of HiveTokens.js file and paste them into the ‘’ single quotes in line 105. It’s a very long string.
5. Save and publish the code.
6. Go into the SmartThings mobile app and go to SmartApps section.
7. Open Hive(Connect) app
8. Tap ‘Done’.
9. This should refresh the new tokens. Open Hive(Connect) app again.
10. Hopefully it should say ‘AUTHENTICATED’ in the smart app.
11. BINGO! Hopefully all your Hive devices should wake up.

Now in theory, the smart app uses a refresh-token API using your initial token to refresh the token every 30 minutes and replaces the initial values with new ones going forward, so you shouldn’t need to regenerate the HiveTokens.js using npm again. I think. The test to see if this method works long term or whether we will have to regenerate HiveTokens.js again. I’m hoping not.

Please let me know if anyone gets this working as it works for me before I update the main instructions on this page.

1 Like

That’s great - thanks Alyc100 big time!

I’ll give it a bash later and update…

Edit: It’s not playing ball currently, issues with the CognitoUserPoolUsers part as the export command is not natively supported in Windows, tried installing https://github.com/JaredPh/cognito-export-users but there is a credentials error connecting to AWS.

If the generated files aren’t unique, could they be supplied?

export on OS X terminal is just setting environment variables. I think these are Windows equivalent. https://stackoverflow.com/questions/47711696/export-node-variable-in-windows-like-on-mac

so it might be
$env:CognitoUserPoolUsers=eu-west-1_SamNfoWtf
$env:CognitoUserPoolClientWeb=3rl4i0ajrmtdm8sbre54p9dvd9

if using PowerShell as suggested on that forum.

Generated files are unique to your credentials so you would not want to share them.

Slight diff in how PS handles it -

$env:CognitoUserPoolUsers = ‘eu-west-1_SamNfoWtf’
$env:CognitoUserPoolClientWeb = ‘3rl4i0ajrmtdm8sbre54p9dvd9’

Just working through the rest…

Edit: It’s imported the devices, but multiple times.

If I don’t try and import the lights, it imports the TRV’s and thermostat once. If I import the lights, then it duplicates the heating devices yet doesn’t add the lights. Each time I save the settings within the app, it adds another copy of the heating devices?

Edit2: Light issue seems separate, lights just aren’t importing. Each time settings are saved in the SmartApp, the devices are duplicated.

Edit3: Heads up - the latest update seems to have removed the version 3.1.1b? Or something similar updates, which fixed the naming format - adding HIVE TRV to the end of devices.

That aside, everything seems connected and working!

1 Like

Hi, Thanks for the work on this. I followed the instructions (although I’m no developer) and I get this error when I try to generate the tokens.

C:\Users\andyn\node_modules\amazon-user-pool-srp-client>node index.js > HiveTokens.json
C:\Users\andyn\node_modules\amazon-user-pool-srp-client\index.js:144
const userPoolId = process.env.CognitoUserPoolUsers.split(’_’)[1]
^

TypeError: Cannot read property ‘split’ of undefined
at login (C:\Users\andyn\node_modules\amazon-user-pool-srp-client\index.js:144:55)
at Object. (C:\Users\andyn\node_modules\amazon-user-pool-srp-client\index.js:179:1)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47

C:\Users\andyn\node_modules\amazon-user-pool-srp-client>

I tired using the PS command from Matt instead but I still get the error. Any idea what I am doing wrong ?

I ran back over the instructions step by step but still got the same .

Any help is appreciated thankyou

Andy

Edit: Update … I didnt reboot the laptop afte rinstalling node.js … not sure why it mattered but restarted and got it to work. However initial findings are

It authenticates with Hive , and see the devices, however it didnt want to install the one device despite selecting it. That might be a time thing as seen this behaviour before.

Also when you click done in the app I get an error saying “Something went wrong. Please try to install the smartapp again”

Will test and see what happens over the next day or so.

Thanks to everyone involved for all the effort that went into resolving this issue with HIve.

Hi Alyc100,
I followed Your instructions on windows and linux (everything went smoothly). But in SmartThings app when i pressing “Done” in Hive (Connect) smartapp nothing happens.
I’m repeating that over and over but I can’t see “Authenticated as’ me Hive user name” (What I can see is: “Tab to refresh authentication”).

I’m sure that I have done everything as I should, I have disabled 2FA and putting correct login data to index.js. I tried repeat whole process 3 times with the same resultats.

EDIT:
In Simulator (IDE) when I’m clicking on “updateDevices” i can see list of my devices in debug but in SmartThings app is still the same.

EDIT2:
Now in Smartapp (Hive Connect) in SmartThings app i can see “Autheticated as null. Tap to refresh authentication”. After pressing “Done” nothing changed.

@Alyc100
I eventually got this to work :grinning:

You weren’t joking when you said the token strings are LONG!

I did encounter some errors at first as others have mentioned above, but I put this down to first attempting the steps on my work laptop (as it already has node and npm installed), which connects to a VPN and is then behind a corporate proxy, so I concluded that there were some connectivity issues going on. Dropbox is also blocked, so I had to mess around sending the index.js file around via email from my phone.

I then tried it all on my personal laptop. Installed node and npm from scratch. Downloaded the index.is file directly from Dropbox. Set the env vars using PowerShell. Generated the HiveTokens.json file. Copied the loooooong token strings to the Hive Connect smartapp in ST IDE, saved and published. All good.

Then in the new SmartThings app, managed to add back my Hive Heating and authenticate with Hive using the updated v3.2 Hive Connect smartapp. Happy days.

As a side note, Hive Hot Water didn’t seem to be affected by this issue at all; it remained connected in ST the whole time and didn’t need adding back. Only the Hive Heating needed to be added again.

Also needed to re-add the Hive Heating to Pollster refreshing and re-associate it with webCoRE.

Everything seems to be working for me now. Time will tell I guess to see if the token refreshing works properly, but so far so good.

Let’s just hope that it’s a longer while this time before BG / Centrica decide to change something else with the authentication at their end again and create another world of pain with a broken integration for us…

Thanks for all your help on this @Alyc100, it’s very much appreciated.

frazzlegod

I’m seeing exactly the same if it’s any consolation (I used the windows version of Node.JS and Powershell if it’s any use to know) - first ‘Tap to refresh Authentication’ and now “Autheticated as null’.

Out of curiosity, for those having auth issues - are you using Windows?

I’ve made some slight adjustments to the Hive app in 3.2a. Please update if you can. Remember you will have to replace the tokens again once updated in Smartthings IDE. It’s a shame App Settings can’t handle the large tokens.

Some adjustments include:

  • Change how HiveTokens.json contents is pasted into code. Now you can paste the whole contents of the HiveTokens.json within the single quotes in line 105.
    def hiveTokenString = 'PASTE HiveToken.json content into here'

  • reducing the frequency that token refresh API is called from 5 minutes to 20.

  • stopping the removal of tokens if Hive API responds with a 500 status code which is unnecessary.

This might fix the issues people are seeing on the latest comments as you can paste the whole contents of the HiveTokens.json file into the ‘’ single quotes.

Can we just copy and paste the token values from v3.2 to v3.2a of the smartapp? Or do we have to regenerate the token values again using node?

Not sure how long the tokens are valid for. It might work.

@Alyc100
Maybe I celebrated too soon :pensive:

If I change my Hive Heating externally to ST, i.e. using the actual Hive app, ST does seem to detect and reflect whatever the change was (for example, changing from off to boost).

However, the controls for Hive Heating in the ST app don’t seem to perform any changes at all. Changing temp or changing mode, it thinks about it for a few seconds and then just gives up and keeps whatever the setting was before.

So it only seems to be a one way thing. The Hive Connect ST smartapp can read changes fine, it just can’t make changes itself.

Has anyone else experienced this?

1 Like