mirror of
https://github.com/smkrv/ha-text-ai.git
synced 2026-07-21 22:54:00 +08:00
d89914414901343735031446c9550077a62fa9c7
🤖 HA Text AI for Home Assistant
Transform your smart home experience with powerful AI assistance powered by OpenAI's GPT models
🌟 Features
- 🧠 Advanced AI Integration: Leverage OpenAI's powerful models (GPT-3.5, GPT-4) for smart home interactions
- 💬 Natural Language Control: Control your home and get information using everyday language
- 📝 Conversation Memory: Maintain context with conversation history tracking
- ⚡ Real-time Responses: Get quick, contextual responses to your queries
- 🎯 Customizable Behavior: Fine-tune AI responses with adjustable parameters
- 🔒 Secure Integration: Your API key and data are handled securely
- 🎨 Flexible Configuration: Easy setup with multiple configuration options
- 🔄 Automation Ready: Integrate AI responses into your automations
📋 Prerequisites
- Home Assistant installation (Core, OS, Container, or Supervised)
- OpenAI API key (Get one here)
- Python 3.9 or newer
⚡ Quick Start
Manual Installation
- Download the repository
- Copy
custom_components/ha_text_aito yourcustom_componentsdirectory - Restart Home Assistant
- Add configuration to
configuration.yaml:
ha_text_ai:
api_key: !secret openai_api_key
⚙️ Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
api_key |
string | Required | Your OpenAI API key |
model |
string | gpt-3.5-turbo |
AI model to use |
temperature |
float | 0.7 |
Response creativity (0-2) |
max_tokens |
integer | 1000 |
Maximum response length |
request_interval |
float | 1.0 |
Minimum seconds between requests |
api_endpoint |
string | OpenAI default | Custom API endpoint URL |
🛠️ Available Services
ask_question
Ask the AI assistant a question:
service: ha_text_ai.ask_question
data:
question: "What's the optimal temperature for sleeping?"
model: "gpt-4" # optional
temperature: 0.5 # optional
max_tokens: 500 # optional
set_system_prompt
Configure AI behavior:
service: ha_text_ai.set_system_prompt
data:
prompt: "You are a home automation expert focused on energy efficiency"
clear_history
Reset conversation history:
service: ha_text_ai.clear_history
get_history
Retrieve conversation history:
service: ha_text_ai.get_history
data:
limit: 5 # optional
🔧 Practical Examples
Smart Temperature Management
automation:
trigger:
platform: time_pattern
hours: "/1"
action:
service: ha_text_ai.ask_question
data:
question: >
Current temperature is {{ states('sensor.living_room_temperature') }}°C.
Should I adjust the thermostat for optimal comfort and energy savings?
Smart Lighting Assistant
automation:
trigger:
platform: state
entity_id: binary_sensor.living_room_motion
to: 'on'
condition:
condition: template
value_template: "{{ states('sensor.illuminance') | float < 10 }}"
action:
service: ha_text_ai.ask_question
data:
question: >
Motion detected in living room with low light levels.
What's the best lighting scene to set based on the time of day?
❗ Common Issues
API Rate Limits
- Increase
request_intervalif hitting rate limits - Consider upgrading your OpenAI plan
- Use caching for frequent queries
High Token Usage
- Reduce
max_tokensparameter - Clear conversation history regularly
- Use focused system prompts
Connection Issues
- Check internet connectivity
- Verify API key validity
- Ensure endpoint accessibility
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ for the Home Assistant Community
Languages
Python
100%