### PHP Composer Installation Source: https://github.com/ground-creative/tuyapiphp/blob/master/README.md Instructions for installing the Tuya Cloud API PHP client using Composer by adding the package to your composer.json file. ```php "require": { "tuyapiphp/tuyapiphp": "*" } ``` -------------------------------- ### PHP Basic Usage: Get Access Token Source: https://github.com/ground-creative/tuyapiphp/blob/master/README.md Shows how to obtain a new access token from the Tuya API using the `get_new` method of the token service. ```php $data = $tuya->token->get_new( ); ``` -------------------------------- ### PHP Device Operations: Get App List Source: https://github.com/ground-creative/tuyapiphp/blob/master/README.md Retrieves a list of devices associated with a specific Tuya App ID. Requires a valid access token. ```php $app_id = 'xxxxxxxxxxxxxxxxxxxx'; $device_id = 'xxxxxxxxxxxxxxxxxxx'; // Get a token $token = $tuya->token->get_new( )->result->access_token; // Get list of devices connected with tuya/smart life app $tuya->devices( $token )->get_app_list( $app_id ); ``` -------------------------------- ### PHP Device Operations: Get Status Source: https://github.com/ground-creative/tuyapiphp/blob/master/README.md Fetches the current status of a specific Tuya device using its device ID. Requires a valid access token. ```php $tuya->devices( $token )->get_status( $device_id ); ``` -------------------------------- ### PHP Camera Stream: Get Stream Link Source: https://github.com/ground-creative/tuyapiphp/blob/master/README.md Allocates a stream for a Tuya camera and returns the stream URL. Requires the App ID, Camera ID, and desired stream type (e.g., 'rtsp'). ```php $app_id = 'xxxxxxxxxxxxxxxxxx'; $camera_id = 'xxxxxxxxxxxxxxxxxxxx'; $tuya = new \tuyapiphp\TuyaApi( $config ); // Get a token $token = $tuya->token->get_new( )->result->access_token; // Get camera stream link $stream = $tuya->devices( $token )->post_stream_allocate( $app_id , $camera_id , [ 'type' => 'rtsp' ] ); Use the returned url to open the stream: `ffplay -i rtsps://xxxxxxxxx` ``` -------------------------------- ### PHP Basic Usage: Create Instance Source: https://github.com/ground-creative/tuyapiphp/blob/master/README.md Demonstrates how to create a new instance of the TuyaApi client with provided configuration including access key, secret key, and base URL. ```php $config = [ 'accessKey' => 'xxxxxxxxxxxxxxxxx' , 'secretKey' => 'xxxxxxxxxxxxxxxxx' , 'baseUrl' => 'https://openapi.tuyaus.com' ]; $tuya = new \tuyapiphp\TuyaApi( $config ); ``` -------------------------------- ### PHP Device Operations: Send Command Source: https://github.com/ground-creative/tuyapiphp/blob/master/README.md Sends a command to a Tuya device. Requires the device ID and a payload specifying the command code and value. ```php $payload = [ 'code' => 'switch_1' , 'value' => false ]; $tuya->devices( $token )->post_commands( $device_id , [ 'commands' => [ $payload ] ] ); ``` -------------------------------- ### PHP Device Operations: Set Name Source: https://github.com/ground-creative/tuyapiphp/blob/master/README.md Updates the name of a Tuya device. Requires the device ID and a payload containing the new name. ```php $tuya->devices( $token )->put_name( $device_id , [ 'name' => 'FAN' ] ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.