Hi Home Assistant Community,
I’m developing a Home Assistant add-on and facing an issue with reading the SUPERVISOR_TOKEN
.
Here’s a summary of the situation:
- Add-on Repository: GitHub - wooooooooooook/HAaddons: homeassistant addons
- Problematic Add-on:
HeatMapBuilder
- Issue:
In Python,os.environ.get("SUPERVISOR_TOKEN")
returnsNone
. (See (/HeatMapBuilder/apps/app.py#L107)
Even runningecho $SUPERVISOR_TOKEN
inrun.sh
returns nothing.
config.json
already includes"hassio_api": true
Recent Changes
I changed the base image in Dockerfile
from python:3
to a Home Assistant image:
Dockerfile
ARG BUILD_ARCH=amd64
FROM ghcr.io/home-assistant/${BUILD_ARCH}-base-python:3.13-alpine3.21
Mystery Part 1
The add-on CommaxWallpadAddon
, which uses the same structure, works perfectly fine. (CommaxWallpadAddon)
Mystery Part 2
After installing the HeatMapBuilder
add-on, if I enter the Docker container via the Advanced SSH & Web Terminal
add-on (using docker exec -it addon_d31743d4_heatmapbuilder /bin/sh
), running run.sh
or executing app.py
directly shows the SUPERVISOR_TOKEN
without any issue.
Suspected Cause
I thought it might be a timing issue with when the supervisor injects the token. So I tried adding a waiting script in run.sh
:
#!/usr/bin/with-contenv bashio
set -e
TIMEOUT=30
# Wait for SUPERVISOR_TOKEN
while [ $TIMEOUT -gt 0 ] && [ -z "$SUPERVISOR_TOKEN" ]; do
echo "Waiting for SUPERVISOR_TOKEN environment variable to be set..."
sleep 1
TIMEOUT=$(( TIMEOUT - 1 ))
done
if [ -z "$SUPERVISOR_TOKEN" ]; then
echo "Error: SUPERVISOR_TOKEN environment variable not set after waiting."
exit 1
fi
echo "SUPERVISOR_TOKEN is set, starting app..."
exec python app.py
However, this script times out without ever detecting the SUPERVISOR_TOKEN
.
Question
Why is SUPERVISOR_TOKEN
not available when the add-on starts, but it works when manually running run.sh
inside the container? Could this be a timing issue or something related to the base image?
Any advice or suggestions would be greatly appreciated!