[groheondus] Fix missing automatic refresh ++ (#11955)

* Fix scheduling of thing and token update, tries to avoid service rate limiting. Added more logging. Added some missing null checks. Ensure recent data is fetched, not data from yesterday

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Updated to latest versio of API lib

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Added new channel waterconsumption_since_midnight that sums todays water consumption (same as in the Grohe app)

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Add more debug logging

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* More null checks, also set channels to Undef if a value is missing

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Fixed missing embedding of commons-text as it is a dependency of the api lib

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Refresh token 1 hour before expiry

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Re-login in case token refresh fails

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Factor in timezone when calculating consum since midnight

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Use QuantityType<Volume> for water consumption

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Minor

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* i18n of dynamic error messages

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* More i18n. Plus retry of failed refresh token - with a delay to possibly avoid rate limiting

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Adjust refresh token timeout to 5 minutes before expire. Also retry with username/pwd login if token login fails (could be an expired token)

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Clear old discovery results

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Fetch data further back to ensure battery device has been online

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Updated README with old data warning

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Typo

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Do not allow polling interval less than 900 as rate limiting most likely will block the calls

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Fix failed token refresh giving up

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Removed refresh token login webpage. Another attempt at handling token refresh

Signed-off-by: Arne Seime <arne.seime@gmail.com>

* Fix status detail

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>

* Restore formatting

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>

* Fix newly introduced warnings

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>

* Remove redundant logging

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>

Signed-off-by: Arne Seime <arne.seime@gmail.com>
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
Co-authored-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Arne Seime
2022-10-27 09:03:17 +02:00
committed by GitHub
parent 26ad08cca9
commit 618b7a4e3a
14 changed files with 393 additions and 600 deletions

View File

@@ -5,7 +5,7 @@ The binding uses the REST API interface (the same as used by the Android App) to
## Supported Things
This binding should support all appliances from GROHE, however, only the GROHE Sense Guard is tested with it.
This binding should support all appliances from GROHE, however, only the GROHE Sense and Sense Guard is tested with it.
| Thing type | Name |
|--------------------------|--------------------------|
@@ -29,18 +29,15 @@ There is only one thing and one bridge that needs to be configured together to g
### Account Bridge
The `groheondus:account` bridge is used to configure the API interface for a specific account, which is used to access the collected and saved data of your GROHE account.
You can either use your username and password combination for logging in into your GROHE account, in which case both parameters, `username` as well as `password`, are required arguments and refer to the same login credentials you used during setting up your GROHE account or while logging into the app.
Alternatively you can use a so called `refresh token` to grant openHAB access to your account without having to share your credentials with the system.
For that you need to obtain such `refresh token` from the GROHE ONDUS Api (see more on that below) and paste this string into the respective input field on the account management page you can reach from `http://<your-openHAB-domain-and-port>/groheondus`.
On this site you can also delete a previously saved `refresh token`.
The GROHE ONDUS binding also refreshes this refresh token in order to ensure that you stay logged in.
Use the same credentials as in the mobile app.
### Appliance
The `groheondus:sense` and `groheondus:senseguard` things are used to retrieve information of a specific appliance from GROHE.
This appliance needs to be connected with your GROHE ONDUS account as configured in the corresponding Account Bridge.
The appliance needs to be configured with the unique appliance ID (with the `applianceId` configuration) as well as the `roomId`
and the `locationId`. Once the account bridge is configured, the appliances in your account will be discovered as Appliance things.
The appliance needs to be configured with the unique appliance ID (with the `applianceId` configuration) as well as the `roomId` and the `locationId`.
Once the account bridge is configured, the appliances in your account will be discovered as Appliance things.
`pollingInterval` has a minimum value of 900 seconds to avoid service rate limiting.
| Configuration | Default value | Description |
|--------------------------|--------------------------|-------------------------------------------------------|
@@ -48,19 +45,20 @@ and the `locationId`. Once the account bridge is configured, the appliances in y
| roomId | '' | ID of the room the appliance is in |
| locationId | '' | ID of the location (building) the appliance is in |
| pollingInterval | Retrieved from API, | Interval in seconds to get new data from the API |
| | usually 900 | The `sense` thing uses 900 by default |
| | usually 900 | The `sense` thing uses 900 by default. |
#### Channels
##### senseguard
| Channel | Type | Description |
|--------------------------|--------------------------|-------------------------------------------------------|
| name | String | The name of the appliance |
| pressure | Number:Pressure | The pressure of your water supply |
| temperature_guard | Number:Temperature | The ambient temperature of the appliance |
| valve_open | Switch | Valve switch |
| waterconsumption | Number | The amount of water used in a specific timeframe |
| Channel | Type | Description |
|---------------------------------|--------------------|--------------------------------------------------|
| name | String | The name of the appliance |
| pressure | Number:Pressure | The pressure of your water supply |
| temperature_guard | Number:Temperature | The ambient temperature of the appliance |
| valve_open | Switch | Valve switch |
| waterconsumption | Number:Volume | The amount of water used in a specific timeframe |
| waterconsumption_since_midnight | Number:Volume | The amount of water used since midnight |
##### sense
@@ -71,6 +69,8 @@ and the `locationId`. Once the account bridge is configured, the appliances in y
| temperature | Number:Temperature | The ambient temperature of the appliance |
| battery | Number | The battery level of the appliance |
Note: Be aware that the Sense reports data once a day (at most), and that the value posted in the channel - however the latest - may be up to 48 hours old.
## Full Example
Things file:
@@ -93,47 +93,9 @@ Items file:
String Name_Sense_Guard "Appliance Name" {channel="groheondus:senseguard:groheondus:appliance:550e8400-e29b-11d4-a716-446655440000:name"}
Number:Pressure Pressure_Sense_Guard "Pressure [%.1f %unit%]" {channel="groheondus:senseguard:groheondus:appliance:550e8400-e29b-11d4-a716-446655440000:pressure"}
Number:Temperature Temperature_Sense_Guard "Temperature [%.1f %unit%]" {channel="groheondus:senseguard:groheondus:appliance:550e8400-e29b-11d4-a716-446655440000:temperature_guard"}
Number:Volume Water_Usage_Since_Midnight_Sense_Guard "Water usage since midnight [%.1f %unit%]" {channel="groheondus:senseguard:groheondus:appliance:550e8400-e29b-11d4-a716-446655440000:waterconsumption_since_midnight"}
String Name_Sense "Temperature [%.1f %unit%]" {channel="groheondus:sense:groheondus:appliance:444e8400-e29b-11d4-a716-446655440000:name"}
Number:Temperature Temperature_Sense "Temperature [%.1f %unit%]" {channel="groheondus:sense:groheondus:appliance:444e8400-e29b-11d4-a716-446655440000:temperature"}
Number Humidity_Sense "Humidity [%.1f %unit%]" {channel="groheondus:sense:groheondus:appliance:444e8400-e29b-11d4-a716-446655440000:humidity"}
````
## Obtaining a `refresh token`
Actually obtaining a `refresh token` from the GROHE ONDUS Api requires some manual steps.
In order to more deeply understand what is happening during the process, you can read more information about the OAuth2/OIDC (OpenID Connect) login flow by searching for these terms in your favorite search engine.
Here is a short step-by-step guide on how to obtain a refresh token:
1. Open a new tab in your Internet browser
2. Open the developer console of your browser (mostly possible by pressing F12)
3. Select the network tab of the developer console (which shows you the network request done by the browser)
4. Open the following URL: https://idp2-apigw.cloud.grohe.com/v3/iot/oidc/login
5. You will automatically being redirected to the GROHE ONDUS login page, login there
6. After logging in successfully, nothing should happen, except a failed request to a page starting with `token?`
7. Click on this request (the URL in the request overview should start with `ondus://idp2-apigw.cloud.grohe.com/v3/iot/oidc/token?` or something like that
8. Copy the whole request URL (which should contain a lot of stuff, like a `state` parameter and so on)
9. Open a new tab in your Internet browser and paste the URL into the address bar (do not hit ENTER or start the navigation to this page, yet)
10. Replace the `ondus://` part of the URL with `https://` and hit ENTER
11. The response of the page should be plain text with a so called `JSON object`. Somewhere in the text should be a `refresh_token` string, select the string after this `refresh_token` text, which is encapsulated with `"`.
E.g.: If the response of the page looks like this:
````
{
"access_token": "the_access_token",
"expires_in":3600,
"refresh_expires_in":15552000,
"refresh_token":"the_refresh_token",
"token_type":"bearer",
"id_token":"the_id_token",
"not-before-policy":0,
"session_state":"a-state",
"scope":"",
"tandc_accepted":true,
"partialLogin":false
}
````
Then the `refresh_token` value you should copy would be: `the_refresh_token`.
This value is the `refresh token` you should save as described above.