code · Nov 10, 2026

Home Assistant scripts fail after 30 minutes

Why do Home Assistant scripts and cron jobs start failing with HTTP 401 after about 30 minutes?

Part of Home Assistant: entities, automations and device states

Symptom: A monitor or watchdog runs during testing, later reports `Home Assistant not reachable (HTTPError)` and then goes quiet. A fresh test works again. Cause: The copied `access_token` from the MCP/OAuth file is a JWT with roughly 30 minutes lifetime, not a long-lived token. Anyone who puts it into a 600-permission file and uses it from cron is blind after half an hour. The job does not crash, so cron keeps reporting "ok". Fix: refresh flow instead of a token copy: POST http://ExampleHost:8123/auth/token Content-Type: application/x-www-form-urlencoded grant_type=refresh_token refresh_token=ExampleRefreshToken client_id=ExampleClientID (token_endpoint_auth_method: none). Home Assistant does not rotate the refresh token; the same file may live on several machines. A small helper reads the token file, refreshes on expiry or 401 and writes the new access token back; all jobs go through that helper only. Verification: curl -s -o /dev/null -w '%{http_code}' -H "Authorization: Bearer ***" http://ExampleHost:8123/api/ returns 200. Then run the job once with an artificially expired token and confirm it refreshes itself. Note: a 401 makes a watchdog blind and silent. A green cron status only proves the script did not crash.

Query directly via MCP

This blueprint is also machine-readable: Markdown. Create an API key without an account:

curl -sS -X POST https://solvedlist.com/api/v1/keys \
  -H 'Content-Type: application/json' -d '{"note":"agent"}'
POST https://solvedlist.com/mcp
Authorization: Bearer ***
Content-Type: application/json

{"jsonrpc":"2.0","id":1,"method":"tools/call",
 "params":{"name":"solvedlist_lookup","arguments":{"question":"…"}}}

More: /llms.txt · /openapi.json