Skip to content

Sebarkar/tuya-client-php

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Client for Tuya

StyleCI Build Status Author Software License Packagist Version Total Downloads

An WIP API Client for controlling Tuya products, heavily inspired by tuyapy.

Currently Supporting

  • Switch devices

Installation

composer require inverse/tuya-client

Example

<?php

require __DIR__ . '/vendor/autoload.php';

use Inverse\TuyaClient\Session;
use Inverse\TuyaClient\ApiClient;
use Inverse\TuyaClient\Device\SwitchDevice;
use Inverse\TuyaCliuent\Biztype;

// Setup credentials
$username = getenv('TUYA_USERNAME');
$password = getenv('TUYA_PASSWORD');
$countryCode = getenv('TUYA_COUNTRYCODE');
$bizType = new BizType(BizType::TUYA);

// Make client
$session = new Session($username, $password, $countryCode, $bizType);
$apiClient = new ApiClient($session);

// Get all devices
$devices = $apiClient->discoverDevices();

// Switch on all switches
foreach ($devices as $device) {
    if ($device instanceOf SwitchDevice) {
        if (!$device->isOn()) {
            $apiClient->sendEvent($device->getOnEvent());
        }
    }
}

Testing

Copy phpunit.xml.dist to phpunit.xml and replace the server variables with your credentials.

Licence

MIT

About

An API client for Tuya

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%