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

An org-mode inbox fed from a Matrix room

The bots in Matrix status messages from a cron job and A daily morning summary in Matrix only write into Matrix. This one goes the other way: I write a message into a Matrix room, and it ends up as a TODO in an org-mode file in my notes repo.

The setup is a Forgejo Action that runs once an hour. It reads the room, adds every new message from me to matrix-inbox.org, commits and pushes the file, and then reacts to the message with a checkmark.

img1

The bot has its own account @org-bot on my Conduit homeserver. The access token is stored as a Forgejo secret.

The room is not encrypted to reduce complications with olm/megolm persistence.

Reading the room

The script uses the plain client-server API with httpx. It fetches the last 100 events of the room with /messages?dir=b, so the newest event comes first. Then it collects the bot's checkmarks and walks back through my messages until it hits one that is already acked:

acked = {
    ev["content"]["m.relates_to"]["event_id"]
    for ev in events
    if ev["type"] == "m.reaction" and ev["sender"] == BOT
}

new = []
for ev in events:
    if ev["type"] != "m.room.message" or ev["sender"] != OWNER:
        continue
    if ev["event_id"] in acked:
        break  # everything older is acked too
    new.append(ev)

The script skips edits, otherwise fixing a typo in Matrix would add a new entry.

The inbox file

The first line of a message becomes the headline, every further line becomes the body. Entries are grouped by day, newest day on top and newest entry on top within a day:

#+STARTUP: showeverything
#+TITLE: Matrix inbox

* matrix inbox entries

** 2026-10-31

*** TODO prepare a draft blog post for the matrix org bot
*** TODO check the airpressure on the cube29

Ack only after the push

The order matters: if the bot reacts before the push and the push fails, the message is acked but the entry is lost with the runner. So the script has two modes, matrix-inbox.py to add the messages and matrix-inbox.py ack to react, and the git part stays in the workflow between them:

steps:
  - uses: actions/checkout@v7
    with:
      token: ${{ secrets.GITHUB_TOKEN }}
  - name: Install uv
    uses: https://github.com/astral-sh/setup-uv@v6
  - name: Add new messages to inbox
    run: uv run matrix-inbox.py
  - name: Commit and push
    run: |
      git config user.name "Automated"
      git config user.email "actions@forgejo.local"
      git remote set-url origin https://oauth2:${{ secrets.GITHUB_TOKEN }}@forgejo.example.com/${{ github.repository }}
      git add matrix-inbox.org
      git diff --staged --quiet || git commit -m "matrix inbox - $(TZ=Europe/Berlin date +'%Y-%m-%d %H:%M')"
      git push
  - name: Ack messages
    run: uv run matrix-inbox.py ack

The event ids of the added messages are handed from the first uv run matrix-inbox to the second one via a small file in $RUNNER_TEMP.