الأكاديمية ← قنوات المراسلةتوثيق رسمي · إرشاد عربي

الربط مع Home Assistant

Home Assistant

متوسط6 دقائق قراءةالدرس 54 أسئلة✓ 2026-08-18
قبل أن تقرأ

ما هذه الصفحة، وماذا تحتوي.

بوابة المراسلة: الوصلة التي تجعلك تكلّم Hermes من تطبيق تستعمله أصلًا، مثل Telegram أو WhatsApp، بدل الطرفية. الوكيل الذي تصله من هاتفك تستعمله فعلًا. الذي يحتاج فتح الحاسوب تنساه بعد أسبوع. الصفحة فيها تحذير من المصدر، و6 دقائق قراءة. انتبه: افتح القناة لنفسك فقط في البداية عبر قائمة سماح. القناة المفتوحة تعني أن أي شخص يراسل وكيلك.

6أقسام
12أمثلة برمجية
2جداول
1أوامر
1,043كلمة من المصدر
الوصف الرسمي في سطر

Control your smart home with Hermes Agent via Home Assistant integration.

ماذا ستستطيع بعدها

نتائج مأخوذة من هذه الصفحة، لا من قالب.

  • تعرف ما بوابة المراسلة ولماذا قد تحتاجه.
  • تنفّذ hermes gateway وتفهم ما يحدث بعدها.
  • تقرأ الجدول وتأخذ منه السطر الذي يخصّك فقط.
  • تضبط HASS_TOKEN في المكان الصحيح.
ما ستقابله من أسماء

كما تظهر تمامًا داخل Hermes.

الأوامر
  • hermes gateway
متغيرات البيئة
  • HASS_TOKEN
  • HASS_URL
خريطة الصفحة

انتقل مباشرة إلى ما تحتاجه.

  1. 01Setup
  2. 02Available Tools
  3. 03Gateway Platform: Real-Time Events
  4. 04Security
  5. 05Example Automations
  6. 06Troubleshooting
الصفحة الرسمية كاملة

بلا اختصار أو حذف.

النص أدناه منقول من المصدر الرسمي بالإنجليزية حتى تبقى الأوامر والأسماء دقيقة كما هي. قبل كل قسم شرح عربي يوضّح ما بداخله.

Hermes Agent integrates with Home Assistant ↗ in two ways:

  1. Gateway platform — subscribes to real-time state changes via WebSocket and responds to events
  2. Smart home tools — four LLM-callable tools for querying and controlling devices via the REST API

Setup

خطوات عملية بالترتيب. نفّذ خطوة وتأكد أنها نجحت قبل الانتقال للتالية. الأوامر هنا: hermes gateway.

1. Create a Long-Lived Access Token

  1. Open your Home Assistant instance
  2. Go to your Profile (click your name in the sidebar)
  3. Scroll to Long-Lived Access Tokens
  4. Click Create Token, give it a name like "Hermes Agent"
  5. Copy the token

2. Configure Environment Variables

Shell7 أسطر
# Add to ~/.hermes/.env

# Required: your Long-Lived Access Token
HASS_TOKEN=your-long-lived-access-token

# Optional: HA URL (default: http://homeassistant.local:8123)
HASS_URL=http://192.168.1.100:8123

3. Start the Gateway

Shellسطر واحد
hermes gateway

Home Assistant will appear as a connected platform alongside any other messaging platforms (Telegram, Discord, etc.).

Available Tools

شرح للفكرة نفسها. اقرأه ببطء، فبقية الأقسام تبني عليه. تذكير: الوصلة التي تجعلك تكلّم Hermes من تطبيق تستعمله أصلًا، مثل Telegram أو WhatsApp، بدل الطرفية.

Hermes Agent registers four tools for smart home control:

halistentities

List Home Assistant entities, optionally filtered by domain or area.

Parameters:

  • domain (optional) — Filter by entity domain: light, switch, climate, sensor, binary_sensor, cover, fan, media_player, etc.
  • area (optional) — Filter by area/room name (matches against friendly names): living room, kitchen, bedroom, etc.

Example:

Textسطر واحد
List all lights in the living room

Returns entity IDs, states, and friendly names.

hagetstate

Get detailed state of a single entity, including all attributes (brightness, color, temperature setpoint, sensor readings, etc.).

Parameters:

  • entity_id (required) — The entity to query, e.g., light.living_room, climate.thermostat, sensor.temperature

Example:

Textسطر واحد
What's the current state of climate.thermostat?

Returns: state, all attributes, last changed/updated timestamps.

halistservices

List available services (actions) for device control. Shows what actions can be performed on each device type and what parameters they accept.

Parameters:

  • domain (optional) — Filter by domain, e.g., light, climate, switch

Example:

Textسطر واحد
What services are available for climate devices?

hacallservice

Call a Home Assistant service to control a device.

Parameters:

  • domain (required) — Service domain: light, switch, climate, cover, media_player, fan, scene, script
  • service (required) — Service name: turn_on, turn_off, toggle, set_temperature, set_hvac_mode, open_cover, close_cover, set_volume_level
  • entity_id (optional) — Target entity, e.g., light.living_room
  • data (optional) — Additional parameters as a JSON object

Examples:

Textسطران
Turn on the living room lights
→ ha_call_service(domain="light", service="turn_on", entity_id="light.living_room")
Text3 أسطر
Set the thermostat to 22 degrees in heat mode
→ ha_call_service(domain="climate", service="set_temperature",
    entity_id="climate.thermostat", data={"temperature": 22, "hvac_mode": "heat"})
Text3 أسطر
Set living room lights to blue at 50% brightness
→ ha_call_service(domain="light", service="turn_on",
    entity_id="light.living_room", data={"brightness": 128, "color_name": "blue"})

Gateway Platform: Real-Time Events

فيه تحذير مهم. اقرأه قبل أن تنفّذ أي شيء من هذا القسم. نصّ التحذير من المصدر مذكور أسفل هذا الشرح.

The Home Assistant gateway adapter connects via WebSocket and subscribes to state_changed events. When a device state changes and matches your filters, it's forwarded to the agent as a message.

Event Filtering

Configure which events the agent sees in ~/.hermes/config.yaml under the Home Assistant platform's extra section:

YAML16 سطرًا
platforms:
  homeassistant:
    enabled: true
    extra:
      watch_domains:
        - climate
        - binary_sensor
        - alarm_control_panel
        - light
      watch_entities:
        - sensor.front_door_battery
      ignore_entities:
        - sensor.uptime
        - sensor.cpu_usage
        - sensor.memory_usage
      cooldown_seconds: 30
SettingDefaultDescription
watch_domains(none)Only watch these entity domains (e.g., climate, light, binary_sensor)
watch_entities(none)Only watch these specific entity IDs
watch_allfalseSet to true to receive all state changes (not recommended for most setups)
ignore_entities(none)Always ignore these entities (applied before domain/entity filters)
cooldown_seconds30Minimum seconds between events for the same entity

Event Formatting

State changes are formatted as human-readable messages based on domain:

DomainFormat
climate"HVAC mode changed from 'off' to 'heat' (current: 21, target: 23)"
sensor"changed from 21°C to 22°C"
binary_sensor"triggered" / "cleared"
light, switch, fan"turned on" / "turned off"
alarm_control_panel"alarm state changed from 'armed_away' to 'triggered'"
(other)"changed from 'old' to 'new'"

Agent Responses

Outbound messages from the agent are delivered as Home Assistant persistent notifications (via persistent_notification.create). These appear in the HA notification panel with the title "Hermes Agent".

Connection Management

  • WebSocket with 30-second heartbeat for real-time events
  • Automatic reconnection with backoff: 5s → 10s → 30s → 60s
  • REST API for outbound notifications (separate session to avoid WebSocket conflicts)
  • Authorization — HA events are always authorized (no user allowlist needed, since the HASS_TOKEN authenticates the connection)

Security

فيه تحذير مهم. اقرأه قبل أن تنفّذ أي شيء من هذا القسم. نصّ التحذير من المصدر مذكور أسفل هذا الشرح.

The Home Assistant tools enforce security restrictions:

Entity IDs are validated against the pattern ^[a-z_][a-z0-9_]*\.[a-z0-9_]+$ to prevent injection attacks.

Example Automations

شرح للفكرة نفسها. اقرأه ببطء، فبقية الأقسام تبني عليه.

Morning Routine

Text9 أسطر
User: Start my morning routine

Agent:
1. ha_call_service(domain="light", service="turn_on",
     entity_id="light.bedroom", data={"brightness": 128})
2. ha_call_service(domain="climate", service="set_temperature",
     entity_id="climate.thermostat", data={"temperature": 22})
3. ha_call_service(domain="media_player", service="turn_on",
     entity_id="media_player.kitchen_speaker")

Security Check

Text10 أسطر
User: Is the house secure?

Agent:
1. ha_list_entities(domain="binary_sensor")
     → checks door/window sensors
2. ha_get_state(entity_id="alarm_control_panel.home")
     → checks alarm status
3. ha_list_entities(domain="lock")
     → checks lock states
4. Reports: "All doors closed, alarm is armed_away, all locks engaged."

Reactive Automation (via Gateway Events)

When connected as a gateway platform, the agent can react to events:

Text7 أسطر
[Home Assistant] Front Door: triggered (was cleared)

Agent automatically:
1. ha_get_state(entity_id="binary_sensor.front_door")
2. ha_call_service(domain="light", service="turn_on",
     entity_id="light.hallway")
3. Sends notification: "Front door opened. Hallway lights turned on."

Troubleshooting

قسم لحل المشكلات. ابحث فيه عن العطل الذي يشبه حالتك بدل قراءته كاملًا.

Environment variables not picked up. The adapter reads credentials from ~/.hermes/.env (auto-merged at startup) or from config.yaml. Double-check the file lives under the active Hermes profile home and that there's no stray quoting around the URL/token. Restart the gateway after editing — env changes are only applied on process start.

REST auth failing (401 Unauthorized). The token must be a Long-Lived Access Token created from your HA user profile page (Profile → Security → Long-lived access tokens). Short-lived UI session tokens won't work. Also verify the base URL includes the scheme and port (e.g. http://homeassistant.local:8123) and is reachable from the host running Hermes — curl -H "Authorization: Bearer <token>" <url>/api/ should return {"message": "API running."}.

اختبار الفهم

4 أسئلة إجاباتها كلها في هذه الصفحة.

كل خيار اسم حقيقي من توثيق Hermes. حتى الخيارات الخاطئة حقيقية، لكنها من صفحات أخرى.

1. أي متغير بيئة من التالي يظهر فعليًا في هذا الدرس؟
2. ما التحذير الذي يذكره المصدر في هذا الدرس؟
3. أي عنوان من التالي لا يظهر في هذا الدرس؟
4. أي مفتاح إعداد يظهر في أمثلة هذا الدرس؟