skye-harris/hass_local_openai_llm
À propos
Home Assistant LLM integration for local OpenAI-compatible services (llamacpp, vllm, etc)
IA et apprentissage automatiqueProgression mesurée des étoiles
- in 24h
- +1
- in 7 days
- +4
- in 15 days
- +7
- in 1 month
- Historique en cours
Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.
README.md
OriginalLocal OpenAI LLM (Custom Integration for Home Assistant)
Allows use of generic OpenAI-compatible LLM services, such as (but not limited to):
- DeepSeek
- Google (Gemini)
- llama.cpp
- LM Studio
- LocalAI
- Ollama
- OpenLLM
- OpenRouter
- Requesty
- Scaleway
- UberLLM
- vLLM
This integration has been forked from Home Assistants OpenRouter integration, with the following changes:
- Added server URL to the initial server configuration
- Made the API Key optional during initial server configuration: can be left blank if your local server does not require one
- Uses streamed LLM responses
- Conversation Agents support TTS streaming
- Automatically strips
<think>tags from responses - Added support for image inputs for AI Task entities
- Added support for reconfiguring Conversation Agents
- Added option to trim conversation history to help stay within your context window
- Added temperature control (conversation agent + ai task)
- Added option to strip emojis from responses
- Added support for parallel tool calling
- Added experimental Retrieval Augmented Generation capability
- Added chat template arguments support
- Added image generation support for AI Task entities
- Added tools support for Generate Data actions for AI Task entities
- Added decision model support for AI Task evaluate actions
- Emits a
local_openai_llm_generation_completeevent for all LLM completion requests, with usage/timings data if available
Installation
Install via HACS (recommended)
Have HACS installed, this will allow you to update easily.
Adding Tools for Assist to HACS can be using this button:
[!NOTE] If the button above doesn't work, add
https://github.com/skye-harris/hass_local_openai_llmas a custom repository of type Integration in HACS.
- Click install on the
Local OpenAI LLMintegration. - Restart Home Assistant.
Manual Install
- Copy the
local_openaifolder from latest release to thecustom_componentsfolder in your config directory. - Restart the Home Assistant.
Integration Configuration
After installation, configure the integration through Home Assistant's UI:
- Go to
Settings→Devices & Services. - Click
Add Integration. - Search for
Local OpenAI LLM. - Follow the setup wizard to configure your desired services.
Configuration Notes
- The Server URL must be a fully qualified URL pointing to an OpenAI-compatible API.
- This typically ends with
/v1but may differ depending on your server configuration.
- This typically ends with
- A Server Type configuration can be set to expose some additional options for different inference servers and providers, where they have been implemented.
- Assist requires a fairly lengthy context for tooling and entity definitions.
- It is strongly recommended to use at least 10k context size and to limit history length and exposed entities to avoid context overflow issues.
- This is not configurable through OpenAI-compatible APIs, and needs to be configured with the inference server directly.
- Tool calling must be enabled in your inference engine, eg:
- Parallel tool calling requires support from both your model and inference server.
- In some cases, control of this is handled by the server directly, in which case toggling this will not have any result.
- Chat Template Arguments allow you to provide custom arguments to your model
- Arguments are supplied as key/value pairs and provided to the
chat_template_kwargsrequest parameter - Values support Jinja2 templates, in order to provide non-string and more complex data structures
- Arguments differ per model, and not all models make use of user-provided arguments
- See your models documentation for what arguments are available to be used
- Arguments are supplied as key/value pairs and provided to the
- Request Body Parameters allow you to provide additional top-level parameters to the chat completion request body
- Parameters are supplied as key/value pairs and merged into the request body
- Values support Jinja2 templates, in order to provide non-string and more complex data structures
- Internally managed parameters, and parameters with dedicated configuration options, cannot be configured here
- Provider support differs; see your provider and model documentation for available parameters
- AI Task entities can be configured for Text and/or Image generation capabilities
- This capability uses the Images API spec and requires support from your chosen image generation server
- Support has been developed and tested with StableDiffusion.cpp
- Always continue conversation — When a voice agent finishes speaking, passes the active voice turn back to the user in
order to naturally continue the conversation
- If the user speaks, the assistant continues the conversation naturally
- If the user stays silent, the assistant stops following up after a timeout
- If the user says a stop keyword (e.g. "STOP") while the agent is actively speaking, the follow-up is canceled immediately (default HomeAssistant behaviour)
- The agent is provided a
stop talkingtool to end the conversation via natural language request to the agent itself (while the assist satellite is listening, not speaking) - When disabled (default), only assistant responses ending in a question will pass the active voice turn back to the user
All Server Types
Custom HTTP Headers
Add custom HTTP headers as key-value pairs to all LLM API requests. Useful for passing custom metadata or provider-specific headers:
- Values support Jinja2 templates and have access to all default Home Assistant template variables and functions (e.g. entity
states). - The current Conversation ID is available in the
conversation_idvariable. - All header values are coerced to strings after rendering.
DeepSeek Cloud Configuration
Reasoning Effort
When the server type is set to DeepSeek Cloud, both conversation and AI task agents show a new DeepSeek Configuration section with a Reasoning Effort option. This controls the depth of reasoning when thinking is enabled.
- High (default) — standard reasoning effort.
- Max — maximum reasoning effort.
When enabled, thinking content returned by the model is also fed back into the conversation as reasoning content on supported Home Assistant versions (2026.4+).
Thinking Mode
Controls when reasoning is enabled. Leave the option unset to disable thinking.
- Always on — thinking remains enabled for every iteration.
- First loop iteration only — thinking is disabled on iterations after the first (e.g., during tool-call rounds).
llama.cpp Configuration
When the server type is set to llama.cpp, both conversation and AI task agents show a llama.cpp Configuration section with the following options.
Thinking Mode
Controls when reasoning is enabled. Leave the option unset to disable thinking.
- Always on — reasoning is enabled for every iteration of the agent loop.
- First loop iteration only — thinking is disabled on iterations after the first (e.g., during tool-call rounds).
Note: This option completely overrides any existing enable_thinking option in your Chat Template Arguments.
Include prior thinking
Controls whether thinking/reasoning content from prior conversation turns is sent back in new completion requests.
Some reasoning models require this enabled, and others require it disabled. Check the documentation for your model if unsure.
- Enabled (default) — prior-turn
thinking_contentis passed asreasoning_contentin the next request, allowing the model to see its own prior reasoning. - Disabled — prior thinking context is stripped before sending. Use for models that reject prior reasoning context (e.g., Gemma 4).
Slot ID
Pins requests to a specific llama.cpp server slot for prompt-cache reuse. Leave empty to allow any slot to be used.
Use loaded model
When enabled, the integration prioritizes using models already resident in memory to minimize latency.
It follows these rules:
- Primary: Uses the configured model if it is currently loaded.
- Fallback: If the configured model is not loaded, it selects the first loaded model that supports the required modality (e.g., image inputs). If no compatible loaded models exist, it defaults back to the configured model.
This is ideal for users with diverse model setups who want to route tasks to whatever is currently available in memory rather than waiting for a specific model to load.
Sampling Parameters
These options control how llama.cpp selects tokens during text generation.
Please refer to
the llama.cpp documentation
for further information and usage.
| Parameter | Description | Range |
|---|---|---|
| Top-P | Restricts sampling to the top-p probability mass of tokens. | 0–1 |
| Min-P | Minimum probability threshold for nucleus sampling, providing additional control when combined with top-p. | 0–1 |
| Top-K | Limits sampling to the k highest-probability tokens. | 1–1000 |
| Repeat Penalty | Penalizes repeat sequences of tokens. | -2–2 |
| Presence Penalty | Penalizes tokens already present in the context. | -2–2 |
Model naming
llama.cpp exposes the value supplied via its --alias flag on the model object. When an alias is set it is used as the
model's display name; otherwise the raw model id (typically the full model file path) is used, with the path and
.gguf
extension stripped for a cleaner name.
LocalAI Configuration
When the server type is set to LocalAI, Chat Template Arguments are sent via the OpenAI metadata request field
rather than a top-level chat_template_kwargs field, as this is where LocalAI reads chat template variables from.
Values are coerced to strings, per LocalAI's metadata convention.
See LocalAI model configuration.
vLLM Configuration
When the server type is set to vLLM, both conversation and AI task agents show a vLLM Configuration section with the following options.
Thinking token budget
Caps how many tokens the model may spend on reasoning, via the thinking_token_budget request parameter. Once the
budget is reached, vLLM forces the reasoning block to be closed and the model proceeds to its answer.
- Empty (default) — no budget is sent, and the server default applies.
- 0 — the reasoning block is closed immediately, so the model answers without thinking.
- Any higher value — limits reasoning to that number of tokens.
Thinking Mode
Controls when reasoning is enabled. Leave the option unset to disable thinking.
- Always on — reasoning is enabled for every iteration and the token budget (if set) applies to all iterations.
- First loop iteration only — thinking is disabled on iterations after the first (e.g., during tool-call rounds).
Requires a reasoning model and a vLLM version that supports the parameter. Refer to the vLLM reasoning outputs documentation for further information.
When the budget is reached the reasoning block is closed with the parser's end string, which can leave the model cut off mid-thought. A wrap-up message can be added there to transition into the answer more gracefully, though this is configured on the vLLM server rather than per request:
--reasoning-parser qwen3
--reasoning-config '{"reasoning_start_str": "<think>", "reasoning_end_str": "\n\nTime to wrap up my reasoning and answer.</think>"}'
Context Injection
This integration supports injecting dynamic content into the active Conversation Agent prompt when making a request. The injected content is rendered from a Jinja2 template and inserted before the current user message.
Configuration
Context injection template — A Jinja2 template that is rendered per-request. The default template provides the current date and time, but you can customize it to include any dynamic content.
Context injection role — Where to insert the rendered content:
System:
The content is inserted as an additional System message to the model, before the current user message.
As long as the model does not reject it, this is the recommended method to use. Not all model chat templates will render these out, but support is becoming more widespread.
Tool Result:
The content is inserted as a Tool Call Result message to the model, before the current user message.
Assistant:
The content is inserted as an additional Assistant message to the model, before the current user message.
In cases where the Tool Call Result role method does not work for a model, this is the next recommended to test with.
User:
The content is inserted as an additional User message to the model, before the current user message.
Recommended only where neither the System nor Assistant injection methods work for the model, but may not produce
desirable results. Some models have been known to repeat the date/time back to the user without request.
Disabled (no selection):
If your model simply refuses to work well with any method, simply remove the value from the configuration option to disable this again.
Available Template Variables
The template is rendered with access to the standard HomeAssistant template environment, with the following additional variables exposed:
device— TheDeviceEntryobject for the requesting device, orNonearea— TheAreaEntryobject for the device's area, orNonefloor— TheFloorEntryobject for the area's floor, orNone
Available attributes on objects:
- device:
id,name,model,manufacturer,sw_version,area_id,identifiers - area:
id,name,icon,floor_id,normalized_name - floor:
id,name,icon,level,normalized_name,floor_id
Decision Models
Home Assistant 2026.11 added the ai_task.evaluate action, which asks a decision model yes/no, choice and score
questions and returns probabilities rather than generated text. This integration supports decision models served
through the TypeSafe-compatible /v1/systemone API, such as
llama.cpp
and Ollama.
- Add one from your server's integration entry with Add decision model. This is available for the Generic and llama.cpp server types.
- Decision models get their own AI Task entity, separate from your data and image generation entities. Select it as
the default decision entity in the AI Task settings to use it without passing
entity_id. - On llama.cpp, the model list only shows models the server reports as native decision models. A chat model prompted to classify is not a decision model, and the server will reject it.
- Image attachments are supported when the model and server support image input. On llama.cpp this requires a multimodal projector to be loaded.
action: ai_task.evaluate
data:
task_name: Check delivery
state: "{{ states('sensor.last_delivery_message') }}"
questions:
delivered:
type: noul
instructions: Has the package been delivered?
location:
type: choice
instructions: Where was the package left?
criteria:
front_door: At the front door or on the porch
mailbox: Inside the mailbox
other: Somewhere else, or the message does not say
response_variable: delivery
Experimental: Retrieval Augmented Generation (RAG) with Weaviate
Retrieval Augmented Generation is used to pre-feed your LLM messages with related data to provide contextually relevant information to the model based on the user input message.
This integration supports connecting your Agent to a Weaviate vector database server. Once configured, user messages to the Agent will be queried against the Weaviate database first, and the result data pre-emptively injected into the current conversation as contextual data for the Agent to utilise in their response.
This is not a general-purpose "memory" for the Agent: content is only provided to the Agent if it matches on the current user input message to the model.
See the Weaviate documentation for further information on Weaviate.
Weaviate Configuration
- Install Weaviate locally
- A pre-made
docker-compose.ymlis provided in theweaviatedirectory of this repository.- Upgrading an existing install: Weaviate only supports upgrading one minor version at a time. If your data
was created with the previous
1.34.0image, step through the latest patch of each minor (1.35,1.36,1.37,1.38) before starting1.39.13. See the Weaviate migration guide.
- Upgrading an existing install: Weaviate only supports upgrading one minor version at a time. If your data
was created with the previous
- Weaviate Cloud is not supported: there is no free tier available and its cheapest pricing plan isn't attractive for personal/home use, and so I don't anticipate demand for this.
- A pre-made
- Reconfigure your LLM Server entity (not the Agent entity) in Home Assistant.
- Expand the
Weaviate configurationsection and fill in the details server address and API key (homeassistantif using the supplieddocker-compose.yml).
- Expand the
- Optional: Reconfigure your AI Agent entities in Home Assistant.
- This is only needed if you wish to change the default Weaviate values on a per-agent basis:
- Object class name: Defaults to
Homeassistant, can be changed if you want a different data store for the Agent. The integration will handle creating the required object class within Weaviate if it does not already exist. - Maximum number of results to use: Defaults to
2. - Result score threshold: Defaults to
0.9. - Hybrid search alpha: Defaults to
0.5. Balances the hybrid result scoring between 0 (fully text-matched) and 1 (fully vectorised) matching.
- Object class name: Defaults to
- This is only needed if you wish to change the default Weaviate values on a per-agent basis:
Managing Data
Self-hosted Weaviate does not come with a front-end to manage data at all at this current point in time.
I have included a simple NodeJS-based WebApp server within the /weaviate directory of this repository, that can be
used to connect to your local Weaviate instance and view, query, and manage the data in your object class. This is also
setup into the supplied docker-compose.yml and exposed on port 9090 by default.
This tool supports the following basic functionality:
- Connect to your server and list the available object classes.
- View the available entry data in each class.
- Add new entry data to a class.
- Perform vector and hybrid searches against an object class.
This is not a general-purpose Weaviate management tool, rather it is purpose-built specifically for use with this integration and the object classes that it creates.
Notes
- Only the current generations user message is queried in the database, no prior user messages are included.
- Search results are used for the current user/assistant turns only (including multiturn tool usages), and do not carry forward to subsequent user/assistant turns.
- Objects are stored as 2 pieces of data: the
query, and thecontent:- The
queryis what is vectorised and the user inputs searched against. - The
contentis the main content to be provided to be fed to the LLM, along with itsquerytext for context.
- The
- Useful for providing contextual information to the LLM for different types of requests, without having all of it in your prompt at all times.
- I have performed basic testing of this with a variety of models across a few inference providers:
- Qwen 3-VL 8B locally on llama.cpp.
- Minimax m2.1 on OpenRouter.
- Ministral 8B 2512 on OpenRouter.
- GPT-5 on OpenRouter.
- Gemma 3 27B on Scaleway.
- Llama 3.1 8B on Scaleway.
- GPT-OSS-120B on Scaleway.
- A service action,
local_openai.add_to_weaviate, can be used from within Home Assistant to add content to the database.
Web Search & Additional Tools
Looking to add some more functionality to your Home Assistant conversation agent, such as web and localised business/location search? Check out my Tools for Assist integration here!
These tools exist as a separate integration for compatibility across the wider Home Assistant Conversation ecosystem.
Not sure where to begin?
Check out this excellent guide from contributor @NickM-27 on the Home Assistant Community forum.
Acknowledgements
This integration was forked from the OpenRouter integration for Home Assistant by @joostlek.
Contributors
I would like to thank the following people for their contributions to this project:
NickM-27 |
JulienDeveaux |
VysseCodes |
PollyBot13 |
srwalter |
alexjurkiewicz |
ordex |
gtrev500 |
whinis |
Johnson145 |
ksmarty |
Mugga6315 |
Thibaultjaigu |
Thyraz |
jgancedo |
geryduyck |
dudanogueira |
TomGrozev |
Support Development
If you find this integration useful and would like to support development, please consider buying me a coffee.
Explorer des projets similaires
Chargement…
