Cloudflare AI Agent (Conversation) for Home Assistant

LLM Disclaimer: This project was built with significant help from AI. But I kinda know what I’m doing.


Why I Built This

I wanted a voice assistant experience in Home Assistant that felt as natural as Google Home or Alexa. Home Assistant has excellent voice satellite hardware support, but the AI conversation side has some friction.

The existing LLM integrations for HA (OpenAI, Anthropic, Google, etc.) all work the same way: on every single request, they serialize your entire exposed entity list — every light, sensor, switch, media player and send it as context to the model. In a moderately sized smart home, that’s thousands of tokens per request. This means:

  • It’s slow. Packing and sending all that context adds latency on every voice command.

  • It’s expensive. You’re paying for thousands of input tokens just to turn on a light.

  • It shares everything. Your full home topology — device names, areas, entity states — goes to the LLM provider on every request, whether relevant or not.

How This Project Is Different

Instead of sending your entire home to the model, this project flips the architecture. A persistent AI agent runs on Cloudflare Workers and connects directly to Home Assistant’s MCP (Model Context Protocol) server. The agent discovers available tools — lights, climate, media, scripts — once, and then calls them on demand.

When you speak to a voice satellite, Home Assistant sends the agent just ~200 bytes: your text, which room you’re in, and a conversation ID. The agent already knows what tools are available. It reasons about your request, calls the right tool with the right area parameter, and responds.

The key pieces:

  • Cloudflare Workers + Durable Objects — The agent runs as a Durable Object with persistent state. The MCP connection and tool list survive across requests. A cron job keeps it warm so there’s no cold start penalty.

  • MCP — The agent connects to HA’s MCP server and discovers tools dynamically. It only interacts with entities when it needs to, through tool calls. Your entity list never leaves your HA instance in bulk.

  • Custom HA Integration — The HA integration resolves which room the voice satellite is in and sends only that context.

  • Extensible via HA scripts — Any HA script you expose via Voice Assistants automatically appears as a tool the agent can call. This is how I added Music Assistant queue management, favouriting tracks, and custom playback modes.

The whole system is two components: a Cloudflare Worker (TypeScript) and a Home Assistant custom integration (Python, installable via HACS).

Try It

The project is available on GitHub: github.com/nnmalex/ha-ai-conversation-cloudflare

Setup takes about 10 minutes — deploy the worker, install the integration via HACS, point it at your agent, and assign it to a voice assistant.

Feedback and contributions welcome.