More weight

Here’s a followup on my post about tracking and plotting my weight. The shortcuts we’ll cover were written a couple of weeks ago, but I thought weight would be a touchy subject during the week of Thanksgiving.

As you may recall, I’m using an app that (among other things) communicates with a smart scale to record my weight. But it doesn’t share that data with the Health app, so I pulled all the weights over the past 4–5 months out of the app, saved them to a CSV file, and wrote a short Python script to plot my weight over time. I also wrote a shortcut that I could run every morning to update the CSV file with that day’s weight.

A few days after posting, I realized that Shortcuts has actions that communicate with the Health app. So it should be easy to change the shortcut to both update the CSV file and send the data to the Health app. And it was easy; all I had to do was add one more step to the shortcut I’d already written. Here’s the new version:

StepActionComment
1 Weight Today Step 01 Get today’s date
2 Weight Today Step 02 Format the date as yyyy-mm-dd
3 Weight Today Step 03 Ask the user for today’s weight
4 Weight Today Step 04 Assemble the date,weight line
5 Weight Today Step 05 Append the line to the CSV file
6 Weight Today Step 06 Update the Health app with today’s weight

The only change is the addition of Step 6, which takes the weight that’s input in Step 3 and logs it to the Health app. Because the date argument of the Log Health Sample action defaults to today’s date, there’s no need to fill it in in Step 6.

That’s great going forward, but what about all the weights that were collected since July? For that, I had to do two things:

  1. Clear out all the weight data already saved in Health. Although my weight wasn’t added automatically to Health, I have been updating my weight (approximately) every month or so. That data had to go to make way for the correct data from the scale.
  2. Use the CSV file to enter all the weight data recorded there into Health.

To clear out the unwanted weight data, I opened Health, tapped the Weight category, and scrolled down to the bottom. This is where the Show All Data button is.

Buttons at the bottom of the Weight page

Tapping that button took me to a view of all my weight data in reverse chronological order. There’s an Edit button in the top right corner of the view; tapping it adds the red “No” buttons that allow you to delete any individual value. But what I did was tap the Delete All button in the top left corner. That got rid of everything.

Weight data in Health app

Now it’s time for a shortcut that enters the data from my CSV file. While I suspect there are prebuilt actions for reading and interpreting CSV files, I didn’t see any right away, so I decided to copy the data directly into the shortcut and use brute force to extract the dates and weights. Here’s the shortcut:

StepActionComment
1 Add Weights To Health Step 01 The weight data from the CSV file without the header row
2 Add Weights To Health Step 02 Split into lines
3 Add Weights To Health Step 03 Repeat with each line
4 Add Weights To Health Step 04 Split the line at the comma
5 Add Weights To Health Step 05 The first item is the date
6 Add Weights To Health Step 06 The second item is the weight
7 Add Weights To Health Step 07 Log the weight for the given day in the Health app
8 Add Weights To Health Step 08 End repeat loop

The first time I ran this, I noticed a problem in the data. There were two days I was out of town and didn’t weigh myself. These appeared in the CSV file like this:

2024-08-31,184.00
2024-09-01,184.79
2024-09-02,
2024-09-03,
2024-09-04,183.80
2024-09-05,184.99

When the blank values were logged into Health, they were interpreted as zeros, which made the plot of my weight in Health look pretty funny. So I deleted those two lines, went back and deleted all the weight data from Health, and ran the shortcut again. That put everything right.

I’ve kept this second shortcut around, even though I hope to never use it again. With luck, all I’ll have to do is run the Weight Today shortcut every time I weigh myself and both the CSV file and the Health app will stay up to date. Although I prefer the graph I made with Python and Matplotlib, the one in the Health app isn’t bad. And it’s generated automatically.

Weight plot from Health app