Home Assistant on Raspberry Pi 5: AI-Powered Smart Home Automation with OpenCode

đŸŽĨ Watch the Video Tutorial


💡 Why Home Assistant + OpenCode?

Home Assistant is a powerful open-source home automation platform. But setting it up traditionally means writing YAML files, debugging automations, and spending hours configuring devices. OpenCode changes that. It’s an AI tool that gives you natural language access to your entire Home Assistant configuration. Instead of “write a YAML automation,” you just say “turn on lights when someone’s detected at the door” and OpenCode creates the automation for you. Combine Home Assistant OS on a Raspberry Pi 5 with OpenCode, and you’ve got a smart home system that’s powerful, local, private, and genuinely easy to use. By the end of this guide, you’ll have Home Assistant running on your Pi, all your devices discovered automatically, and OpenCode connected so you can build automations with AI assistance. â„šī¸ Note: Home Assistant OS is a complete operating system that runs on bare metal. It’s not a Docker container or a traditional Linux distro. Everything stays local on your network — no cloud dependency.

🛠 What You’ll Need

  • Raspberry Pi 5 with 8GB RAM (Pi 4 with 4GB works, but Pi 5 is recommended)
  • Storage: MicroSD card (32GB+ recommended) or NVMe drive with M.2 adapter
  • Power supply: Official Pi 5 power supply (27W recommended)
  • Local network with internet connectivity
  • Raspberry Pi Imager (free, official tool from Raspberry Pi Foundation)
  • OpenCode API key (free tier available)
  • Smart home devices on your network (cameras, switches, locks, speakers, etc.)
💡 Tip: I’m using a Pi 5 with 8GB RAM and an NVMe drive for faster boot times. SD card works fine but is slower. NVMe boot requires a Pi 5 and M.2 adapter.

📋 Step-by-Step Setup

1. Download Raspberry Pi Imager

Go to https://www.raspberrypi.com/software/ and download Raspberry Pi Imager for your operating system (Windows, Mac, or Linux). Install and launch it.

2. Select Your Hardware

In Raspberry Pi Imager, click “Choose device” Select Raspberry Pi 5

3. Select Home Assistant OS

Click “Choose OS” Navigate to Other specific-purpose OS Select Home Automation Select Home Assistant This is Home Assistant OS — the complete, optimized operating system.

4. Choose Your Storage

Click “Choose storage” Select your MicroSD card or NVMe drive

âš ī¸ Important: This will erase all data on the selected storage. Double-check you’ve selected the right device.

5. Write the Image

Click “Next” and then “Yes” to confirm. Raspberry Pi Imager writes the Home Assistant OS image to your storage. This takes 5-10 minutes depending on storage speed. Once complete, it will auto-eject. Insert your storage into your Pi and power it on.

6. Initial Boot

Home Assistant OS will take 5-10 minutes to boot the first time. You’ll see output on the Pi’s HDMI display (if connected) showing the boot progress. Once booted, you’ll see an IP address displayed on the screen (e.g., http://192.168.1.100:8123)

7. Access Home Assistant Web Interface

From another computer on your network, open a browser and navigate to:
http://[your-pi-ip]:8123
Or if you noted the IP from the display:
http://10.0.3.53:8123
You should see the Home Assistant setup page.

8. Create Your Account

Click “Create a new smart home” Enter a username (e.g., “demo”) Enter a secure password Click “Create account”

9. Configure Location & Settings

Enter your address (or leave as default) Select your country (important for timezone and units) Choose what analytics you want to send (optional) Click “Next” Home Assistant will automatically detect devices on your network (cameras, smart speakers, lights, etc.) These are displayed on the summary screen Click “Finish”

10. Install OpenCode Plugin

Go to Settings → Apps (this used to be called “Add-ons”) Look for the three-dot menu or “Add repository” button Paste this URL:
https://github.com/magnusoverli/opencode
The repository will be added Click back into Apps Find OpenCode in the list Click it and select Install

11. Configure OpenCode

Once installed, go to the OpenCode app page Check these boxes:
  • Start on boot (auto-start the service)
  • Auto-update (keep it current)
  • Show in sidebar (quick access)
Click Start OpenCode will start running on your Pi

12. Create OpenCode Account & API Key

In the OpenCode app sidebar (or at http://[your-pi]:8124), click “Connect” Select OpenCode Zen Go to the URL provided Click “Login” Choose “Continue with Google” (creates account automatically) Once logged in, go to API keys Click “Create new API key” Name it something descriptive (e.g., “home-assistant”) This helps track billing/usage if you scale up later Copy the API key

13. Connect API Key to OpenCode App

Go back to your Home Assistant OpenCode app in the sidebar Paste the API key into the configuration field Hit Enter/Save OpenCode will verify the connection Select your AI model (free tier recommends “deepset/deepseek-v2-lite-free”) Click “Ready to use”

14. Start Using OpenCode

Now you can ask OpenCode to create automations, recommendations, or help troubleshoot: “What automations would you recommend based on my devices?” “Create a scene that turns on living room lights at 50%” “Check my automations for duplicates or conflicts” “Create a face recognition automation for my doorbell” OpenCode has full access to your Home Assistant configuration and can create/modify automations based on your requests.

🔧 What You Can Do Now

Automation Creation: Ask OpenCode to create automations without writing YAML. “Turn on porch lights at sunset” becomes a real automation.

Smart Scenes: Build multi-device scenes with natural language. “Movie time” scene that dims lights, closes blinds, and sets TV input.

Face Recognition Automation: Use your camera to recognize family members. Example: “If [family member] is detected at doorbell, unlock the front door with 60-second cooldown and send notification.”

Device Integration Recommendations: OpenCode analyzes your devices and suggests useful automations you haven’t considered.

Automation Audit: Let OpenCode review your existing automations for duplicates, conflicts, or redundancy. It will clean them up for you.

Voice & Sonos Integration: Set up daily alarm automations using Sonos speakers, voice notifications, etc.

âš™ī¸ Understanding the Setup

Home Assistant OS: A complete operating system optimized for smart home automation. Runs directly on your Pi, not in Docker.

Device Discovery: Home Assistant automatically finds compatible devices on your network (smart lights, cameras, switches, locks).

Local First: All your automations, device configs, and sensor data stay on your Pi. No cloud upload required.

OpenCode: An AI layer that lets you interact with Home Assistant using natural language instead of YAML.

API Key: Secures your OpenCode connection. Keep it private. One key per project helps track usage.

Free Tier: OpenCode free tier works great for personal use. Paid tiers for higher API call volume.

💡 Practical Use Cases

Security Automation: “If motion is detected at the front door after 10 PM, turn on the porch lights and send me a notification with a camera snapshot.”

Comfort Automation: “When I arrive home (phone location detected), turn on entryway lights, set AC to 72°, and unlock the front door.”

Energy Optimization: “Turn off all lights in the kitchen after 30 minutes of no motion detected.”

Scheduled Tasks: “Every weekday at 6:30 AM, turn on the bedroom lights gradually and play my morning playlist on Sonos.”

Scene Creation: “When I say ‘Leaving home,’ lock all doors, turn off all lights, close blinds, and arm security system.”

Device Troubleshooting: “My bedroom lights sometimes turn on randomly. Can you find conflicting automations?”

âš ī¸ Important Considerations

Cooldown & Safety: Always add safeguards to automations. Example: Face recognition doorbell unlock includes a 60-second cooldown so a person can’t use the same scan to repeatedly unlock.

Local Network Only: Home Assistant runs locally. For remote access, you’d need a separate setup (Tailscale, VPN, subscription, or reverse proxy). This video covers local setup only.

API Key Security: Keep your OpenCode API key private. Don’t share it in public forums or commit to GitHub.

Device Compatibility: Not all smart devices integrate with Home Assistant. Check compatibility before purchasing. Generally, Zigbee, Z-Wave, WiFi-enabled, and MQTT devices work well.

Storage Reliability: Home Assistant stores your config and automations on storage. Use reliable, non-enterprise SD cards or NVMe. Backup regularly.

Free Tier Limits: OpenCode free tier has API call limits. Personal use is fine. Heavy automation triggering might hit limits.

🚀 What’s Next?

  • Add more smart devices (cameras, locks, lights, speakers)
  • Use OpenCode to create your own automations
  • Build complex multi-device scenes
  • Set up face recognition for your doorbell
  • Create automations based on device sensors (motion, temperature, humidity)
  • Integrate voice assistants (if supported by your devices)
  • Set up remote access (VPN, Nabu Casa, etc.)
  • Backup your Home Assistant configuration regularly

✅ Conclusion

Home Assistant on Raspberry Pi 5 gives you a powerful, local smart home system. Add OpenCode and you get AI-assisted automation without needing to learn YAML. The setup is straightforward: flash Home Assistant OS, create your account, install OpenCode plugin, connect your API key, and start building automations with natural language. Everything stays on your network. No cloud dependency. No monthly subscriptions. Your data is yours. From face recognition doorbells to automated lighting scenes to security automations, OpenCode makes building these systems approachable for everyone.
đŸ“ē Watch the full video guide: IT HomeLab Online on YouTube

If you found this helpful, like and subscribe to IT HomeLab Online for more tutorials.

â˜•ī¸ Support the channel: Buy Me a Coffee

Enjoyed this guide?

Subscribe to the channel for more homelab builds, Raspberry Pi projects, and AI automation tutorials. â–ļ Watch on YouTube

Enjoyed this guide?

Subscribe to the channel for more homelab builds, Raspberry Pi projects, and AI automation tutorials.

▶ Watch on YouTube