call_service
Control Home Assistant smart home devices by calling services to turn on lights, adjust climate settings, or operate switches with specific parameters.
Instructions
Call a Home Assistant service (e.g., turn on a light, set climate)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| domain | Yes | Service domain (e.g., 'light', 'switch', 'climate') | |
| service | Yes | Service name (e.g., 'turn_on', 'turn_off', 'set_temperature') | |
| entity_id | No | Target entity ID | |
| data | No | Additional service data (e.g., brightness, temperature) |
Implementation Reference
- src/index.ts:207-229 (handler)Switch case handler for 'call_service' tool that prepares service data and calls haClient.callServicecase "call_service": { const serviceData: any = {}; if (args?.entity_id) { serviceData.entity_id = args.entity_id; } if (args?.data) { Object.assign(serviceData, args.data); } const result = await haClient.callService( args?.domain as string, args?.service as string, serviceData ); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; }
- src/index.ts:127-152 (registration)Tool registration for 'call_service' including name, description, and input schema{ name: "call_service", description: "Call a Home Assistant service (e.g., turn on a light, set climate)", inputSchema: { type: "object", properties: { domain: { type: "string", description: "Service domain (e.g., 'light', 'switch', 'climate')", }, service: { type: "string", description: "Service name (e.g., 'turn_on', 'turn_off', 'set_temperature')", }, entity_id: { type: "string", description: "Target entity ID", }, data: { type: "object", description: "Additional service data (e.g., brightness, temperature)", }, }, required: ["domain", "service"], }, },
- src/index.ts:58-62 (helper)HomeAssistantClient method that performs the actual service call via the HA APIasync callService(domain: string, service: string, data: any = {}) { return this.fetch(`services/${domain}/${service}`, { method: "POST", body: JSON.stringify(data), });