abearxiong d17efcc606 feat: integrate light control functionality with Home Assistant
- Added LightHA class to manage light services.
- Implemented searchLight method for device discovery.
- Created app.ts and index.ts for application setup and routing.
- Developed callText function to parse and execute light commands.
- Established routes for handling Home Assistant control commands.
- Configured Bun for building the application with TypeScript support.
2026-01-31 16:11:52 +08:00
2025-12-05 00:33:03 +08:00
2025-12-30 02:57:24 +08:00

灯光管理

该模块提供对Home Assistant中灯光设备的管理功能包括获取灯光列表、搜索特定灯光设备以及控制灯光的开关状态。

import { haLight }  from '@kevisual/ha-api';

const light = new haLight({
  host: 'http://your-home-assistant:8123',
  token: 'your-long-lived-access-token',
});
// 获取所有灯光设备
const lights = await light.getLights();
console.log(lights);

const searchResult = await light.searchLight('living room');
console.log(searchResult);

if(searchResult.hasMore) {
  console.log('多个灯光设备匹配该关键词,请进一步筛选。');
} else if(searchResult.id) {
  console.log(`唯一匹配的灯光设备ID为: ${searchResult.id}`);
  light.toggleLight({ entity_id: searchResult.id, service: 'turn_on' });
} else {
  console.log('没有找到匹配的灯光设备。');
}

音箱管理

该模块提供对Home Assistant中音箱设备的管理功能执行文本指令等。

import { TextHA }  from '@kevisual/ha-api';

const tts = new TextHA({
  host: 'http://your-home-assistant:8123',
  token: 'your-long-lived-access-token',
});
// 获取所有音箱设备
const entities = await text.getSpeakerEntities();
// 执行文本指令
const res2 = await text.executeTextDirective('text.xiaomi_lx06_9e08_execute_text_directive', '关闭阳台灯');
console.log(res2);
Description
homeassistant api 调用
Readme 100 KiB
Languages
TypeScript 100%