Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh token expires often #23

Open
peternorlander opened this issue Apr 11, 2022 · 27 comments
Open

Refresh token expires often #23

peternorlander opened this issue Apr 11, 2022 · 27 comments

Comments

@peternorlander
Copy link

Hi!

I really like this integration but I wanted to ask. I don't know if it is just me but how often do you guys need to create a new token? Mine usually only last for maybe two weeks then I need to get a new one.

Regards
Peter

@Floppe
Copy link

Floppe commented Apr 13, 2022

Hi. Have no idea how often, but it's so often that it's annoying. I've stopped using this integration until proper OAuth is implemented.

I've also noticed the same thing with Grohes own Android App. Have to sign in again after some weeks. So could be the problems are coming from their own services.

// Joachim

@peternorlander
Copy link
Author

I spent a little time trying to understand how Grohe's OAuth is working using postman but can't really get it to work. Even when I copied the urls chrome is using with the same payloads I get errors that I'm using an outdated browser. Anyone has any idea how to make OAuth working?

@seranoo
Copy link

seranoo commented Jun 16, 2022

Hi!

I have the same issues, like every two weeks i need to generate a new token. And more or less the same issue with the Apple app, often need to delete/reinstall the app to get it working again.

It is such a pity, the combination with Grohe Sense and my home alarm is essentially why I started the whole HA "trip". I will have to find some other hardware that can accomplish a similar functionality.

Regards,
Magnus

@erikkt
Copy link

erikkt commented Jun 16, 2022

I've had to modify mine. I have installed an Wemos ESP relay board inside the Grohe Sense Guard. It was an easy hack. Now I have at least a reliable way of shutting the water off.

@seranoo
Copy link

seranoo commented Jun 16, 2022

Do you run the Wemos ESP relay board in parallell with the Grohe Sense Guard functionality? I.e. can the Grohe Sense Guard automatically shut off the water in case of an unexpected high flow, etc?

And of course, do you have any photos of the hack? Would love to have some pointers.

@erikkt
Copy link

erikkt commented Jun 16, 2022

Yes, the Grohe functionality is unaffected (when it actually works...)
There are solder points where the power cable attaches and where the solenoid valve attaches. If you with a wemos relay short circuit the negative from power to the negative on the solenoid, the solenoid will activate. You have 12v power already present there, so you need a wemos mini with relay card, and a small 12v->5v converter. Then you only need three wires between the wemos setup and the Sense guard, 12v + and -, and negative from relay to solenoid.
Using ESPHome the code is super simple, and very reliable. And best of all, it is cloud independent.

@seranoo
Copy link

seranoo commented Jun 16, 2022

Wow!!! Thanks erikkt! Then that is exactly what I will do!

In my opinion the "local Grohe functionality" appears working well. I've got kids that once in a while forgets to completely turn off the tap, and the the Grohe Sense Guard always turns off the water. At least in my experience. I think is is just the cloud connection that really sucks.

Again, thanks for this!

@bendikrb
Copy link

I threw together some code to retrieve the token. Hopefully this could help integrating authentication in the HA integration!

""" """
import html
import json
import re
import sys
from urllib.parse import urlparse

import requests

BASE_URL = 'https://idp2-apigw.cloud.grohe.com/v3/iot/'
LOGIN_URL = f"{BASE_URL}oidc/login"


def main():
    args = [arg for arg in sys.argv[1:]]
    if len(args) < 2:
        raise ValueError("Need exactly 2 arguments: username, password")
    login(args[0], args[1])


def login(username, password):
    oauth_session = requests.Session()

    redirect = oauth_session.get(LOGIN_URL, allow_redirects=False)
    redirect.raise_for_status()

    login_url = redirect.headers['Location']
    login_form = oauth_session.get(login_url)
    login_form.raise_for_status()

    regex = r'action="([^ >"]*)"'
    matches = re.findall(regex, login_form.content.decode('utf-8'), re.MULTILINE)
    login_url = html.unescape(matches[0])

    response = oauth_session.post(
        login_url,
        allow_redirects=False,
        data={
            "username": username,
            "password": password,
        })
    response.raise_for_status()

    token_url = urlparse(response.next.url)._replace(scheme="https").geturl()
    token_result = oauth_session.get(token_url)
    token_result.raise_for_status()
    token = token_result.json()
    print("== Successfully retrieved access token ==")
    print(json.dumps(token, indent=4))


if __name__ == '__main__':
    main()

@aperezva
Copy link

Thanks
How can execute it?. Would I to create file?.

BR and good job

@aperezva
Copy link

Another question, do you know why data from HA differs taht data APP shows?

Thanks

@bendikrb
Copy link

Thanks How can execute it?. Would I to create file?.

Yes, and then you can run it in cli, like; python3 filename.py exampleuser mypasswd

@aperezva
Copy link

Thanks to difficult to me, I don´t have pythonknowledge and show me a error

Last login: Mon Jul 18 15:38:54 on ttys000
cd '/Users/xxxxxxx/Downloads/' && '/usr/local/bin/python3' '/Users/xxxx/Downloads/api grohe.py' && echo Exit status: $? && exit 1
xxxxxxx@iMac ~ % cd '/Users/txxxxxxx/Downloads/' && '/usr/local/bin/python3' '/Users/xxxxxxxx/Downloads/api grohe.py' && echo Exit status: $? && exit 1
Traceback (most recent call last):
File "/Users/xxxxxxxx/Downloads/api grohe.py", line 8, in
import requests
ModuleNotFoundError: No module named 'requests'
tonyperezvalls@iMac-de-Tony Downloads %

@bendikrb
Copy link

bendikrb commented Jul 18, 2022

pip3 install requests
.. or run this in a container (use one of the SSH addons for example), or even add it as a command line sensor

@aperezva
Copy link

Thanks,

Today is the third time I have to generate a new token. It seems I will till another integration will be ready. Impossible to manage it in this way.

Thanks a lot for your time

@bendikrb
Copy link

That doesn't sound right - are you sure you're using the refresh token?

@aperezva
Copy link

aperezva commented Jul 18, 2022

Yes, and it’s working for some time but after 2 hours HA show me an error in the token

Any suggestions?

@aperezva
Copy link

aperezva commented Aug 7, 2022

Thanks How can execute it?. Would I to create file?.

Yes, and then you can run it in cli, like; python3 filename.py exampleuser mypasswd

Hi again @bendikrb

After renewal token every two days, I need you help to implement this feature and get token in the easier way.

How can I setup the command line sensor?. It means that this sensor will provide me the updated token ?

Please, support me in this way if you have time.

thanks

@pertakman
Copy link

I'm struggling with having to restart HA due to complaints about the refresh token. It does not seem to matter whether I get a new refresh token or not, but I'd also like to get help with automating this somehow.

@seranoo
Copy link

seranoo commented Aug 19, 2022

Hi @erikkt!

Yesterday I had a chance to open up the Grohe Sense Guard and to short circuit the negative from power to the negative on the solenoid (just manually to test it out).

It worked great. However, since you have to keep short circuiting the negative from power to the negative on the solenoid it appears to no longer be possible to use the button on the front of the Grohe Sense Guard or to use the app. Am I correct?

Is this the way you have approached it? Looking forward to hearing back from you!

Kindest regards, Magnus

@erikkt
Copy link

erikkt commented Aug 19, 2022

@seranoo
You are correct in the sense that if the water is turned off by short circuiting manually or by a relay, you cannot turn on water with the Grohe button or with the app. This setup will turn off water and override everything else.
But in normal cases, the water is on, and in that case you can turn off water with relay, button and/or app.

@seranoo
Copy link

seranoo commented Aug 23, 2022

I can highly recommend the proposal by @erikkt until (somwhere in the future...) when Grohe sorts out their app/token. That is, add a separate piece of hardware to provide negative power to the solenoid when you want to turn off the water.

There is plenty of space inside of Grohe Sense, so anything will do really. Just push the two buttons on the sides and open the lid.

erikkt used a wemos mini with relay card, and a small 12v->5v converter. I instead used a Shelly 1 running on 12V. Either solution is super easy and now is actually possible to be sure that the water is turned off when you want it to. No more having to rely on if the token for the day is working.

@pertakman
Copy link

After having giving the proposal by @erikkt some consideration I decided to hack the Grohe sense guard as suggested. To avoid the frustration of not being able to turn the water back on in case Home Assistant crashes I decided to add a momentary button and some configuration settings to ensure that power cycling the Grohe sense guard turns the water back on again. I've attached my yaml file for those of you that find that helpful.

grohe-sense-guard.txt

Warmly, Per

@Sleepy81
Copy link

Sleepy81 commented Oct 2, 2022

Tried the python script, but get the following:

Traceback (most recent call last):
File "C:\Users\XXXXX\grohe.py", line 53, in
main()
File "C:\Users\XXXXX\grohe.py", line 18, in main
login(args[0], args[1])
File "C:\Users\XXXXX\grohe.py", line 44, in login
token_url = urlparse(response.next.url)._replace(scheme="https").geturl()
AttributeError: 'NoneType' object has no attribute 'url'

@peternorlander
Copy link
Author

peternorlander commented Oct 11, 2022 via email

@autopower
Copy link

It looks like new refresh token is created everytime you access Grohe endpoint via mobile app.

@jahiekk
Copy link

jahiekk commented Aug 30, 2024

I implemented automatic token refresh on the sensor code: https://github.com/jahiekk/homeassistant-grohe_sense

@peternorlander
Copy link
Author

peternorlander commented Aug 30, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants