- Curated guides under docs/; trim China-only integration docs and screenshots - Root and main README set aligned with westernized product positioning - LICENSE text update where applicable
10 KiB
Xiaozhi ESP32 Open Source Server and HomeAssistant Integration Guide
[TOC]
Introduction
This document will guide you on how to integrate ESP32 devices with HomeAssistant.
Prerequisites
- HomeAssistant is installed and configured
- The model I chose this time is: free OpenAI, which supports function call
Pre-start Operations (Required)
1. Get HA Network Address Information
Please visit your Home Assistant network address. For example, my HA address is 192.168.4.7, and the port is the default 8123, then open in the browser
http://192.168.4.7:8123
Manual method to query HA's IP address**(Only applicable when xiaozhi-esp32-server and HA are deployed on the same network device [e.g., same wifi])**:
Enter Home Assistant (frontend).
Click Settings in the bottom left corner → System → Network.
Scroll to the bottom
Home Assistant websitearea, inlocal network, click theeyebutton to see the currently used IP address (such as192.168.1.10) and network interface. Clickcopy linkto copy directly.
Alternatively, if you have set up a directly accessible Home Assistant OAuth address, you can also access it directly in the browser
http://homeassistant.local:8123
2. Login to Home Assistant to get development key
Login to HomeAssistant, click bottom left avatar -> Profile, switch to Security navigation bar, scroll to the bottom Long-lived access tokens to generate api_key, and copy and save it. All subsequent methods require this api key and it only appears once (tIP: you can save the generated QR code image, and scan the QR code later to extract the api key again).
Method 1: Xiaozhi Community-built HA Calling Function
Function DescrIPtion
-
If you need to add new devices later, this method requires manually restarting the
xiaozhi-esp32-server serviceto update device information**(Important**). -
You need to ensure that
Xiaomi Homehas been integrated in HomeAssistant and Mi Home devices have been imported intoHomeAssistant. -
You need to ensure that the
xiaozhi-esp32-server Smart Control Consolecan be used normally. -
My
xiaozhi-esp32-server Smart Control ConsoleandHomeAssistantare deployed on the same machine on another port, version is0.3.10http://192.168.4.7:8002
Configuration Steps
1. Login to HomeAssistant to organize the device list that needs to be controlled
Login to HomeAssistant, click Settings in the bottom left corner, then enter Devices & Services, and click Entities at the top.
Then search for the switches you want to control in entities. After the results appear, click on one of the results in the list, and a switch interface will appear.
In the switch interface, we try clicking the switch to see if it turns on/off with our clicks. If it can be operated, it means it's properly connected to the network.
Then find the settings button in the switch panel, click it, and you can view the Entity ID of this switch.
We open a notepad and organize a piece of data in this format:
Location + English comma + Device name + English comma + Entity ID + English semicolon
For example, I'm at the company, I have a toy light, its identifier is switch.cuco_cn_460494544_cp1_on_p_2_1, then write this piece of data:
Company,Toy Light,switch.cuco_cn_460494544_cp1_on_p_2_1;
Of course, in the end I might need to operate two lights, my final result is:
Company,Toy Light,switch.cuco_cn_460494544_cp1_on_p_2_1;
Company,Desk Lamp,switch.iot_cn_831898993_socn1_on_p_2_1;
This string, we call it "device list string" and need to save it well, it will be useful later.
2. Login to Smart Control Console
Use the administrator account to login to the Smart Control Console. In Agent Management, find your agent, then click Configure Role.
Set intent recognition to Function Call or LLM Intent Recognition. At this time you will see an Edit Functions button on the right. Click the Edit Functions button, and a Function Management dialog will pop up.
In the Function Management dialog, you need to check HomeAssistant Device Status Query and HomeAssistant Device Status Modification.
After checking, click HomeAssistant Device Status Query in Selected Functions, then configure your HomeAssistant address, key, and device list string in Parameter Configuration.
After editing, click Save Configuration, then the Function Management dialog will be hidden, then click save agent configuration.
After successful saving, you can wake up the device for operation.
3. Wake up device for control
Try saying to the esp32, "Turn on XXX light"
Method 2: Xiaozhi uses Home Assistant's voice assistant as LLM tool
Function DescrIPtion
- This method has a relatively serious disadvantage——This method cannot use the function_call plugin capabilities of the Xiaozhi open source ecosystem, because using Home Assistant as Xiaozhi's LLM tool will transfer the intent recognition capability to Home Assistant. However, this method can experience the native Home Assistant operation functions, and Xiaozhi's chat capability remains unchanged. If you are really concerned, you can use [Method 3](##Method 3: Using Home Assistant's MCP service (recommended)) which is also supported by Home Assistant, which can maximize the experience of Home Assistant's functions.
Configuration Steps:
1. Configure Home Assistant's large model voice assistant.
You need to configure Home Assistant's voice assistant or large model tool in advance.
2. Get Home Assistant's voice assistant Agent ID.
-
Enter the Home Assistant page. Click
Developer Toolson the left. -
In the opened
Developer Tools, click theActionstab (as shown in operation 1), in theActionsoption bar on the page, find or enterconversation.process (conversation-process)and selectConversation: Process(as shown in operation 2). -
Check the
Agentoption on the page, in the highlightedConversation Agent, select the voice assistant name you configured in step 1, as shown in the figure, I have configuredOpenAIand select it. -
After selection, click
Enter YAML modeat the bottom left of the form. -
Copy the agent-id value, for example, mine in the figure is
01JP2DYMBDF7F4ZA2DMCF2AGX2(for reference only). -
Switch to the
config.yamlfile of the Xiaozhi open source serverxiaozhi-esp32-server, in the LLM configuration, find Home Assistant, set your Home Assistant network address, Api key and the agent_id you just queried. -
Modify the
LLMof theselected_moduleattribute in theconfig.yamlfile toHomeAssistant, andIntenttonointent. -
Restart the Xiaozhi open source server
xiaozhi-esp32-serverto use it normally.
Method 3: Using Home Assistant's MCP service (recommended)
Function DescrIPtion
-
You need to integrate and install the HA integration in Home Assistant in advance——Model Context Protocol Server.
-
This method and Method 2 are both solutions provided by HA officially. Unlike Method 2, you can normally use the open source community-built plugins of the Xiaozhi open source server
xiaozhi-esp32-server, while allowing you to freely use any LLM large model that supports function_call functionality.
Configuration Steps
1. Install Home Assistant's MCP service integration.
Official integration website——Model Context Protocol Server..
Or follow the manual operations below.
Go to Home Assistant page Settings > Devices & Services.
In the bottom right corner, select the Add Integration button.
Select Model Context Protocol Server from the list.
Follow the on-screen instructions to complete the setup.
2. Configure Xiaozhi open source server MCP configuration information
Enter the data directory and find the .mcp_server_settings.json file.
If you don't have a .mcp_server_settings.json file in your data directory,
- Please copy the
mcp_server_settings.jsonfile from the root directory of thexiaozhi-serverfolder to thedatadirectory and rename it to.mcp_server_settings.json - Or download this file, download it to the
datadirectory and rename it to.mcp_server_settings.json
Modify this part of the content in "mcpServers":
"Home Assistant": {
"command": "mcp-proxy",
"args": [
"http://YOUR_HA_HOST/mcp_server/sse"
],
"env": {
"API_ACCESS_TOKEN": "YOUR_API_ACCESS_TOKEN"
}
},
Note:
- Replace configuration:
- Replace
YOUR_HA_HOSTinargswith your HA service address. If your service address already contains https/http (e.g.,http://192.168.1.101:8123), just fill in192.168.1.101:8123. - Replace
YOUR_API_ACCESS_TOKENinAPI_ACCESS_TOKENinenvwith the development key api key you obtained earlier.
- Replace
- If you add configuration and there are no new
mcpServersconfigurations after the"mcpServers"brackets, you need to remove the final comma,, otherwise parsing may fail.
Final effect reference (as follows):
"mcpServers": {
"Home Assistant": {
"command": "mcp-proxy",
"args": [
"http://192.168.1.101:8123/mcp_server/sse"
],
"env": {
"API_ACCESS_TOKEN": "abcd.efghi.jkl"
}
}
}
3. Configure Xiaozhi open source server system configuration
-
Select any LLM large model that supports function_call as Xiaozhi's LLM chat assistant (but don't select Home Assistant as LLM tool). The model I chose this time is: free OpenAI, which supports functioncall function calling, but sometimes the calls are not very stable. If you want to pursue stability, it is recommended to set LLM to: OpenAILLM, using the specific model_name: gpt-4o-mini.
-
Switch to the
config.yamlfile of the Xiaozhi open source serverxiaozhi-esp32-server, set your LLM large model configuration, and adjust theIntentof theselected_moduleconfiguration tofunction_call. -
Restart the Xiaozhi open source server
xiaozhi-esp32-serverto use it normally.