More weight
December 9, 2024 at 1:10 PM by Dr. Drang
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:
Step | Action | Comment |
---|---|---|
1 | Get today’s date | |
2 | Format the date as yyyy-mm-dd | |
3 | Ask the user for today’s weight | |
4 | Assemble the date,weight line | |
5 | Append the line to the CSV file | |
6 | 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
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:
- 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.
- 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
button is.Tapping that button took me to a view of all my weight data in reverse chronological order. There’s an
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 button in the top left corner. That got rid of everything.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:
Step | Action | Comment |
---|---|---|
1 | The weight data from the CSV file without the header row | |
2 | Split into lines | |
3 | Repeat with each line | |
4 | Split the line at the comma | |
5 | The first item is the date | |
6 | The second item is the weight | |
7 | Log the weight for the given day in the Health app | |
8 | 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
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.