casita
The missing Home Assistant CLI for your agent.
casita lets an AI agent ask your Home Assistant what's on, what needs attention and why something changed, and get short, structured answers back. It reads the state of only what you've exposed to Assist, and runs only the scripts you allow.
$ casita find "porch light" # find things by name, area or alias
$ casita find --device-class battery --below 20 # which batteries are dying?
$ casita log light.front_porch --since 24 # why did the porch light come on at 2 a.m.?
$ casita stats --device-class power # is this reading unusual for this hour?
$ casita view @on-by-area.sql --param min=5 # your own view, in SQL
$ casita run casita_porch_on --set /brightness=40 # run a script you allowed; previews first
$ casita view :maintenance # what needs attention?
{ "ha": { "catalog_age_s": 49, "state_age_s": 0, "state_stale": false, … },
"result": { "count": 2, "rows": [
{ "entity_id": "sensor.hallway_motion_battery", "state": "14", "unit": "%", "issue": "low_battery", … },
{ "entity_id": "sensor.smoke_detector_battery", "state": "9", "unit": "%", "issue": "low_battery", … } ], … } }
Quickstart · What it can reach · For agents
What it does
Find and read
casita find kitchen # full text over name, id, alias, area
casita find --domain lock --state unlocked # by domain and live state
casita find --area Office --device-class temperature --above 25 # filters combine
casita state sensor.kitchen_temperature # one entity with attributes
casita area "Kitchen" # everything in a room
casita overview # per-area rollup
Search runs against a local SQLite mirror, so a warm find makes no call to Home Assistant.
Built-in views
casita view :<name> runs a built-in view. Three of them return exceptions only and make up a sweep; each catches a failure the others can't see:
| View |
Surfaces |
:maintenance |
Low batteries, unavailable devices, pending updates |
:health |
Devices whose own connectivity sensor says they're offline |
:stale |
Sensors that should be streaming and have gone silent, while their device still looks fine |
:stale is keyed on Home Assistant's last_reported heartbeat, not on the value changing, so a temperature that has been 21.5° all day is healthy and a probe that stopped reporting is not.
Also included: :active (what is on, open or running), :rollup (per-area counts), :sensors (readings for a device class), :consumables (refill, replace, swap), :comfort (climate drift from setpoint) and :air (air quality by metric). Three more need a specific integration: :energy (Emporia Vue), :fleet (Tesla Fleet) and :grounds (Rain Bird, Plant). casita view with no argument lists them all with their parameters.
Some devices report a state that looks like a fault and isn't, such as a printer that sleeps. Tell casita once and the views stop raising it; casita view :muted lists what is currently suppressed. See Teaching it what normal looks like.
Why did that happen
casita log light.front_porch --since 24 # one entity: state transitions and logbook
casita log --since 6 # house-wide recent activity
Is this number unusual
casita stats reads Home Assistant's long-term statistics and reports facts, not verdicts.
casita stats --device-class power # now vs the same hour of day over the last week
casita stats --device-class temperature --trend # this week vs last, with each entity's share of the change
The hour-of-day baseline matters: a circuit can sit at its daily average and still be far out of line for 3 a.m.
Your own views
casita view "<SELECT …>" runs read-only SQL over the mirror, one row per entity, for whatever the built-in views don't cover. Results are capped at 500 rows.
casita view "SELECT area, COUNT(*) AS n FROM entities WHERE exposed=1 AND state='on' GROUP BY area"
Keep a view in a file and give it parameters with defaults:
-- on-by-area.sql: how many things are on, per area.
-- @param min=1
SELECT area, COUNT(*) AS n FROM entities
WHERE exposed = 1 AND state = 'on'
GROUP BY area HAVING n >= :min ORDER BY n DESC
casita view @on-by-area.sql --param min=5
Running a script
Off by default. To let casita run scripts, name them in ~/.casita/config.yaml:
policy:
write:
allow_prefixes: ["script.casita_"]
A script can then be run if it matches a prefix, is exposed to Assist, and matches no deny rule. casita checks all three against Home Assistant at the moment of the call, so un-exposing a script takes effect immediately.
$ casita actions --view result.actions
[ { "action": "script.casita_porch_on", "name": "Turn the porch light on",
"description": "Turn the porch light on", "fields": { "brightness": {} } } ]
$ casita run casita_porch_on --set /brightness=40 # preview: nothing is sent
{ "preview": { "service": "script.casita_porch_on", "data": { "brightness": 40 } },
"result": { "dry_run": true, "fired": false } }
$ casita run casita_porch_on --set /brightness=40 --execute --view result
{ "dry_run": false, "fired": true, "outcome": "completed",
"changed": [ { "entity_id": "light.front_porch", "state": "on" } ] }
$ casita run casita_porch_on --set /entity_id=lock.front_door --execute
{ "code": "INVALID_INPUT",
"message": "script.casita_porch_on does not declare \"entity_id\". Declared fields: \"brightness\"." }
- Preview first.
run sends nothing without --execute.
- Only declared fields. Home Assistant would turn any key into a script variable; casita passes only the fields the script declares, and at most 16384 characters of input in total.
- Required fields. A field the script marks
required must be given a value, or nothing is sent. Home Assistant does not enforce this itself: it starts the script and fails part-way.
changed lists the entities Home Assistant saw change, limited to ones the agent may read, and without the script itself. A device that reports late isn't in it, so an empty list doesn't mean nothing happened.
RUN_OUTCOME_UNKNOWN means the script was sent and Home Assistant didn't confirm it finished (it took over a minute, or the call failed). It may have run. casita never marks this retryable; check the effect before sending again. Home Assistant often gives no reason for a failure; the step it reached and the error are in the script's trace in Home Assistant, which casita does not read.
- Audit. casita keeps a log in
~/.casita/audit/<month>.ndjson: refusals with their reason, previews, and for a fire a record before it is sent and another with the outcome. One of those is a guarantee: the record before a fire is sent, and if it can't be written the script isn't sent. The rest are best effort.
What it can reach
Two rules decide what casita can read and what it can run:
readable = exposed to Assist AND NOT denied in config.yaml
runnable = a script AND exposed to Assist AND matches an allow prefix AND NOT matches a deny rule
Anything else is refused:
$ casita state camera.nursery
{ "code": "READ_NOT_ALLOWED",
"message": "camera.nursery is not readable (not exposed to Assist, or policy-denied)." }
- State and attributes are stored in the mirror only for readable entities, so no query, including hand-written SQL, can return them for anything else.
- The only thing casita ever asks Home Assistant to do is run a script on the runnable list. There is no command that calls another service.
- The Home Assistant URL and token come from the environment and config file. No command that talks to Home Assistant accepts either as an argument.
casita init --url only seeds a new config; it never replaces an existing one, and it is not served over MCP.
What it does disclose: view can list the ids, names and areas of entities you haven't exposed, without their state. Un-exposing an entity in Home Assistant takes effect for reads at the next catalog refresh (usually within the hour and never more than two with the default settings; casita catalog refresh applies it now).
What running scripts does not limit
- casita limits which scripts run, not what a script does. A deny rule such as
*garage* matches the script's entity id. It stops script.casita_open_garage and does not stop a script.casita_goodnight that opens the garage.
- Your scripts are the boundary. Keep each one single-purpose. The agent chooses the value of every field, so a field that picks a target or an action turns the script into a general remote.
- Preview-by-default prevents accidents, not intent. An agent can pass
--execute itself, and over MCP nobody confirms.
- Checking and sending are two steps. A script un-exposed in the moment between them is still sent.
- The house talks to the agent. Entity names and logbook messages reach it as text and can ask it to run something.
Where the boundary is
casita limits what an agent can do through casita. How much that is worth depends on where the agent runs:
- casita is the agent's only route to the house (connected over MCP with no shell, or sandboxed without the token and without network access to Home Assistant): the limits above are designed to be the agent's limits.
- The agent also has a shell as the same user: it can read the token casita uses and call Home Assistant directly. Here casita keeps a well-behaved agent on a narrow path. It does not contain a hostile one.
casita holds a Home Assistant token, and a non-admin token is not a scoped one: Home Assistant will let it read every state and call services. Everything narrower than that is casita's doing. The project has had no security review by anyone outside it. To report a problem, see SECURITY.md.
Quickstart
Requires Node 22.16+ (casita uses the built-in node:sqlite with FTS5; there is nothing native to build).
npm install -g casita # the CLI
casita skills add # the skill: into ~/.agents/skills, linked into Claude Code
casita init --url http://homeassistant.local:8123 # writes ~/.casita/config.yaml; never a token
export CASITA_HA_TOKEN=<long-lived access token> # an admin user's token to start; see Tokens
casita doctor # config, token, reachability, what's readable
casita find kitchen
casita doctor reports the scope casita will work within, for example exposed=312 readable=312 writable=0. Expose entities in Home Assistant under Settings → Voice assistants → Expose. A fresh config is read-only.
Installing the skill
casita skills add installs the skill that ships with the CLI you have, so the two always match. It writes to ~/.agents/skills, which several coding agents read, and links the skill into Claude Code's folder when Claude Code is present. For the rest:
| Agent |
Command |
| OpenClaw, Hermes |
npx skills add igrigorik/casita |
| Hermes, straight from GitHub |
hermes skills install igrigorik/casita/skills/casita |
| Claude Code, as a plugin |
claude plugin marketplace add igrigorik/casita, then claude plugin install casita@casita |
OpenClaw reads the skill's metadata and offers to install the casita command from npm if it is missing.
From source: git clone https://github.com/igrigorik/casita && cd casita && pnpm install && pnpm build && npm install -g .
For agents
- Skill:
skills/casita/SKILL.md maps what a person asks to what to run, and carries the heuristics that keep a sweep from crying wolf. Install it with casita skills add (see Quickstart).
- Pointing an agent at this repo:
AGENTS.md tells it how to install and check casita.
- MCP:
casita --mcp serves the same commands to a host with no shell. See Over MCP.
Over MCP
casita --mcp runs casita as an MCP server over stdio. Register it the way your host registers any stdio server, with the token in its environment:
{ "mcpServers": { "casita": {
"command": "casita", "args": ["--mcp"],
"env": { "CASITA_HA_TOKEN": "<long-lived access token>" } } } }
In Claude Code: claude mcp add casita -e CASITA_HA_TOKEN=<token> -- casita --mcp. Either way the token then lives in the host's configuration.
The host sees twelve tools, one per command: find, state, area, overview, view, log, stats, actions, doctor, catalog_refresh, catalog_show and run. Eleven are marked read-only. run is not, so a host that asks before a tool changes something asks before run and nothing else. init is not offered: a config cannot be created over MCP.
Everything under What it can reach applies unchanged. A host with no shell is the setup where casita's limits are the agent's limits; see Where the boundary is.
Output and freshness
JSON by default; --format md|yaml|toon|jsonl. --view '<jmespath>' reshapes any result, and --token-limit bounds it.
Every answer says how old it is:
"ha": { "catalog_age_s": 41, "state_age_s": 6, "state_stale": false }
Structure and exposure are cached for an hour and refreshed in the background. State older than 30 seconds is re-pulled when a command depends on it. --fresh forces a live pull, and if Home Assistant can't be reached the answer is marked stale instead of passed off as current.
Configuration
casita init writes ~/.casita/config.yaml:
ha_url: http://homeassistant.local:8123
token_env: CASITA_HA_TOKEN # the NAME of the variable; the token is never written here
# admin_token_env: CASITA_HA_ADMIN_TOKEN
catalog_ttl_s: 3600
state_ttl_s: 30
policy:
read:
deny_domains: [] # e.g. [camera]
deny_entities: [] # globs, e.g. ["*bedroom*"]
write:
allow_prefixes: [] # [] = read-only. ["script.casita_"] to run those scripts
deny_entities: ["*garage*", "*main_water*", "*tesla*command*"] # match the script's entity id
Tokens
Reading states, history, the logbook and statistics, and running a script, work with a non-admin user's token. Reading the entity registries and the exposure list does not: Home Assistant restricts that to administrators. casita makes that read in catalog refresh, and in actions and run, which check exposure live. Set CASITA_HA_ADMIN_TOKEN as well and casita uses it for that read and nothing else; with one token, that token has to be an admin's. casita doctor tells you which situation you're in.
Teaching it what normal looks like
Some devices report a state that looks like a fault and isn't: a printer that sleeps, a smart bulb on a switched circuit. Put that in ~/.casita/context.yaml once and the views stop raising it:
context:
- match: "sensor.photo_printer_*"
text: "Sleeps when idle; 'unavailable' is normal."
normal_states: [unavailable]
- match: binary_sensor.plant_sensor_online
text: "Deep-sleep sensor; 'off' between wakes is normal."
normal_states: [off]
max_silence_h: 30 # muted only while it keeps reporting