[V4] Dev service Withings

Hello,

I am trying to develop a service that retrieves data from devices of this brand.

Once the information is retrieved from the account and the devices, I want to retrieve all the historical measurement data.

I create feature_states for each measurement by defining the created_date and the updated_date, but after saving, these 2 dates are forced to the current date and not to what I defined.

How can I save device measurements from the past?

Hello @euguuu! Great if you develop this service, I saw your PR :slight_smile:

Good point, this is indeed the current behavior, see the incriminating line of code:

Could you describe in more detail the expected behavior of your service so we can see how to do the best?

In this service, I start by requesting the information to connect the user’s Withings account (via OAuth2).

Once the connection is validated, I retrieve the account information to create the existing devices in this account (scale, watch, etc.) and I create the associated features (battery, weight, pulse, etc.). I also retrieve the history of existing measurements, and I would like to record these measurements (with their actual creation dates) to have the history in Gladys and allow display in the form of a curve, for example.

Once all this is done, I want to set up a poll to retrieve new measurements once a day. In my case, it is not the time when Gladys retrieves the measurements that counts, but the creation date of the measurement by the device on the Withings account.

Got it, I see the idea!

Since you’re syncing a lot of values at once, I don’t think the current function makes sense.

What we need is to create a function like the saveState function, but instead of taking 1 value, it takes an array of values.

This function would:

  1. Insert the list of t_device_feature_state in the DB
  2. Update the t_device_feature.last_value with the last value of the array
  3. Call the scenes with the last value and propagate the last value via websockets to connected clients

Basically, copy this function:

To handle multiple insertions.

Then listen to a new event, like EVENTS.DEVICE.NEW_STATE_SYNC in the same way as EVENTS.DEVICE.NEW_STATE

Could you take care of this in your PR? :slight_smile:

Don’t hesitate if you have any questions!

Hello,

I need to get back to it, but yes I will take care of integrating this modification.

Hello,

I’ve made significant progress on this development. I’ve just pushed a nearly final version of the PR [WIP] Withings.

This integration allows:

  • Connecting to the Withings account
  • A generic API (server & front) to connect to OAuth2 services (to be confirmed on other integrations)
  • Automatic creation of Withings devices
  • Retrieving device measurements
  • Displaying a ‹ Health › box in the dashboard similar to the DeviceInRoom box

The remaining tasks to consider the integration correct are:

  • Integration documentation (in progress)
  • Adding a configuration for the demo site
  • Code review if possible and taking into account the remarks
  • [Optional] Testing the integration by volunteers with more devices (the integration should work for all Withings devices, but I only have one for now)

Ideally, for a next version, I would have liked to display a box on the dashboard in the form of a line graph. Are there components already planned to display the history of data?

Some images of the integration:

Great all that! Thanks @euguuu
By any chance would it be possible to display a historical weight curve? Which is generally the whole interest of a connected scale. To be set as desired: 1 week / 1 month / 1 year.

The question is also being asked :wink:

Oh yes, actually if I could read I wouldn’t ask this kind of question… ^^
Sorry!

Magnificent!!

That’s very nice work @euguuu :slight_smile:

I think this is more something we want in general for Gladys, not just for this service. So I don’t think it’s necessary to develop this in the service.

We have this task that already has 12 votes:

I think that will solve the problem :slight_smile:

I really liked v3 for that… :stuck_out_tongue:

Great! Well, as I don’t understand how Gladys is built, I didn’t think we could create a « history » tool and use it on all the sensors we want. Thanks for the info!

Yes, currently the history is in the database, by the way when you configure Gladys for the first time you define what retention you want.

The feature needs to be developed.

Is there any development ongoing at this display level? Have there already been decisions made about the technology to use or the architecture to implement, or do we need to start from scratch?

This is where it happens

There is no development currently underway. We discussed this in the other topic, which is just a « to-do » list, but overall, everything needs to be done: choosing the chart library and development :slight_smile:

Should we discuss this in the other topic?

Hello everyone,
I’m bringing up the topic again.
@euguuu is nearing the end of development, the PR is under review, so we are looking for volunteers to test/validate the service, preferably with hardware.

Thanks in advance.

I’m bringing the topic back up, does anyone have equipment and could test the PR? :slight_smile:

Otherwise, could we have a small presentation of the PR @euguuu? :slight_smile:

What does it do? Which Withings devices are supported?

The associated documentation describes each page of the service step by step. I can do a demo if needed or provide my Withings codes (corresponds to OAuth2 as I can delete/change them with one click after testing).

I have only tested in real conditions with one device (the Body scale), but in theory, the service is compatible with all devices of the brand.

The service automatically creates devices based on those declared on the Withings profile, retrieves the history of measurements, and then performs a daily poll to retrieve new measurements.

In terms of measurement usage, there is a box similar to the device in-room box but which only retrieves features of the ‹ health › category.

Ok, and how do you handle the fact that these are health devices that are more « personal » than related to the home?

Your scale returns weights linked to people in your home (and not linked to rooms like most sensors so far), how did you think about that?