PHPackages                             kan-agency/hive-php-api - 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. [API Development](/categories/api)
4. /
5. kan-agency/hive-php-api

ActiveLibrary[API Development](/categories/api)

kan-agency/hive-php-api
=======================

An unofficial package to support the Hive Home API

1.0.2(5y ago)339[3 issues](https://github.com/kan-agency/hive-php-api/issues)MITPHPPHP &gt;=7.0.0CI failing

Since Apr 16Pushed 5y ago2 watchersCompare

[ Source](https://github.com/kan-agency/hive-php-api)[ Packagist](https://packagist.org/packages/kan-agency/hive-php-api)[ RSS](/packages/kan-agency-hive-php-api/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (5)Versions (4)Used By (0)

Hive Home PHP API
-----------------

[](#hive-home-php-api)

An unofficial package to support the Hive Home API

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

[](#installation)

This package can be installed via [Composer](https://getcomposer.org):

```
$ composer require kan-agency/hive-php-api
```

It requires **PHP &gt;= 7.0.0**.

Simple Usage
------------

[](#simple-usage)

There's a helper class, named `Kan\Hive\Hive`, which should be instantiated with the same credentials used to login to . This can be done like the below:

```
use Kan\Hive\Hive;

$hive = new Hive(
  'name@email.com',
  'password'
);
```

Once that's complete, we need to create a reference to a device using it's ID (Note: You can locate the ID of devices by viewing the URL of the  after selecting the required device).

```
use Kan\Hive\Reference\Device;

$plug = Device::make('123456ab-7898-7654-c321-d234567e89f1');
```

The device we're using here is a Plug, so, the below code will work for the above `$plug` device:

```
use Kan\Hive\Device\Plug;

Plug::fromHive($hive, $plug)->off(); // Will switch the plug off.
Plug::fromHive($hive, $plug)->on();  // Will switch the plug on.
```

That's it, simple. For more advance useage, see the below section.

Advance Usage
-------------

[](#advance-usage)

We should still instantiate an instance of the helper class `Kan\Hive\Hive`, however, you can utilise a Service Provider to inject this as a dependency into a class. We won't go into depth on how to do that, so for this example, we'll use the same method as above:

```
use Kan\Hive\Hive;

$hive = new Hive(
  'name@email.com',
  'password'
);
```

We can now create a new class within our project, let's name it `Lamp` and ensure it extends the correct device class. For this example, that is `Kan\Hive\Device\Plug`, as we have a lamp plugged into a plug. We need to implement the method `getDevice()` to return an instance of the correct device using it's ID, as explained above:

```
