Introduction
Smart home systems like Home Assistant have revolutionized how we control lighting, climate, and security. Yet, even the most advanced automations (e.g., "turn on lights at sunset") are static — they can't adapt to your daily mood, unexpected weather, or complex routines. Enter ASI Biont, an AI agent that connects directly to your Home Assistant via execute_python (using the requests library to call Home Assistant's REST API). Instead of manually coding YAML automations, you simply chat with the AI: "If the outdoor temperature drops below 5°C and I'm home, turn on the heater and send me a notification." ASI Biont writes the integration script in seconds, runs it in a cloud sandbox, and executes it on schedule. This article shows you how to connect Home Assistant to ASI Biont, with real code examples, automation scenarios, and a comparison with traditional automation.
Why Connect Home Assistant to an AI Agent?
Home Assistant already supports hundreds of integrations, but creating complex conditional logic (e.g., "if CO2 > 1000 ppm AND no one is home, open windows for 10 minutes") requires YAML expertise and frequent tweaking. ASI Biont eliminates this bottleneck: you describe the desired behavior in natural language, and the AI generates the Python code that calls Home Assistant's REST API (http://homeassistant.local:8123/api/services/...). This means:
- No YAML writing — AI handles the API calls.
- Dynamic adaptation — AI can adjust thresholds based on weather forecasts or your calendar.
- Multi-device orchestration — combine lights, thermostat, and security cameras in one flow.
How ASI Biont Connects to Home Assistant
ASI Biont supports two primary methods to control Home Assistant:
-
HTTP API via execute_python (most common): The AI writes a Python script using the
requestslibrary to call Home Assistant's REST API (e.g.,POST /api/services/light/turn_on). The script runs in a cloud sandbox on ASI Biont's Railway server. You provide the Home Assistant URL and a long-lived access token (obtained from Home Assistant → Profile → Long-Lived Access Tokens). -
WebSocket (for real-time events): The AI can use the
websocketslibrary to subscribe to Home Assistant's WebSocket API (ws://homeassistant.local:8123/api/websocket) and receive state changes instantly.
Important: ASI Biont does NOT require additional hardware bridges for Home Assistant — just an internet connection and API access.
Step-by-Step Integration Example: Lighting + Climate + Security
Scenario
You want an automation that:
- Turns on the living room lights when motion is detected after sunset.
- Sets the thermostat to 22°C if indoor temperature drops below 18°C.
- Sends a Telegram alert if the front door is opened after 10 PM.
Step 1: Get Home Assistant API Token
- Open Home Assistant → your profile (bottom left) → Long-Lived Access Tokens.
- Create a token (e.g.,
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...).
Step 2: Define the Automation in Chat
In the ASI Biont chat, type:
"Connect to my Home Assistant at http://192.168.1.10:8123 with token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... Create an automation that: 1) When motion sensor 'binary_sensor.living_room_motion' changes to 'on' after sunset, turn on 'light.living_room_lights'. 2) If temperature sensor 'sensor.living_room_temp' < 18°C, set 'climate.thermostat' to 22°C. 3) If 'binary_sensor.front_door' is 'on' after 22:00, send a Telegram message with text 'Door opened at night!'."
Step 3: AI Generates the Code
ASI Biont writes a Python script (simplified):
import requests
import datetime
HOME_ASSISTANT_URL = "http://192.168.1.10:8123"
TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
HEADERS = {"Authorization": f"Bearer {TOKEN}", "Content-Type": "application/json"}
def call_service(domain, service, entity_id, data=None):
url = f"{HOME_ASSISTANT_URL}/api/services/{domain}/{service}"
payload = {"entity_id": entity_id}
if data:
payload.update(data)
response = requests.post(url, headers=HEADERS, json=payload)
return response.status_code == 200
def get_state(entity_id):
url = f"{HOME_ASSISTANT_URL}/api/states/{entity_id}"
response = requests.get(url, headers=HEADERS)
return response.json()["state"] if response.ok else None
# 1) Motion + sunset check
motion = get_state("binary_sensor.living_room_motion")
sunset = datetime.datetime.now().hour >= 18 # simplified
if motion == "on" and sunset:
call_service("light", "turn_on", "light.living_room_lights")
# 2) Temperature check
temp = float(get_state("sensor.living_room_temp"))
if temp < 18:
call_service("climate", "set_temperature", "climate.thermostat", {"temperature": 22})
# 3) Door + time check
door = get_state("binary_sensor.front_door")
if door == "on" and datetime.datetime.now().hour >= 22:
# Send Telegram (requires Telegram bot token)
telegram_token = "YOUR_TELEGRAM_BOT_TOKEN"
chat_id = "YOUR_CHAT_ID"
msg = "Door opened at night!"
requests.post(f"https://api.telegram.org/bot{telegram_token}/sendMessage",
json={"chat_id": chat_id, "text": msg})
The AI can run this script on a schedule (e.g., every 5 minutes) or trigger it via a webhook from Home Assistant.
Step 4: Run and Refine
The script runs in the sandbox, and ASI Biont reports any errors (e.g., wrong entity ID). You can ask the AI to add more conditions — like ignoring motion if you're on vacation — and the AI updates the code instantly.
Comparison: Traditional Home Assistant Automation vs. ASI Biont
| Feature | Traditional Home Assistant YAML | ASI Biont AI Agent |
|---|---|---|
| Setup time | 15–30 minutes of YAML editing | 2 minutes in chat |
| Complexity | Requires understanding of triggers, conditions, actions | Natural language description |
| Adaptability | Must manually edit YAML for changes | AI rewrites script on request |
| Multi-device logic | Possible but tedious | AI handles cross-device logic seamlessly |
| External data | Limited to built-in integrations | AI can fetch weather, calendar, or stock data via API |
| Error handling | Must debug YAML syntax | AI reads error logs and fixes code |
Real-World Use Cases
- Climate optimization: AI reads outdoor weather (via OpenWeatherMap API) and indoor temperature, then adjusts thermostat and blinds to save energy.
- Security with AI vision: When a camera detects a person (via Home Assistant image processing), AI sends a snapshot to your phone and asks if you want to trigger the alarm.
- Energy management: AI monitors power consumption from smart plugs (via Home Assistant) and automatically turns off non-essential devices when rates are high.
Pitfalls to Avoid
- Token security: Never share your Home Assistant token publicly. Store it in ASI Biont's secure variables (if available) or use environment variables.
- Sandbox timeout: ASI Biont's
execute_pythonhas a 30-second timeout. For long-running automations, use webhooks or schedule shorter scripts. - Entity IDs: Ensure you use the exact entity ID from Home Assistant (case-sensitive). The AI can list them via
GET /api/states.
Conclusion
Integrating Home Assistant with ASI Biont transforms your smart home from a static rule-based system into an adaptive, intelligent environment. You no longer need to write YAML or debug automations — just describe what you want in plain English, and the AI agent handles the rest. Whether it's lighting, climate, or security, ASI Biont connects to your Home Assistant in minutes via its REST API.
Ready to supercharge your smart home? Visit asibiont.com, create an account, and start chatting with your AI agent today. No coding required — just tell it what you want your home to do.
Comments