c0deaddict / import-garmin-connect

Import Garmin Connect data into InfluxDB
MIT License
2 stars 0 forks source link

Only Info: More values for 'Garmin Index S2 Smart Scale' #2

Closed mpenn0 closed 3 years ago

mpenn0 commented 3 years ago

I would like to show here the possibility how to extend the code. Since we have the scale 'Garmin Index S2 Smart Scale' that measures many values. To do this, I added the following lines of code to the garmin.php file:

def convert_weight(date, data, tags):

ts         = data["timestampGMT"]
weight     = data["weight"]
bmi        = data["bmi"]        # add
bodyFat    = data["bodyFat"]    # add
muscleMass = data["muscleMass"] # add
boneMass   = data["boneMass"]   # add
bodyWater  = data["bodyWater"]  # add
logging.debug(data)             # add
if ts is not None and weight is not None:
    yield {
        "measurement": "weight",
        "tags": tags,
        "time": datetime.utcfromtimestamp(ts / 1000).isoformat() + "Z",
        "fields": {
            "weight"     : weight,
            "bmi"        : bmi,        # add
            "bodyFat"    : bodyFat,    # add
            "muscleMass" : muscleMass, # add
            "boneMass"   : boneMass,   # add
            "bodyWater"  : bodyWater,  # add
            },
    }

The following values are then in the influxdb.

> SELECT * FROM "weight" name: weight time.................bmi bodyFat bodyWater boneMass muscleMass profile weight 1612683936000000000 25.6 27.3... 53.1..... 3980.... 31459..... profile 77470 1612766959000000000 25.4 28.2... 52.4..... 3869.... 31319..... profile 76900