May 27, 2026

Home assistant access token: create and use long-lived tokens

Reading time :  
7
 min
Aymeric Zhuo
Aymeric Zhuo

Home Assistant access token: create and use long-lived tokens

Every smart home automation that talks to Home Assistant from the outside needs one thing: an access token. According to Home Assistant's 2024 analytics, over 1.2 million active installations report data monthly, and the REST API is the primary integration point for custom automations.

This guide covers creating, using, and securing Home Assistant access tokens — then extends into building automated smart home workflows with CodeWords. Unlike generic AI automation posts, this guide shows real CodeWords workflows — not just theory.

How do you create a Home Assistant access token?

  1. Open your Home Assistant instance (usually http://homeassistant.local:8123).
  2. Click your profile avatar in the bottom-left sidebar.
  3. Scroll to Long-Lived Access Tokens.
  4. Click Create Token.
  5. Name it descriptively (e.g., codewords-automation).
  6. Copy the token immediately — Home Assistant displays it only once.

How do you use the access token with the REST API?

import requests

HA_URL = "http://homeassistant.local:8123"
TOKEN = "your_long_lived_access_token"

headers = {
    "Authorization": f"Bearer {TOKEN}",
    "Content-Type": "application/json"
}

# Turn on a light
requests.post(
    f"{HA_URL}/api/services/light/turn_on",
    headers=headers,
    json={"entity_id": "light.living_room"}
)

How do you build smart home automations with CodeWords?

A CodeWords workflow acts as the intelligence layer: making decisions that Home Assistant's YAML automations struggle with — external data, LLM decision-making, multi-service coordination.

Energy optimization: Query HA energy dashboard data, analyze consumption patterns with LLM reasoning, adjust device schedules for off-peak usage.

Anomaly detection: A scheduled workflow polls sensor data, detects unusual patterns (water usage spike, unexpected motion), and alerts you via multiple channels with context.

FAQs

How long does a long-lived access token last?
Indefinitely until you manually delete it from your profile page.

Can I create a token without admin access?
Yes. Any user account can create tokens; the token inherits that user's permission level.

Build smart home AI workflows →

Contents
Ready to try CodeWords?
Get started free
Sign in
Sign in