Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.
/ YeePHP Public archive

💡 A simple PHP library to control your Yeelight RGB lights (currently in development)

Notifications You must be signed in to change notification settings

SharkEzz/YeePHP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

YeePHP

A simple standalone PHP library to interact with Yeelight RGB bulbs (still in development)

Yeelight-PHP ?

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.

Requirements

  • PHP 7.4 or up (tested with PHP 8.0)
  • PHP sockets extension
  • PHP JSON extension
  • Yeelight local network control enabled on your lights

How to install

  • 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!

How does it work ?

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!

Currently implemented methods

  • 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

Examples

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:

Change the light color
<?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

Change the light brightness
<?php

require_once './vendor/autoload.php';

use SharkEzz\Yeelight\YeePHP;

$yeelight = new YeePHP('192.168.0.15');

$yeelight->setBrightness(50)
    ->commit();

Change the color and the brightness in one line of code
<?php

require_once './vendor/autoload.php';

use SharkEzz\Yeelight\YeePHP;

$yeelight = new YeePHP('192.168.0.15');

$yeelight->setBrightness(50)
    ->setColor(0x00FF00)
    ->commit();

Testing

If you want to test this library, make sure you have a working Yeelight RGB light in your local network.

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

Credits

Official Yeelight documentation

Inspired by Yeelight-PHP from itskenny0

About

💡 A simple PHP library to control your Yeelight RGB lights (currently in development)

Resources

Stars

Watchers

Forks

Languages