mapo-89/laravel-homeassistant-api
Composer 安装命令:
composer require mapo-89/laravel-homeassistant-api
包简介
Laravel package to interact with Home Assistant REST API.
README 文档
README
A simple Laravel integration for the Homeassistant API. This package provides a clean interface to interact with the API.
📖 This README is also available in 🇩🇪 German.
📦 Installation
Install the package via Composer:
composer require mapo-89/laravel-homeassistant-api
Add your API token to your .env file:
HA_URL=http://homeassistant.local:8123 HA_TOKEN=your_long_lived_token
⚡️ Dynamic configuration (URL & token at runtime)
In addition to static configuration via config/homeassistant.php, this package also supports dynamic configurations at runtime. This is useful, for example, if each user has their own Home Assistant token or if the instance URL is to be set dynamically.
Optionally, you can publish the config file:
php artisan vendor:publish --provider="Mapo89\LaravelHomeassistantApi\HomeassistantApiServiceProvider" --tag="config"
⚙️ Usage
📚 The complete API documentation can be found here: home-assistant.io
Initialization
use Mapo89\LaravelHomeassistantApi\Facades\HomeassistantApi; $homeassistantApi = HomeassistantApi::make(); //Alternative with dynamic configuration $config = [ 'url' => 'http://homeassistant.local:8123', 'token' => 'your_long_lived_token' ]; $homeassistantApi = HomeassistantApi::make($config);
🔄 System API
// Check if the API is working $homeassistantApi->system()->verify();
🔄 Config API
// Output current configuration $homeassistantApi->config()->get(); // Check current configuration $homeassistantApi->config()->check();
🔄 States API
$homeassistantApi->states()->all(); // adapt this to your use case
🧩 Template API
More information about templating
// renders a template $homeassistantApi->template()->render(<<<'TEMPLATE' Paulus is at {{ states('device_tracker.paulus') }}! TEMPLATE );
🔔 Events API
Interaction with the Home Assistant event system.
// Retrieve all available events $events = $homeassistantApi->events()->all(); // Trigger custom event $homeassistantApi->events()->fire('my_custom_event', [ 'source' => 'laravel', 'user_id' => 123, ]);
Supported endpoints
GET /api/eventsPOST /api/events/{event_type}
🕒 History API
Access historical state changes of entities.
// Grouped history by entity $history = $homeassistantApi->history()->get( start: now()->subHours(12), entityIds: ['light.kitchen', 'sensor.temperature'], significantOnly: true ); // Access per entity $history['light.kitchen']; // HistoryState[]
Flat output (ideal for charts & analytics)
$flat = $homeassistantApi->history()->flat( start: now()->subHours(6), entityIds: ['light.kitchen', 'sensor.temperature'], );
Supported endpoints
GET /api/history/periodPOST /api/history/period/{timestamp}
📒 Logbook API
Access the Home Assistant logbook – ideal for user activities, automations, and system events.
⚠️ The logbook API requires at least one
entityId.
$entries = $homeassistantApi->logbook()->get( start: now()->subHours(6), entityIds: ['light.kitchen'], end: now() );
Supported endpoint
GET /api/logbook
Query Builder API (States)
Home Assistant does not support server-side filtering of states. This package therefore provides a query builder-like API that can be used to filter states on the client side – inspired by Laravel Eloquent.
✨ Example
use Mapo89\LaravelHomeassistantApi\Facades\HomeassistantApi; $states = HomeassistantApi::make() ->states() ->whereDomain('light') ->whereState('on') ->get();
🧱 Available query methods
whereDomain(string $domain)
Filters by the domain of an entity (e.g., light, sensor, switch).
$lights = HomeassistantApi::make() ->states() ->whereDomain('light') ->get();
whereState(string $state)
Filters by the state of an entity (e.g., on, off, unavailable).
$active = HomeassistantApi::make() ->states() ->whereState('on') ->get();
whereEntityIds(array $entityIds)
Filters by a list of specific entity IDs.
$states = HomeassistantApi::make() ->states() ->whereEntityIds([ 'light.kitchen', 'sensor.temperature', ]) ->get();
whereAttribute(string $key, mixed $value)
Filters by attributes of an entity.
$lights = HomeassistantApi::make() ->states() ->whereDomain('light') ->whereAttribute('brightness', 255) ->get();
get()
Returns all filtered states as an array of State DTOs.
$states = HomeassistantApi::make() ->states()->get();
first()
Returns the first matching state or null.
$state = HomeassistantApi::make() ->states() ->whereEntityIds(['light.kitchen']) ->first();
Artisan Command
The following Artisan commands always use the static configuration from .env or config/homeassistant.php:
# List all states php artisan ha:call # Call a service (e.g., switch lights) (in implementation) php artisan ha:call light toggle --entity=light.livingroom
📒 Changelog
Please see CHANGELOG for recent changes.
🤝 Contributing
Contributions are welcome! Please see CONTRIBUTING for details.
🔐 Security
If you discover any security issues, please do not use the issue tracker. Instead, email us directly at info@postler.de.
👥 Credits
📄 License
The MIT License (MIT). Please see the License File for more information.
🛠️ Laravel Package Boilerplate
Generated using the Laravel Package Boilerplate.
mapo-89/laravel-homeassistant-api 适用场景与选型建议
mapo-89/laravel-homeassistant-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mapo-89/laravel-homeassistant-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mapo-89/laravel-homeassistant-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 28
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-06