PHP code example of inverse / tuya-client
1. Go to this page and download the library: Download inverse/tuya-client library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
inverse / tuya-client example snippets
nverse\TuyaClient\Session;
use Inverse\TuyaClient\ApiClient;
use Inverse\TuyaClient\Device\SwitchDevice;
use Inverse\TuyaClient\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());
}
}
}