project Utilities / zepp_to_influxdb avatar

utilities/zepp_to_influxdb#1: Capture Stress Values



Issue Information

Issue Type: issue
Status: closed
Reported By: btasker
Assigned To: btasker

Milestone: 0.3
Created: 03-Aug-23 14:30



Description

I've MiTM'd the Zepp life so now have details of the requests used to capture some of the metrics that the app visualises.

The Stress event type gives a read out of stress level by time:

band_data_url=f"https://api-mifit-de2.zepp.com/users/{auth_info['token_info']['user_id']}/events"
headers={
        'apptoken': auth_info['token_info']['app_token'],
}
get_data={
        "limit" : 1000,
        "from" : '0',
        "to" : '1691103600000',
        "eventType" : "all_day_stress"
}

The response looks like this

{
  "items": [
    {
      "userId": "<redacted>",
      "eventType": "all_day_stress",
      "subType": "all_day_stress",
      "timestamp": 1690844400001,
      "deviceType": "0",
      "minStress": "37",
      "mediumProportion": "10",
      "maxStress": "62",
      "data": "[{\"time\":1690902960000,\"value\":59},{\"time\":1690903260000,\"value\":48},{\"time\":1690904460000,\"value\":62},{\"time\":1690906260000,\"value\":58},{\"time\":1690907160000,\"value\":53},{\"time\":1690907760000,\"value\":57},{\"time\":1690908060000,\"value\":49},{\"time\":1690908660000,\"value\":44},{\"time\":1690908960000,\"value\":37},{\"time\":1690909260000,\"value\":40}]",
      "relaxProportion": "10",
      "deviceId": "<redacted>",
      "deviceSn": "<redacted>",
      "avgStress": "50",
      "highProportion": "0",
      "deviceSource": "256",
      "deviceMac": "<redacted>",
      "normalProportion": "80"
    }
  ]
}

There is also a single_stress event type, but it doesn't return any values for my account.



Toggle State Changes

Activity


assigned to @btasker

changed the description

One curious thing I've noticed: the API is only currently giving me results from the 1st of August. There's nothing for today or yesterday.

The Zepp app, however does show levels for those days.

It might be that it only syncs the data periodically - the API does seem to be a little finickity about the timestamps used in from and to. Unless a timestamp of midnight is used, results for the specified day won't be included at all.

I'll have to check tomorrow whether yesterday's readings are suddenly available.

I don't get any change in result if I use a from value of 0 so... shrug

I'm adding two types of series.

There's the daily cumulative tracker:

row = {
    "timestamp": int(stress['timestamp']) * 1000000, # Convert to nanos 
    "fields" : {
        "minimum_stress_level" : int(stress['minStress']),
        "max_stress_level" : int(stress['maxStress']),
        "mean_stress_level" : int(stress['avgStress']),
        "relaxed_time_perc" : int(stress['relaxProportion']),
        "normal_stress_time_perc" : int(stress['normalProportion']),
        "medium_stress_time_perc" : int(stress['mediumProportion']),
        "high_stress_time_perc" : int(stress['highProportion'])
        },
    "tags" : {
        "stress" : "daily"
        }
}  

and there's another for the readings that are taken through the day

  row = {
    "timestamp": int(stresspoint['time']) * 1000000, # Convert to nanos 
    "fields" : {
        "current_stress_level" : int(stresspoint['value'])
        },
    "tags" : {
        "stress" : "point_in_time"
        }
}         
verified

mentioned in commit e1fc36ac1f7790f9c61e6d2dc25ed9df65fb85c1

Commit: e1fc36ac1f7790f9c61e6d2dc25ed9df65fb85c1 
Author: B Tasker                            
                            
Date: 2023-08-03T16:59:22.000+01:00 

Message

Collect stress level information (utilities/zepp_to_influxdb#1)

This collects the stress readings submitted by the watch.

Values seem to lag behind by quite a bit though - the most recent value available to me at the moment is a couple of days behind.

+74 -1 (75 lines changed)

Although this is implemented, I'm not going to close this until I've checked whether data is catching up (a couple of days lag isn't great, but it's still better than rolling something out that can't actually collect data).

Oh, actually, they've just shown up

> select mean_stress_level from zepp
name: zepp
time                mean_stress_level
----                -----------------
1690844400001000000 55
1690930800001000000 44
1691017200001000000 33

I guess the app had issues syncing for some reason - I'd signed out and back in. It does seem like it expects you to open the app to trigger a sync once a day or so. Might have to see whether we can do anything about that.

As the data's shown up, I'm going to close this as done.