- Introduction
- Requirements
- How to install
- How does it work?
- Currently implemented method
- Example
- Available methods
- Testing the library
- Credits
It's a very simple PHP library to allows you to communicate with your Yeelight RGB lights.
This library is all based on the official documentation from Yeelight.
- PHP 7.4 or up (tested with PHP 8.0)
- PHP sockets extension
- PHP JSON extension
- Yeelight local network control enabled on your lights
- Require the library using Composer:
composer require sharkezz/yeephp
- Require the composer autoloader (if it is not done yet)
- Instantiate a new Yeelight object
- Use it!
Yeelight-PHP use PHP sockets to communicate with your lights, that make it fast and reliable!
It can as well be used in your 'from scratch' project or in the framework of your choice!
This list is temporary, expect more methods to come
- Set the color (RGB) of the light
- Set the light brightness
- Set the light name
- Set the light power (on of off)
- Get light infos (partially completed)
- Color Flow control
- Proper error handling
Imagine that the Yeelight has the IP 192.168.0.15 and is using the default port (55443), in order to change the light color, you can do this:
<?php
require_once './vendor/autoload.php';
use SharkEzz\Yeelight\YeePHP;
// Create a new instance of Yeelight-PHP
$yeelight = new YeePHP('192.168.0.15');
// Set the color of the light, notice that all the 'set' methods are fluent, it means that you can use them in chain !
$yeelight->setColor(0xFF0000)
->commit(); // The commit method has to be called at the end to send the commands to the light
<?php
require_once './vendor/autoload.php';
use SharkEzz\Yeelight\YeePHP;
$yeelight = new YeePHP('192.168.0.15');
$yeelight->setBrightness(50)
->commit();
<?php
require_once './vendor/autoload.php';
use SharkEzz\Yeelight\YeePHP;
$yeelight = new YeePHP('192.168.0.15');
$yeelight->setBrightness(50)
->setColor(0x00FF00)
->commit();
<?php
require_once './vendor/autoload.php';
use SharkEzz\Yeelight\YeePHP;
$yeelight = new YeePHP('192.168.0.15');
// Set the light off
$yeelight->setPower('off')->commit();
// Set the light on
$yeelight->setPower('on')->commit();
<?php
require_once './vendor/autoload.php';
use SharkEzz\Yeelight\YeePHP;
$yeelight = new YeePHP('192.168.0.15');
$yeelight->setName('YeelightLoremIpsum')->commit();
All Yeelight RGB lights can be accessed by default on the port 55443, if your light doesn't use this port, no problems!
You can set your light port in the constructor like this:
<?php
require_once './vendor/autoload.php';
use SharkEzz\Yeelight\YeePHP;
$yeelight = new YeePHP('192.168.0.15', 12345);
All the methods are documented in the class and in the interface, here it is a global reminder:
Name | Parameters | Return type | Description |
---|---|---|---|
__construct | string $ip int $port | null | Class constructor |
isConnected | x | bool | Return true if the light is reacheable on the local network |
isOn | x | bool | Return true if the light is turned on |
getIP | x | string | Return the current light IP adress |
getPort | x | int | Return the current light port |
getBrightness | x | int | Return the current light brightness between 0 and 100 |
getColor | x | string | return an hexadecimal representation or the light color |
getName | x | string | Return the current light name |
toggle | x | self | Toggle the light state |
setColor | int $hexColor | self | Set the light color, must be an hexadecimal string (eg: 0xFFFFFF) |
setBrightness | int $amount | self | Set the light brightness, $amount must be between 0 and 100 |
setName | string $name | self | Set the light name |
setPower | string $power | self | Set the light power (off or on), $power must be "on" or "off" |
commit | x | bool | Send all the jobs (previous commands) to the light, return true if the changes has been applied |
disconnect | x | bool | Close the current opened socket to the light, return true if the socket has been closed, false otherwise |
If you want to test this library, make sure you have a working Yeelight RGB light in your local network with LAN control enabled.
You juste have to set the $ip
variable in the LightTest.php
file in the tests
folder.
Then just run the PHPUnit executable: ./vendor/bin/phpunit
Official Yeelight documentation
Inspired by Yeelight-PHP from itskenny0