jaroslawhartman / withings-sync

Synchronisation of Withings weight
MIT License
429 stars 83 forks source link

Multiple users #13

Open chaesinidau opened 3 years ago

chaesinidau commented 3 years ago

I use the tool on a docker environement and it worked quiet perfectly. Since a few days, it seems that there is a problem with having 2 users on the same withings-account.

Setting: Withings 1 Account 1 App 2 Users/Names

Garmin 2 Accounts

Docker 2 Differents Containers for every user

Now i'am only able to get data for one user from withings. Wheter i start the first or second container, it always takes the data of the same withingsuser. I unconnected the Withingsapp from the Synctool via dev.withings, but the problem stays the same.

Any help? THX

stv0g commented 3 years ago

I guess we could fix the issue by adding a new parameter to withings-sync which filters the synced data to a single Withings User in the configured Withings Account.

First we would need to figure out if the Withings API provides us the name of the user via their API.

If the User name is provided, you could continue running two Docker containers both connected to the same Withings account.

stv0g commented 3 years ago

I quickly checked the available data provided by the WIthings API: https://developer.withings.com/oauth2/#operation/measure-getmeas

There is no field in the response providing us which user the measurement is associated with. However, there is an attrib (attribution field) which is documented as follows:

The way the measure was attributed to the user:

Value Description
0 The measuregroup has been captured by a device and is known to belong to this user (and is not ambiguous)
1 The measuregroup has been captured by a device but may belong to other users as well as this one (it is ambiguous)
2 The measuregroup has been entered manually for this particular user
4 The measuregroup has been entered manually during user creation (and may not be accurate)
5 Measure auto, it's only for the Blood Pressure Monitor. This device can make many measures and computed the best value
7 Measure confirmed. You can get this value if the user confirmed a detected activity
8 Same as attrib 0

Based on this description it looks to me that you will need to created a dedicated Withings Account for each User in your Withings scale and associate the different users to their respective accounts via the Withings App.

@chaesinidau Can you check if this is possible?

chaesinidau commented 3 years ago

Thanks for checking the API. I managed to create a second account for the second user in withings. Unfortunately i was not yet able to get a second token, even after deleting all the connections described in developer.withings.com. Now i try to delete the API-application on the first user, which takes 7 days until its gone.

Until then, it seems that the Docker-Container always remains to take the data of one person. Keep you updated.

chaesinidau commented 3 years ago

Now i finally could delete my API-application on withings. Unfortunately its still not possible to sync with both accounts. I unlinked the connection in both userprofiles. As soon as i start the container of person A, it asks me to generate a new token. After that, the sync of person A works fine. If i try to start the container of person B, it just starts to collect data's from person A, without having an option of getting a separate token.

Any other approches/ideas, how i could solve it? Thanks a lot!

skatsavos commented 2 years ago

@chaesinidau I modified the script accordingly and created multiple records in withings_user.json so each user has seperate entry. If you want i can share to you the changes i made. The script now works without any issues for 2 users)or more) The only issue i had was when i tried to run the the script(for different user) with crontab at the same time.

greykapp1001 commented 2 years ago

Hi @skatsavos would you be able to share the code please under files changed / pull requests? I am in the same situation and would like to work out how to modify the code to allow for this! It doesn't have to be neat, just that I can go through th code and get it to work for my requirements (apart from at the same time as you mention in your post).

skatsavos commented 1 year ago

I created a pull request: https://github.com/jaroslawhartman/withings-sync/pull/84 I removed some of the parameters for better usabillity and added some others. With these changes you can configure multiple different users. I tried and is working for Garmin.