|
| 1 | +--- |
| 2 | +title: Smart Home Assistant |
| 3 | +weight: 5 |
| 4 | + |
| 5 | +### FIXED, DO NOT MODIFY |
| 6 | +layout: learningpathall |
| 7 | +--- |
| 8 | +## About the assistant |
| 9 | + |
| 10 | +In this section, you will run the assistant through the `smart_home_assistant.py` script. It initializes all configured smart devices on specific GPIO pins and starts a local web server for interacting with the assistant. The script processes user commands using a local language model (via Ollama), parses the model’s JSON output, and executes actions such as toggling lights or locking doors. It supports both terminal and web-based control. |
| 11 | + |
| 12 | +The assistant is available on GitHub. Clone the code and navigate to the project directory: |
| 13 | + |
| 14 | +```bash |
| 15 | +git clone https://github.com/fidel-makatia/EdgeAI_Raspi5.git |
| 16 | +cd EdgeAI_Raspi5 |
| 17 | +``` |
| 18 | + |
| 19 | +## Connect further hardware |
| 20 | + |
| 21 | +In the previous section, you configured a LED on GPIO pin 17. The smart home assistant is by default associating this with a `living_room_light` device. The single LED setup is enough to run through this Learning Path. If you'd like to connect actual devices, or play with more mock sensors, the default configuration looks like the table below. You can repeat the steps on the previous page to verify the hardware setup on the different GPIO pins. See the image below for an example. |
| 22 | + |
| 23 | +| Device Name | GPIO Pin | Type | Room | |
| 24 | +| ----------------- | -------- | --------- | ----------- | |
| 25 | +| living_room_light | 17 | LIGHT | living_room | |
| 26 | +| living_room_fan | 27 | FAN | living_room | |
| 27 | +| smart_tv | 22 | SMART_TV | living_room | |
| 28 | +| bedroom_light | 23 | LIGHT | bedroom | |
| 29 | +| bedroom_ac | 24 | AC | bedroom | |
| 30 | +| kitchen_light | 5 | LIGHT | kitchen | |
| 31 | +| front_door_lock | 26 | DOOR_LOCK | entrance | |
| 32 | +| garden_light | 16 | LIGHT | outdoor | |
| 33 | + |
| 34 | +{{% notice Note %}} |
| 35 | +The code uses gpiozero with lgpio backend for Raspberry Pi 5 compatibility. You can use compatible output devices such as LEDs, relays, or small loads connected to these GPIO pins to represent actual smart home devices. All pin assignments are optimized for the Raspberry Pi 5's GPIO layout. |
| 36 | +{{% /notice %}} |
| 37 | + |
| 38 | +, a red LED, push button, and a sensor module. This setup illustrates a simulated smart home with controllable devices.") |
| 39 | + |
| 40 | + |
| 41 | +## Run the Smart Home Assistant |
| 42 | + |
| 43 | +Run the assistant in different modes depending on your use case. The default model is `deepseek-coder:1.3b`: |
| 44 | + |
| 45 | +{{< tabpane code=true >}} |
| 46 | +{{< tab header="Default (Web API + CLI)" language="bash">}} |
| 47 | +python3 smart_home_assistant.py |
| 48 | +{{< /tab >}} |
| 49 | +{{< tab header="Specify model" language="bash">}} |
| 50 | +python3 smart_home_assistant.py --model qwen:0.5b |
| 51 | +{{< /tab >}} |
| 52 | +{{< tab header="Custom web port" language="bash">}} |
| 53 | +python3 smart_home_assistant.py --port 8080 |
| 54 | +{{< /tab >}} |
| 55 | +{{< tab header="CLI only" language="bash">}} |
| 56 | +python3 smart_home_assistant.py --no-api |
| 57 | +{{< /tab >}} |
| 58 | +{{< /tabpane >}} |
| 59 | + |
| 60 | +### Command Options |
| 61 | + |
| 62 | +| Option | Description | Example | |
| 63 | +|------------------|---------------------------------------------------------------------------------------------------|--------------------------------------------| |
| 64 | +| `--model` | Specify the model to use with Ollama | `--model tinyllama:1.1b` | |
| 65 | +| `--port` | Run the web server on a custom port (default: `8000`) | `--port 8080` | |
| 66 | +| `--no-api` | Disable the web API and run in CLI-only mode |
| 67 | + |
| 68 | +If everything is set up correctly, you should see the following output on running the default command: |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +## Interact With Your Assistant |
| 73 | + |
| 74 | +Try asking the assistant to `turn on living room light`. If you've connected additional devices, come up with prompts to test the setup. |
| 75 | + |
| 76 | +### Web interface |
| 77 | + |
| 78 | + Open your browser and navigate to `http://0.0.0.0:8000`, or as printed in the terminal output. |
| 79 | + |
| 80 | +  |
| 81 | + |
| 82 | + |
| 83 | +### Command line interface |
| 84 | + |
| 85 | +Type commands directly in the terminal. |
| 86 | + |
| 87 | +Sample commands: |
| 88 | + |
| 89 | +```bash |
| 90 | +turn on living room light |
| 91 | +I want to watch my favorite show |
| 92 | +its getting late, secure the house |
| 93 | +``` |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | +{{% notice Troubleshooting %}} |
| 98 | +If you're running into issues with the assistant, here are some things to check: |
| 99 | +- Make sure your virtual environment is activated and that you installed all the packages from previous sections |
| 100 | +- For model loading problems, check if Ollama is running and list available models: |
| 101 | + ```bash |
| 102 | + ollama list |
| 103 | + ollama serve |
| 104 | + ``` |
| 105 | +- If port 8000 is unavailable, run the assistant with a different port using the `--port` flag. |
| 106 | +{{% /notice %}} |
| 107 | + |
| 108 | +## Wrapping up |
| 109 | + |
| 110 | +From here, you can modify the `smart_home_assistant.py` and extend the system by adding more devices, experimenting with conversational commands, or integrating sensors and automation logic into your smart home setup. |
| 111 | + |
| 112 | +You should now know more about setting up a Raspberry Pi 5 to control real-world devices using GPIO pins, and running a smart home assistant powered by local language models through Ollama. You’ve learned how to wire basic circuits with LEDs and resistors to simulate smart devices, and how to launch and interact with the assistant through both the command-line interface and a web dashboard. Along the way, you also explored common troubleshooting steps for GPIO access, missing dependencies, and model loading issues. |
| 113 | + |
0 commit comments