Claude builds my Coros strength workouts

A year ago I downloaded a GPX file from Coros using the unofficial API. This time I wanted to go the other direction. I give Claude Code a list of strength exercises, it finds the matching ones in the Coros catalogue, builds the workouts and uploads them. Then I look at them in the Android Coros app and do them with my Coros Pace 3.

The API

I used the unofficial API of Training Hub again -- the Coros website for planning workouts. The endpoints came from coros-training-mcp, which already figured out how to create workouts. Claude read the code there and wrote a small client with only the Python standard library and PyYAML. The login sends the MD5 hash of the password, and the API host is region specific (teameuapi.coros.com for Europe).

Finding the exercises

I could create my own exercises in Coros. But I like to see the animation of what I should do, and the exercises from the Coros catalogue have one. So the first script downloads the catalogue -- 382 strength exercises -- together with my existing workouts and the calendar. The catalogue is a single GET request with sportType 4 for strength:

exercises = c.request("/training/exercise/query",
                      params={"userId": c.user_id, "sportType": 4})
save("exercises_strength.json", exercises)  # data/exercises_strength.json

Claude searches this file for every exercise on my list:

$ jq -r '.data[].overview' data/exercises_strength.json | grep -i plank

Most exercises matched directly. Some only under another name: the Pallof press is called "kneeling anti-rotational press". Three of the eight exercises were missing, and Claude suggested similar ones from the catalogue instead.

Only some Coros exercises have left and right sides. For the others, "3 sets per side" became 6 sets and "10 reps per side" became 20 reps.

The result is one YAML file per workout, referencing the catalogue keys:

name: Strength C
overview: Lateral stability
exercises:
  - exercise: sid_strength_side_plank
    sets: 6
    time: 30
    rest: 30
  - exercise: sid_strength_bird_dog_balance
    sets: 3
    reps: 20
    rest: 30

Uploading

In coros-training-mcp every exercise is built from scratch out of a few values the caller passes in. The push script instead copies the whole catalogue entry and overwrites only what differs per workout:

e = copy.deepcopy(catalogue[key])
e.update({
    "id": i + 1,
    "originId": catalogue[key]["id"],
    "sets": sets,
    "targetType": target_type,  # 2 = time, 3 = reps
    "targetValue": value,
    "restType": 1,
    "restValue": rest,
    "sortNo": (i + 1) * 16777216,  # same spacing as Training Hub
})
if "weight" in ex:  # kg, Training Hub stores grams
    e.update({"intensityType": 1, "intensityValue": round(ex["weight"] * 1000)})

This covers three things coros-training-mcp does not handle:

  • Sets per exercise. coros-training-mcp always uses one set per exercise and can only repeat the whole circuit.

  • Weights. coros-training-mcp always sends 0.

  • Reps in the time estimate. coros-training-mcp counts them as 0 seconds, the push script assumes 4 seconds per rep, like Training Hub does, plus the rest after every set.

With this estimate Strength C takes 29 instead of the planned 20 minutes, because Coros adds a rest after every set, also between the two sides.

For the rest of the payload my existing Strength A, created in the Android app, served as the reference for which fields Training Hub expects.

On the watch

The watch shows each exercise with its target, sets and rest (left) and plays the animation from the catalogue (right).

img1img2

How much of the Sprites trial credit did I use?

Fly.io gives a $30 trial credit for Sprites and I wanted to know how much of it is left. I run one sprite as a simple service since August 2nd -- the one from Getting a sprite to talk to my tailnet-only Forgejo.

The dashboard shows the credit used only per invoice, not a remaining balance. The Fly GraphQL API has no invoices at all, only creditBalance and billingStatus on the organization. So I downloaded this year's invoices as PDF and summed the "Sprites: Trial Credit applied" lines:

for f in Invoice-*.pdf; do
  pdftotext -layout "$f" - | grep 'Sprites: Trial Credit applied'
done

The months with actual usage (the invoice is issued at the start of the following month):

usage      CPU     RAM    storage  total
August     $0.06   $0.41  $0.02    $0.49
September  $0.22   $2.79  $0.38    $3.39
October    $0.10   $1.25  $0.41    $1.76
total      $0.37   $4.44  $0.81    $5.64

So $5.64 used and $24.36 left. RAM is nearly 80% of the cost.

In September I added features and the service was running more, in October it was mostly passive. October is the realistic baseline. October also had lower rates: CPU went from $0.07 to $0.0385 and RAM from $0.04375 to $0.021875 per unit, so the same usage costs about half.

At $1.76 per month the remaining credit lasts about 14 months. Storage will grow, but it is only $0.41 of that. Even with four times the storage it would be about $3 per month and still last 8 months.

ESP32-CAM: fixing the flash timing

This is a follow-up to ESPHome: ESP32-CAM. Every day at 10:30 a Raspberry PI sends the latest photo of my heating sensor into a Matrix room. For the last few days the image looked like this:

img1

The image is cut off, the JPEG is incomplete. This worked for months, but in the last weeks more and more images broke during the transfer. The flash was switched on in on_image, so the ESP32 decided by itself when the LED is on and the PI just downloaded whatever it got.

Now the on_image block is removed from the ESPHome config and the PI switches the flash: on, wait 2 seconds, request the image, off. The ESPHome web server has a REST endpoint for the light.

The new capture.sh on the PI:

#!/bin/sh
ESP=192.168.0.11

cd /home/pi/images
P="`date +%Y`/`date +%m`"
mkdir -p $P
OUT=$P/`date +%s`.jpg
TMP=capture.tmp

# A finished JPEG ends with the EOI marker ff d9.
complete() {
    [ "$(tail -c 2 "$1" 2>/dev/null | od -An -tx1 | tr -d ' \n')" = "ffd9" ]
}

flash() { curl -s -m 5 -d '' "http://$ESP/light/Camera%20flash/$1" > /dev/null; }
flash turn_on
trap 'flash turn_off; rm -f $TMP' EXIT
sleep 2

# The first two snapshots are buffered or still adjusting to the flash.
for i in 1 2; do curl -s -m 20 -o /dev/null http://$ESP:8081/; done
for i in 1 2 3; do
    curl -s -m 20 -o $TMP http://$ESP:8081/ && complete $TMP && break
    rm -f $TMP
    sleep 2
done
[ -f $TMP ] || { echo "no complete image from $ESP" >&2; exit 1; }

mv $TMP $OUT
ln -sf ./$OUT current.jpg

Only a complete image replaces current.jpg, so Matrix gets the current photo instead of a broken one. An example of a working image:

img2