Emotional eating

Short version: I hacked a way to only get the weight gain/loss number notified to me from my Withings scale. See here for the end solution, or read on for the background.

I’m overweight. It’s a fact that hasn’t really changed in the last 10 years or so, my weight has fluctuated but not significantly. Recently I’ve taken a step back and tried to look at the things that influence me, what I eat, how/when I exercise and do my best to give myself a proper chance of success. I realised the one thing that triggered my emotional eating was seeing my full weight whenever I weighed in.

I could either stop weighing myself and use other methods to define ‘success’… or I could hack together a system that only should me the difference between my last weight and my new weight (gain or loss). Simple!

Emotional eating

One part of that was realising the emotional impact my weight has on me, specifically seeing the numbers when I weigh-in. There is an argument to be made for not weighing yourself and relying on how your clothes feel/inch loss measurements instead but I know that, at some point, I’d still want to know what weight I am. Given that I turn to food for comfort, well the emotional impact is a big factor in my eating habits for any given day.

I have a set of Withings Wi-Fi scales. You stand on them, and the weight is logged on my Withings account (available online or via an app). Each weigh-in logs my weight (108.8kgs today), fat mass (30.8) and BMI (31.4), so when the information is displayed on the app/website they can also show the gain/loss.

Realising that my actual weight – 108.8kg – is the thing that is bothering me and which is triggering negative emotional thoughts (I’ve been below 100, so I know I can manage that, why can’t I get back to that, why? WHY IS LIFE SO UNFAIR!!! etc etc) I decided to try and do something about that part of my ‘system’.

Hacking the system

My first thought was to check the Withings app to see if I could later what was reported and displayed but there isn’t the option. Thanks to the wonder that is IFTTT.com I also log all my weigh-ins in a Google spreadsheet (easier to share with the doctor), however my I stumbled a bit at this point trying to figure out how to trigger the calculation… more on that in a bit.

Through IFTTT I realised I could also create a txt file for each weigh-in and have that added to a folder in Dropbox (or appended to an existing file). From there I headed into Hazel, Automator and Applescript land and was starting to get somewhere but realised that it would only work if my laptop was on so I backed myself out of that particular dead-end.

I tweeted my frustration and, before I’d had a chance to blink, the very generous Ian popped up with a solution! I tweaked his code a little (I’m a good code tweaker, a terrible code writer), and with his permission I’m posting it here.

The Solution

I now have a solution so that every time I stand on my scales, the weight is logged in a Google spreadsheet, which fires a script to calculate the difference between the new weight and the previous weight and then email me the difference.

If you want to replicate this you will need a Withings* scale, an IFTTT account, and a Google Drive account. You might also want a Twitter account but that’s an extra bonus step I added.

  1. Activate the Withings channel in IFTTT .
  2. Activate the Google Drive channel in IFTTT, you’ll need to sign in to make sure IFTTT has access to your Google Drive.
  3. Grab this IFTTT recipe – you can edit the details, or leave them as they are an IFTTT will create a spreadsheet for you. The default is to create a new spreadsheet called ‘Body Scale Measurements’ in a new folder ‘IFTTT/Withings’.
  4. IFTTT recipe

  5. With all that done, go stand on your scales and your new spreadsheet will be created.
  6. Find and open the newly created spreadsheet, go to Tools > Script Editor to create a new script.
  7. Now the codey bit (again, many thanks to Ian). Copy and paste the code below in to the Script Editor. You will need to change the email address. You can test the script by running Debug (the little bug icon).
  8. /**
     weight mailing function
     /
     function mailWeight() {
     var sheet = SpreadsheetApp.getActiveSheet();
     var lastRow = sheet.getLastRow();
     var newWeight = sheet.getRange(lastRow, 2, 1).getValue();
     var oldWeight = sheet.getRange(lastRow–1, 2, 1).getValue();
     var emailAddress = “YOUREMAILADDRESS@gmail.com”;
     var calc = newWeight - oldWeight;
     var message = calc.toFixed(2) + “kg”;
     var subject = “Weight Diff”;
     MailApp.sendEmail(emailAddress, subject, message);
     };

    A few things to call out for the above:

    • If you decided to change the ‘Formatted Row’ section in the IFTTT settings, it’s likely that the column used for the calculation may need to be updated. In the example above, we are getting the value for the calculation from column 3.
    • The calc.toFixed(2) simply limits the calculated number to two decimal points, and I added a string to mention the weight unit being used.
    • If you want to change the subject line of the generated email, just change the text within the quotes in the var subject line.
  9. Optional step – In Gmail, create a filter using the subject of the email generated by the script to add a label to the incoming ‘Weight Diff’ emails. You can then setup a rule in IFTTT whenever a new email with the Weight Diff label arrives and fire off a Tweet.

* May also work with Aria as there are Triggers available within the Fitbit IFTTT channel. Not sure about other scales, but if you can trigger the entry to the Google spreadsheet you should be good to go.