Function Structure
Every function consists of two parts:Specification (spec)
Thespec follows OpenAI’s function schema format:
- name: Function identifier (used by AI to call the function)
- description: Clear explanation of what the function does
- parameters: JSON schema defining expected parameters
Function Implementation
Thefunction section defines how to execute the function:
- type: Function type (see below)
- Additional configuration specific to the function type
Function Types
Native
Built-in functions provided by the component
Template
Return dynamic values using Jinja2 templates
Script
Execute sequences of Home Assistant services
REST
Fetch data from external REST APIs
Scrape
Extract data from web pages
Composite
Chain multiple function types together
SQLite
Query Home Assistant’s database
Bash
Execute shell commands with security controls
Read File
Read file contents safely with path restrictions
Write File
Write content to files safely with path restrictions
Edit File
Safely edit files with find-and-replace operations
Reserved Parameters
Delay Parameter
Add a delay to execute functions in the background after a specified time:Default Functions
Extended OpenAI Conversation includes this default function:execute_services
execute_services
Adding Custom Functions
Add functions through the Options configuration:Best Practices
Clear descriptions
Clear descriptions
Write detailed descriptions that explain exactly what the function does and when to use it. The AI relies on these descriptions to choose the right function.✅ Good: “Get the current weather and forecast for a specific location using the weather entity”❌ Bad: “Get weather”
Specific parameters
Specific parameters
Define all required parameters with clear descriptions and appropriate types.
Test thoroughly
Test thoroughly
Test each function with various inputs before deploying to production. Check edge cases and error handling.
Use appropriate types
Use appropriate types
Choose the simplest function type that meets your needs. Don’t use composite functions when a template would suffice.