PHPackages                             indexzer0/ha-rest-api-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. indexzer0/ha-rest-api-client

ActiveLibrary[HTTP &amp; Networking](/categories/http)

indexzer0/ha-rest-api-client
============================

Simple client for accessing home assistant rest api and webhooks.

v2.0.0(2y ago)6466[1 issues](https://github.com/IndexZer0/ha-rest-api-client/issues)[3 PRs](https://github.com/IndexZer0/ha-rest-api-client/pulls)MITPHPPHP ^8.2

Since Feb 21Pushed 2y ago1 watchersCompare

[ Source](https://github.com/IndexZer0/ha-rest-api-client)[ Packagist](https://packagist.org/packages/indexzer0/ha-rest-api-client)[ Docs](https://github.com/indexzer0/ha-rest-api-client)[ GitHub Sponsors](https://github.com/IndexZer0)[ RSS](/packages/indexzer0-ha-rest-api-client/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (10)Versions (7)Used By (0)

ha-rest-api-client
==================

[](#ha-rest-api-client)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d2893afd1d1bd741280f3624251af011da4ff00346e25b56511c93a88dfbe9a3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e6465787a6572302f68612d726573742d6170692d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/indexzer0/ha-rest-api-client)[![Tests](https://camo.githubusercontent.com/e1161e3d9064c4429162144745805e564c99e8b5448ab15d21e80d52b7fdcece/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f696e6465787a6572302f68612d726573742d6170692d636c69656e742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/indexzer0/ha-rest-api-client/actions/workflows/run-tests.yml)[![codecov](https://camo.githubusercontent.com/7b1d0324d8a29048ded1d0b9dea920b26ce0b06034febd1d391bb4fd47e8660b/68747470733a2f2f636f6465636f762e696f2f67682f496e6465785a6572302f68612d726573742d6170692d636c69656e742f67726170682f62616467652e7376673f746f6b656e3d4a4d4638554738533459)](https://codecov.io/gh/IndexZer0/ha-rest-api-client)[![Total Downloads](https://camo.githubusercontent.com/1f06e917acc5ea2d8d17048f112cd29da79196de6832d11fab6d5a887c0537fe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696e6465787a6572302f68612d726573742d6170692d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/indexzer0/ha-rest-api-client)

Clients for accessing HomeAssistant Rest API &amp; Webhooks.

- [Requirements](#requirements)
- [Installation](#installation)
- [Prerequisites](#prerequisites)
- [Usage](#usage)
    - [Basic (Http Client Auto Discovery)](#basic-http-client-auto-discovery)
    - [Custom Http Client (optional)](#custom-http-client-optional)
    - [HaRestApiClient - Available Methods](#harestapiclient---available-methods)
    - [HaWebhookClient - Available Methods](#hawebhookclient---available-methods)
    - [Error Handling](#error-handling)
- [Changelog](#changelog)
- [Contributing](#contributing)

Requirements
------------

[](#requirements)

- PHP Version &gt;= 8.2
- A PSR-18 compatible http client.
- A PSR-17 compatible factory.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require indexzer0/ha-rest-api-client
```

This library does not have a dependency on Guzzle or any other library that sends HTTP requests. This packages uses the awesome HTTPlug to achieve the decoupling. We want you to choose what library to use for sending HTTP requests. Consult this list of packages that support [php-http/client-implementation](https://packagist.org/providers/php-http/client-implementation) to find clients to use. For more information about virtual packages please refer to [HTTPlug](https://docs.php-http.org/en/latest/httplug/users.html).

Install your choice of http client.

Example:

```
composer require guzzlehttp/guzzle
composer require guzzlehttp/psr7
```

Prerequisites
-------------

[](#prerequisites)

- Check out the [Home Assistant Rest Api docs](https://developers.home-assistant.io/docs/api/rest/).
    - Add the [API integration](https://www.home-assistant.io/integrations/api/) to your `configuration.yaml`.
    - Create a `Long-Lived Access Token` in your profile.

Usage
-----

[](#usage)

This package provides two clients. `HaRestApiClient` and `HaWebhookClient`.

### Basic (Http Client Auto Discovery)

[](#basic-http-client-auto-discovery)

```
/*
 * ---------------------------
 * HaRestApiClient
 * ---------------------------
 */
$restApiClient = new \IndexZer0\HaRestApiClient\HaRestApiClient(
    'token',
    'http://localhost:8123/api/'
);
$restApiClient->status(); // ['message' => 'API running.']

/*
 * ---------------------------
 * HaWebhookClient
 * ---------------------------
 */
$webhookClient = new \IndexZer0\HaRestApiClient\HaWebhookClient(
    'http://localhost:8123/api/'
);
$webhookClient->send('GET', 'webhook_id'); // ['response' => '']
```

### Custom Http Client (optional)

[](#custom-http-client-optional)

The client needs to know what library you are using to send HTTP messages. You could provide an instance of a PSR-18 compatible http client and PSR-17 compatible factory, or you could fallback on auto discovery (basic example above). Below is an example on where you provide a Guzzle7 instance.

```
/*
 * ---------------------------
 * HaRestApiClient
 * ---------------------------
 */
$restApiClient = new \IndexZer0\HaRestApiClient\HaRestApiClient(
    'token',
    'http://localhost:8123/api/',
    new \IndexZer0\HaRestApiClient\HttpClient\Builder(
        new \GuzzleHttp\Client(),
        new \GuzzleHttp\Psr7\HttpFactory(),
        new \GuzzleHttp\Psr7\HttpFactory(),
        new \GuzzleHttp\Psr7\HttpFactory(),
    )
);
$restApiClient->status(); // ['message' => 'API running.']

/*
 * ---------------------------
 * HaWebhookClient
 * ---------------------------
 */
$webhookClient = new \IndexZer0\HaRestApiClient\HaWebhookClient(
    'http://localhost:8123/api/',
    new \IndexZer0\HaRestApiClient\HttpClient\Builder(
        new \GuzzleHttp\Client(),
        new \GuzzleHttp\Psr7\HttpFactory(),
        new \GuzzleHttp\Psr7\HttpFactory(),
        new \GuzzleHttp\Psr7\HttpFactory(),
    )
);
$webhookClient->send('GET', 'webhook_id'); // ['response' => '']
```

### HaRestApiClient - Available Methods

[](#harestapiclient---available-methods)

```
$restApiClient = new \IndexZer0\HaRestApiClient\HaRestApiClient(
    'token',
    'http://localhost:8123/api/'
);
$restApiClient->status();
$restApiClient->config();
$restApiClient->events();
$restApiClient->services();
$restApiClient->history(['light.bedroom_ceiling']);
$restApiClient->logbook();
$restApiClient->states();
$restApiClient->state('light.bedroom_ceiling');
$restApiClient->errorLog();
$restApiClient->calendars();
$restApiClient->calendarEvents('calendar.birthdays');
$restApiClient->updateState('light.bedroom_ceiling', 'on');
$restApiClient->fireEvent('script_started', [
    'name'      => 'Turn All Lights Off',
    'entity_id' => 'script.turn_all_lights_off'
]);
$restApiClient->callService('light', 'turn_on', [
    'entity_id' => 'light.bedroom_ceiling'
]);
$restApiClient->renderTemplate("The bedroom ceiling light is {{ states('light.bedroom_ceiling') }}.");
$restApiClient->checkConfig();
$restApiClient->handleIntent([
    'name' => 'SetTimer',
    'data' => [
        'seconds' => '30',
    ]
]);
```

### HaWebhookClient - Available Methods

[](#hawebhookclient---available-methods)

```
$webhookClient = new \IndexZer0\HaRestApiClient\HaWebhookClient(
    'http://localhost:8123/api/'
);

/*
 * ---------------------------
 * GET request example
 * ---------------------------
 */
$webhookClient->send(
    method: 'GET',
    webhookId: 'webhook_id',
    queryParams: ['query' => 'param'],
);

/*
 * ---------------------------
 * POST request example - with json body
 * ---------------------------
 */
$webhookClient->send(
    method: 'POST',
    webhookId: 'webhook_id',
    payloadType: 'json',
    data: ['json' => 'data']
);

/*
 * ---------------------------
 * POST request example - with form params body
 * ---------------------------
 */
$webhookClient->send(
    method: 'POST',
    webhookId: 'webhook_id',
    payloadType: 'form_params',
    data: ['form' => 'param']
);
```

### Error Handling

[](#error-handling)

All exceptions thrown by the package implement `\IndexZer0\HaRestApiClient\Exception\HaExceptionInterface`.

How-ever it doesn't harm to also catch `\Throwable`.

```
try {
    $webhookClient = new \IndexZer0\HaRestApiClient\HaWebhookClient(
        'http://localhost:8123/api/'
    );
    $response = $webhookClient->send('GET', 'webhook_id');
} catch (\IndexZer0\HaRestApiClient\Exception\HaExceptionInterface $haException) {

} catch (\Throwable $t) {
    // Shouldn't happen - but failsafe.
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

- Currently accepting PR for`$client->camera();` as I don't have a camera entity to develop against.

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [IndexZer0](https://github.com/IndexZer0)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

3

Last Release

891d ago

Major Versions

v1.0.1 → v2.0.02024-02-28

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/24657691?v=4)[IndexZer0](/maintainers/IndexZer0)[@IndexZer0](https://github.com/IndexZer0)

---

Top Contributors

[![IndexZer0](https://avatars.githubusercontent.com/u/24657691?v=4)](https://github.com/IndexZer0 "IndexZer0 (115 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

psr-7phppsr-17psr-18httplugwebhookREST APIIndexZer0php-figHome Assistantha-rest-api-clientSmart TechPSR-7 HTTP message interfacesPSR-17 HTTP FactoriesPSR-18 HTTP Client

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/indexzer0-ha-rest-api-client/health.svg)

```
[![Health](https://phpackages.com/badges/indexzer0-ha-rest-api-client/health.svg)](https://phpackages.com/packages/indexzer0-ha-rest-api-client)
```

###  Alternatives

[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28153.9k](/packages/phpro-http-tools)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k6.0M766](/packages/sylius-sylius)[brd6/notion-sdk-php

Notion SDK for PHP

6124.4k](/packages/brd6-notion-sdk-php)[php-http/httplug-bundle

Symfony integration for HTTPlug

39022.0M62](/packages/php-http-httplug-bundle)[florianv/exchanger

PHP exchange rate provider layer for currency conversion: 30+ services, chain fallback, and caching.

1865.1M20](/packages/florianv-exchanger)[elastic/transport

HTTP transport PHP library for Elastic products

2025.4M10](/packages/elastic-transport)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
