A next-generation smart home assistant optimized for Raspberry Pi 5, leveraging local language models via Ollama for robust natural language understanding and device control. Designed for low latency and high throughput.
- LLM-First Architecture: All commands are processed by a local language model, enabling flexible and conversational interactions beyond traditional rule-based systems.
- High Performance: Engineered for Raspberry Pi 5 with memory-mapped caching and multi-threading, delivering 30+ tokens/second. Lightweight and responsive, even on resource-constrained hardware.
- Model Flexibility: Supports multiple optimized models, including
tinyllama:1.1b,qwen:0.5b, anddeepseek-coder:1.3b. Includes a benchmarking tool to compare model performance. - Real-Time Control: Direct GPIO management for smart devices using
gpiozeroand the modernlgpiopin factory, ensuring low-latency hardware communication. - Web Dashboard: Responsive web interface
- System Optimizations: Options to apply system-level enhancements for Raspberry Pi, such as setting the CPU governor to "performance" and increasing process priority.
This assistant uses a modular, LLM-first architecture for maximum performance and flexibility.
- Input Handling: Accepts user commands via interactive terminal or FastAPI web interface.
- Command Understanding:
- NEON Path (Fast Path): Simple commands (e.g., "turn on the living room light") are processed using a NEON-optimized, hardware-accelerated string matcher for instant recognition and execution.
- LLM Path (Flexible Path): Complex or conversational commands are sent to a local Ollama instance. The language model interprets intent and returns a standardized JSON object for action.
- Action Execution: Parses JSON output to determine and execute device actions or scene activations.
- Device Control: Interfaces directly with Raspberry Pi GPIO pins via
gpiozerofor smart device management. - State Management: Tracks device and sensor states in real time for an accurate smart home overview.
- Web Dashboard: FastAPI server provides a real-time dashboard accessible from any device on your network.
Install the following Python libraries:
ollama
numpy
httpx
orjson
gpiozero
fastapi
uvicorn
psutil
uvloop
A running Ollama instance with your chosen models is required.
Clone the repository:
git clone https://github.com/fidel-makatia/EdgeAI_Raspi5.git
cd EdgeAI_Raspi5Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activateInstall dependencies:
pip install -r requirements.txtInstall Ollama:
Follow the official instructions for Raspberry Pi: Ollama Installation Guide
Download a language model (example):
ollama pull tinyllamaRun the main script:
python3 smart_home_assistant.py --model [MODEL_NAME]Command-Line Arguments:
--model(Required): Name of the Ollama model (e.g.,tinyllama,qwen:0.5b)--port: Web server port (default: 8000)--no-web: Disable web interface (terminal-only mode)--optimize: Apply system-level optimizations (requires sudo)
Example:
python3 smart_home_assistant.py --model tinyllama --optimizeAccess the web dashboard at:
http://<your-pi-ip>:8000
Here are some example commands you can use with the assistant:
turn on living room lightI want to watch my favorite showits getting late, secure the house
| Model | Tokens/Sec | Avg Latency | Time/Cmd |
|---|---|---|---|
| qwen:0.5b | 17.0 | 8217 | 8217 |
| tinyllama:1.1b | 12.3 | 9429 | 9429 |
| deepseek-coder:1.3b | 7.3 | 22503 | 22503 |
| gemma2:2b | 4.1 | 23758 | 23758 |
| deepseek-r1:7b | 1.6 | 64797 | 64797 |
Looking through the code, I can extract the GPIO pin assignments from the _init_devices() method. Here are the Raspberry Pi pins used:
| Device | GPIO Pin | Type | Room | Dimmable |
|---|---|---|---|---|
| Living Room Light | GPIO 17 | Light | Living Room | ✅ Yes |
| Living Room Fan | GPIO 27 | Fan | Living Room | ❌ No |
| Smart TV | GPIO 22 | Smart TV | Living Room | ❌ No |
| Bedroom Light | GPIO 23 | Light | Bedroom | ✅ Yes |
| Bedroom AC | GPIO 24 | AC | Bedroom | ❌ No |
| Kitchen Light | GPIO 5 | Light | Kitchen | ❌ No |
| Front Door Lock | GPIO 26 | Door Lock | Entrance | ❌ No |
| Garden Light | GPIO 16 | Light | Outdoor | ❌ No |
- Total Pins Used: 8
- Dimmable Devices: 2 (use PWMLED)
- Standard Devices: 6 (use LED)
- Raspberry Pi 5
- 8x Relay modules (or similar switching devices)
- 2x PWM-capable outputs for dimmable lights
- Proper power supplies for high-wattage devices (especially the 1200W AC unit)
- Use appropriate relays rated for the device power consumption
- Always use proper isolation between Raspberry Pi GPIO (3.3V) and mains voltage devices
- Consider using optocouplers for additional safety
Contributions are welcome! Please submit a pull request or open an issue for improvements or bug reports.
This project is licensed under the MIT License. See the LICENSE file for details.


