n8n Home Assistant: Setup Guide & Automation Examples
Learn to integrate n8n with Home Assistant: setup guide, three working automations (climate, security, energy), and local vs. managed hosting comparison.
- n8n connects to Home Assistant via native nodes (easiest), webhooks (most flexible), or a community Docker add-on (fully local).
- Setup takes 10 minutes: generate a long-lived token, add credentials to n8n, test a node, then trigger automations for climate, security, and energy logging.
- Choose local n8n (sub-100ms latency, zero cost, full control) or managed hosting (99.9% uptime, $50-200/month, GDPR data centers available).
n8n integrates with Home Assistant through native nodes, webhooks, and REST APIs. This guide walks you through setup, three working automations you can copy today, and the decision between running n8n locally on your home network or on managed hosting. You'll go from token generation to triggering climate control and security alerts in under an hour.
What is n8n and Why Integrate with Home Assistant?
n8n is a fair-code workflow automation platform with 1,500+ integrations and 210,000+ GitHub stars. Home Assistant is a local-first home automation hub: privacy-focused, runs on a Raspberry Pi, and ships with 100+ official integrations. Neither platform does everything alone. Home Assistant handles device control and state management; n8n adds complex logic, multi-step workflows, and connections to external services (email, Slack, Google Sheets, weather APIs, LLMs). Together, they handle scenarios Home Assistant's built-in automations cannot: conditional logic spanning multiple data sources, transformations, error recovery, and cost tracking. For example, a temperature sensor in Home Assistant can trigger an n8n workflow that queries the weather API, checks occupancy, calculates heating cost, decides whether to turn on the AC, and logs the decision to Google Sheets--all in one triggered automation. n8n handles the orchestration. Home Assistant handles the devices. This pairing scales: from a single motion sensor to a multi-room smart home with 50+ automations.
Three Ways to Connect n8n and Home Assistant
n8n supports three integration methods, each with different tradeoffs: Option A: Native n8n Home Assistant Node is the simplest path. The node ships in n8n's core library. You authenticate with a long-lived access token, then use drag-and-drop actions to call services, fetch entity states, and render templates. Setup takes 5 minutes. Latency is typically under 500ms. Best for: single-server setups, users new to n8n, production workflows where simplicity matters. Option B: Webhooks is bidirectional. Home Assistant POSTs data to an n8n webhook URL when a trigger fires (motion detected, door opened, temperature threshold crossed). n8n receives, processes, and POSTs back to Home Assistant's REST API to call a service. This is more flexible: you can run complex logic, branch workflows, and batch operations. Setup is moderate--you need a reachable URL. Best for: advanced users, scenarios requiring branching or external service calls. Option C: Community Add-On (Rbillon59/hass-n8n) runs n8n inside Home Assistant itself, via Docker. Zero external hosting, instant latency, full local control. Trade-off: you manage updates and backups; it consumes Raspberry Pi RAM. Best for: purists wanting everything local, air-gapped networks, hobbyists not running other services. The comparison table shows setup difficulty, latency, and best-fit scenarios.
| Method | Setup Time | Latency | Best For | Downside |
|---|---|---|---|---|
| Native Node | 5 min | <500ms | Production, simplicity | Requires external n8n instance |
| Webhooks | 15 min | 100-1000ms | Complexity, branching | URL management, debugging harder |
| Community Add-On | 20 min | <50ms | Local-only, hobbyists | Raspberry Pi resources, manual updates |
Step-by-Step: Set Up n8n + Home Assistant (10 Minutes)
This is the native node method: fastest and most reliable. First, generate a long-lived access token in Home Assistant. Log into the Home Assistant UI. Click your profile (bottom left). Scroll to "Long-Lived Access Tokens." Click "Create Token," give it a name (e.g., "n8n Integration"), and copy the token immediately--you can't retrieve it again. Second, add credentials to n8n. In n8n, click Credentials. Click New Credential. Search for "Home Assistant." Paste the token. Enter your Home Assistant URL (for example, your local IP like 192.168.1.100:8123, or your external URL if running n8n remotely). Click Create. Third, add a Home Assistant node to your workflow. Click Add Node. Search "Home Assistant." Select "Get Entity State" or "Call Service." Choose your credential. Pick an entity (e.g., "sensor.living_room_temperature"). Click Execute. If the node runs and returns data, you're connected. If you see an error, check these common fixes: (1) "Home Assistant URL not reachable from n8n": Verify your URL is correct and your firewall allows HTTP/HTTPS traffic. If n8n is remote and Home Assistant is on a home VLAN, you need an external URL or tunnel. (2) "Invalid token": Tokens can expire if regenerated or if Home Assistant was restarted. Regenerate the token and update n8n credentials. (3) "Entity not found": Check Home Assistant's Developer Tools (Settings > Developer Tools > States) to confirm the entity ID matches exactly (case-sensitive). Home Assistant uses sensor.name, not Sensor.Name.
Automation #1: Temperature-Triggered Climate Control
This workflow triggers when a temperature sensor exceeds a threshold, then adjusts your AC. Build it like this: When living room temperature > 25C, turn on the AC and set it to 22C. Home Assistant's built-in automations can do this, but n8n adds power: you can read multiple sensors, check the time of day, verify no one is home, log to Google Sheets, and send a notification--all conditional. Workflow structure: (1) Trigger: "Home Assistant - State Changed." Listen to sensor.living_room_temperature. (2) Condition: Check if the value is > 25. (3) Action: Call Home Assistant service climate.set_temperature on climate.ac_living_room, set temperature to 22. Test it: Set the trigger entity to a low threshold (e.g., > 20) so you can test with current conditions. Run the workflow. Check Home Assistant's history to confirm the AC turned on. After testing, increase the threshold to 25. To debug, check n8n's execution history: click the workflow, then Executions. Click a failed run to see error details. If "Service not found," verify the service name in Home Assistant's Developer Tools. If the service runs but doesn't work, check Home Assistant's device settings--some climate entities don't support temperature setpoints. For production use, store your threshold (25C) as a workflow variable, so you can change it without editing the workflow. Add a Slack or email notification node after the service call, so you're notified whenever the AC turns on.
Automation #2: Motion Detection + Multi-Channel Alerts
Motion triggers n8n, which sends alerts via Telegram, email, and mobile app simultaneously. This is where n8n outshines Home Assistant: Home Assistant can send to one channel; n8n routes to many and enriches data. Workflow structure: (1) Trigger: "Home Assistant - State Changed." Listen to binary_sensor.hallway_motion. Trigger when it changes to "on". (2) Condition: Check if you are away (read input_boolean.away_mode state). Skip alert if you're home. (3) Parallel actions: (a) Send Telegram message: "Motion detected in hallway." (b) Send Gmail: "Motion alert at [timestamp]." Include a camera snapshot URL if available. (c) Call Home Assistant service to turn on hallway lights. (d) Log to Google Sheets: timestamp, location, occupancy state. The power here: Home Assistant binary sensor -> n8n's conditional logic -> three different services, all in parallel. If you wanted this in Home Assistant alone, you'd need three separate automations and lose the data logging. To set up Telegram: Get a bot token from BotFather on Telegram. In n8n, add Credentials for Telegram. Add a "Telegram" node with the message text. For Gmail, add OAuth2 credentials to n8n, then add a "Gmail" node with recipient, subject, and body. Test with a forced motion detection: in Home Assistant Developer Tools, call homeassistant.turn_on on the motion sensor manually. Verify all three notifications arrive. For production, add error handling: if Telegram fails, the email should still send. Use "Try/Catch" node or add an "If" node after each notification to handle failures gracefully.
Automation #3: Energy Logging + Reporting
Daily energy consumption from Home Assistant sensors are logged to Google Sheets; an email summary is sent every evening. Home Assistant has no native integration with Google Sheets; n8n bridges it. Workflow structure: (1) Trigger: Time-based, every day at 23:00. (2) Read all energy sensors from Home Assistant: sensor.energy_total_kwh, sensor.solar_production_kwh. (3) Transform data: Use JavaScript to calculate cost (multiply kWh by your rate, e.g., $0.12/kWh), sum by room, and format as a row. (4) Append to Google Sheets: Add a new row with timestamp, consumption, cost, solar production. (5) Send email summary: "Yesterday you used 15 kWh, costing $1.80. Solar produced 8 kWh." To set up Google Sheets: Create a sheet with columns: Date, Total kWh, Cost, Solar kWh. In n8n, add Google Sheets credentials (OAuth2). Add a "Google Sheets" node with "Append row" operation. For the email, use a Gmail node. The transformation snippet (JavaScript in an "Edit Fields" node) might look like:
return [{
date: new Date().toISOString().split('T')[0],
kwh: parseFloat(data.energy_total_kwh),
cost: parseFloat(data.energy_total_kwh) * 0.12,
solar: parseFloat(data.solar_production_kwh)
}];
Test by running manually. Check Google Sheets to verify a row was appended. After one day, review the email to confirm the summary is readable. For production, add error handling: if Google Sheets is unreachable, log to a fallback (Slack message or local file). Add a notification to Home Assistant so you see the summary in the app as well.
Local vs. Managed n8n: Which Should You Choose?
This decision affects uptime, latency, ops load, and cost. Local n8n (Docker on a Raspberry Pi, NAS, or home server): Latency is sub-100ms--instant communication with Home Assistant on the same network. Privacy: everything stays local, no data sent to external servers. Control: you own the infrastructure, can inspect logs, and modify anything. Downsides: If your Raspberry Pi crashes, workflows stop until you restart it. Backups are your job. n8n updates are manual. If your home internet drops, some external service calls fail (but local triggers still work). Cost: typically your hardware cost (already paid). Best for: home hobbyists, privacy advocates, networks too restrictive for external services. Managed Hosting (Opsily, n8n Cloud, etc.): Uptime is typically 99.9%, guaranteed by the provider. Backups and updates are automatic. You don't manage infrastructure. EU hosting is available, so data residency can be GDPR-compliant if that's required. Scaling is instant--you don't worry about Raspberry Pi RAM or CPU limits. Downsides: Monthly cost, starts around $50/month. Webhooks require a stable external URL (but HTTP reverse proxies handle this). Latency is 500ms-2s over the internet. If your internet drops, workflows can't reach Home Assistant (but Home Assistant automations still run). Best for: production workflows serving multiple people, businesses, scenarios requiring guaranteed uptime, organizations with compliance requirements. The decision matrix:
| Factor | Local | Managed |
|---|---|---|
| Latency | <100ms | 500ms-2s |
| Uptime Guarantee | Yours | 99.9% |
| Monthly Cost | $0 | $50-200 |
| Ops Load | High | Low |
| Data Residency | Local | Depends on provider |
| Best For | Hobbyists, privacy | Production, teams |
If you are running 5-10 automations and they can tolerate occasional downtime, go local. If you are building automations that control heating/cooling or security, or if your workflows call external services (weather APIs, Telegram, Google Sheets), consider managed. Many users start local and migrate to managed as complexity grows. Need help choosing? See our n8n hosting options page for a detailed comparison.
Troubleshooting & Next Steps
Connection fails: "Home Assistant URL not reachable from n8n." This is the #1 problem. If n8n is local (Raspberry Pi), it can reach Home Assistant instantly--both are on your LAN. If n8n is remote (managed hosting), it must reach Home Assistant over the internet, which requires an external URL or port forwarding. For remote n8n: Use Cloudflare Tunnel (free), Tailscale, or a reverse proxy to expose Home Assistant safely. Never open port 8123 directly to the internet. If you use managed hosting like Opsily, documentation covers security best practices. Authentication fails: "Invalid token" or "Unauthorized." Long-lived tokens in Home Assistant can expire if regenerated or if Home Assistant restarts. If auth fails, go to Home Assistant profile, generate a new token, and update n8n credentials. Test immediately. Workflow triggers but service call fails. The service name is likely wrong. Home Assistant service names are domain.service: light.turn_on, switch.toggle, climate.set_temperature. Verify in Developer Tools under "Services." Copy the exact name. Rate limits hit: "Too many requests in a short time." If you query sensors every second, Home Assistant will reject requests. Add delays or batch operations. Use triggers instead: listen for state changes rather than polling. Workflows stop without warning. If running local n8n on a Raspberry Pi, check disk space and RAM. Use df -h and free -m. If low, increase swap or migrate to managed hosting. Next steps: Explore n8n's AI agents. n8n now supports MCP (Model Context Protocol) servers, so LLMs can read Home Assistant states and trigger workflows. This is emerging--not production-ready yet, but powerful for voice-triggered automations. Join the n8n community forum to stay updated. Ready to scale? See our managed n8n hosting plans and find a provider that fits your needs.
Frequently Asked Questions
How do I set up Home Assistant integration in n8n?
Generate a long-lived access token in Home Assistant (Settings > Profile > Long-Lived Access Tokens). In n8n, create a Home Assistant credential with the token and your Home Assistant URL. Add a Home Assistant node to your workflow and test with "Get Entity State." The process takes 5 minutes.
Do I need special permissions or API keys to integrate Home Assistant with n8n?
Yes. Home Assistant requires a long-lived access token (not basic username/password). The token is associated with your user account. If you need separate tokens for different workflows, create multiple tokens or a separate Home Assistant user account. Tokens can be revoked anytime from the Home Assistant UI.
Can I combine Home Assistant with other apps in n8n workflows?
Yes, that's the main point. Trigger from Home Assistant, then route to Slack, Gmail, Google Sheets, Telegram, or any of n8n's 1,500+ integrations. Add conditional logic, transformations, and parallel actions. This is why n8n is powerful: Home Assistant handles devices; n8n orchestrates everything else.
What are common use cases for Home Assistant integrations with n8n?
Temperature-triggered climate control, motion-detected multi-channel alerts, energy logging to Google Sheets, occupancy-based scene changes, weather-aware outdoor lighting, voice assistant integration for complex workflows, security camera snapshots with alerts, and cost tracking for appliances. Any scenario requiring multi-step logic or external services fits.
How does n8n's pricing model benefit me when integrating Home Assistant?
n8n is free if self-hosted locally. If using managed hosting, you pay for execution minutes (the time workflows run, not idle time). For Home Assistant, most workflows run on triggers (a motion sensor activates once) or schedules (daily reports), so costs are predictable. Managed hosting typically costs $50-200/month depending on volume, often less than Home Assistant add-ons requiring dedicated hardware.
What's the difference between running n8n locally vs. in the cloud for Home Assistant?
Local n8n (Raspberry Pi): instant latency, zero cost, everything on your network, but uptime depends on your hardware and backups are your job. Cloud n8n (managed hosting): 99.9% uptime, automatic backups, no ops work, GDPR-compliant data centers available, but monthly cost and 500ms-2s latency. Local is for hobbyists; managed is for production.
What are common mistakes when connecting n8n and Home Assistant?
Using basic auth instead of long-lived tokens. Forgetting that the token is case-sensitive and must be copied in full. Mistyping entity names (they are case-sensitive: sensor.living_room_temperature, not Sensor.Living_Room_Temperature). Polling sensors every second instead of using triggers (wastes resources). Not testing connections with a forced state change before going to production. Assuming a Raspberry Pi can run Home Assistant and n8n simultaneously (RAM/CPU often insufficient--migrate n8n to a second device or managed hosting).
The Bottom Line
n8n and Home Assistant integrate via native nodes, webhooks, or a community add-on--pick based on your skill level and needs. Setup takes 10 minutes; the three automations in this guide are copy-paste-ready and cover climate, security, and energy logging. The real choice is local versus managed: home users usually start local and scale to managed hosting as workflows grow in complexity and importance. If you're running production automations that control climate, security, or critical devices, managed hosting is safer. If you're experimenting, go local. Either way, explore Opsily's managed n8n hosting options to understand what cloud-native automation looks like when you're ready to scale.