Tuya Api PHP Client

Related tags

API tuyapiphp
Overview

Tuya Api PHP Client

This is a simple php client to interact with devices that support the tuya api over the cloud.

Requirements

I believe all is needed is php curl for the requests.

Installation

With composer:

Add the package to your composer.json file

"require": 
{

        "tuyapiphp/tuyapiphp": "*"
}

and run composer update

Stand Alone:

You must require all the needed classes manually, or you can use an autoloader like this one.

Basic Usage

Use these setup instructions for how to find the needed parameters.

Create new instance

	$config =
	[
		'accessKey' 	=> 'xxxxxxxxxxxxxxxxx' ,
		'secretKey' 	=> 'xxxxxxxxxxxxxxxxx' ,
		'baseUrl'	=> 'https://openapi.tuyaus.com'
	];
	
	$tuya = new \tuyapiphp\TuyaApi( $config );

Get an access token

        $data = $tuya->token->get_new( );	

Example device operations

	$app_id = 'xxxxxxxxxxxxxxxxxxxx';
	
	$device_id = 'xxxxxxxxxxxxxxxxxxx';
	
	// Get a token
	$token = $tuya->token->get_new( )->result->access_token;
	
	// Get list of devices connected with android app
	$tuya->devices( $token )->get_app_list( $app_id );
	
	// Get device status
	$tuya->devices( $token )->get_status( $device_id );

	// Set device name
	$tuya->devices( $token )->put_name( $device_id , [ 'name' => 'FAN' ] );
	
	// Send command to device
	$payload = [ 'code' => 'switch_1' , 'value' => false ];
	$tuya->devices( $token )->post_commands( $device_id , [ 'commands' => [ $payload ] ] );

Example camera stream

	$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

You might also like...
PHP Pi Horizon Client Library

phpi-sdk PHP Pi Horizon Client Library This is part of FASTLANE project for the pi payment gateway, as we are trying to build a pi wallet inside FASTL

PSR-15 middleware to geolocate the client using the ip address

middlewares/geolocation ![SensioLabs Insight][ico-sensiolabs] Middleware to geolocate the client using the ip address and Geocoder and save the result

微信支付 API v3 的 PHP Library,同时也支持 API v2

微信支付 WeChatPay OpenAPI SDK [A]Sync Chainable WeChatPay v2&v3's OpenAPI SDK for PHP 概览 微信支付 APIv2&APIv3 的Guzzle HttpClient封装组合, APIv2已内置请求数据签名及XML转换器,应

This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science courses and the like.
This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science courses and the like.

Simple PHP API v.1.0 This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science courses a

This API provides functionality for creating and maintaining users to control a simple To-Do-List application. The following shows the API structure for users and tasks resources.
This API provides functionality for creating and maintaining users to control a simple To-Do-List application. The following shows the API structure for users and tasks resources.

PHP API TO-DO-LIST v.2.0 This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science cours

API documentation API SCB EASY APP

SCB-API-EASY V3.0 API documentation SIAM COMMERCIAL BANK PUBLIC COMPANY LTD. API SCB Easy V3 endpoint = https://fasteasy.scbeasy.link 1.0. Get balance

Courier API adalah project API untuk mengetahui ongkos kirim Logistik-logistik pengiriman barang antar kota & International
Courier API adalah project API untuk mengetahui ongkos kirim Logistik-logistik pengiriman barang antar kota & International

Courier API Courier API adalah project API untuk mengetahui ongkos kirim Logistik-logistik pengiriman barang antar kota (dalam negeri) & International

Laravel api tool kit is a set of tools that will help you to build a fast and well-organized API using laravel best practices.
Laravel api tool kit is a set of tools that will help you to build a fast and well-organized API using laravel best practices.

Laravel API tool kit and best API practices Laravel api tool kit is a set of tools that will help you to build a fast and well-organized API using lar

LaraBooks API - Simple API for iOS SwiftUI app tests.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Comments
  • /iot-03 ?

    /iot-03 ?

    First: great job on this project, got it running within minutes.

    Second: the endpoints of the API all point to /v1.0/iot-03/ where your code points only to /v1.0/. Is this something redirected in the request or something that needs to be updated to be up-to-date?

    Guess I could commit this myself? But since I'm not very familiar with github, I thought I'd post this for your consideration.

    opened by vespino 4
  • Cannot pass

    Cannot pass "type" query param to get_logs.

    Hi,

    I'm trying to get the logs for a particular device, but the example given:

    $tuya->devices($token)->get_logs($deviceId)

    Causes error:

    ( [code] => 1102 [msg] => type param is null [success] => [t] => 1638617686644 )

    This is because the "type" query param is required for get_status, see here:

    https://developer.tuya.com/en/docs/cloud/0a30fc557f?id=Ka7kjybdo0jse

    I have tried:

    $tuya->devices($token)->get_logs($deviceId, ['type' => '1,2,3,4,5,6,7,8,9']),

    But it causes the URL to become malformed (i.e. it's missing the "/v1.0/devices/{device_id}/logs" part)

    GET https://openapi.tuyaeu.com?type=1%2C2%2C3%2C4%2C5%2C6%2C7%2C8%2C9

    It looks as though the package does not correctly handle payloads for GET requests.

    opened by JamesPoel 3
Releases(v1.0.0)
Owner
null
Chargebee API PHP Client (for API version 2 and Product Catalog version 2.0)

chargebee-php-sdk Overview This package provides an API client for Chargebee subscription management services. It connects to Chargebee REST APIs for

GLOBALIS media systems 8 Mar 8, 2022
The efficient and elegant, PSR-7 compliant JSON:API 1.1 client library for PHP

Woohoo Labs. Yang Woohoo Labs. Yang is a PHP framework which helps you to communicate with JSON:API servers more easily. Table of Contents Introductio

Woohoo Labs. 160 Oct 16, 2022
PHP unofficial client to CryptoPanic.com API

PHP unofficial client to CryptoPanic.com API CryptoPanic.com is a news aggregator platform indicating impact on price and market for traders and crypt

null 6 Nov 2, 2022
This is the PHP ApiDQ API client

ApiDQ API PHP Client This is the PHP ApiDQ API client. This library allows using of the actual API version. You can find more info in the documentatio

Nikita Krasnikov 2 Oct 5, 2021
Simple Client for Airtable API

Airtable Client Bundle (Work In Progress) The Airtable Client bundle is a Symfony bundle that attempts to make the Airtable API easier to use. Retriev

Yoan Bernabeu 28 May 12, 2022
Laravel A2Reviews Client API lets you build apps, extensions, or plugins to get reviews from the A2reviews APP.

Overview Laravel A2Reviews Client API lets you build apps, extensions or plugins to get reviews from the A2reviews APP. Including adding reviews to a

Be Duc Tai 2 Sep 26, 2021
A basic, opinionated, Laravel Api Client

Laravel Api Client Installation Install the pacakage via composer composer require antonioprimera/laravel-api-client If you want to use pre-configured

Antonio Primera 2 Nov 3, 2022
Laravel Client REST Camunda API

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Uriel Reyes 1 Nov 5, 2021
Airbrake.io & Errbit integration for Symfony 3/4/5. This bundle plugs the Airbrake API client into Symfony project

AmiAirbrakeBundle Airbrake.io & Errbit integration for Symfony 3/4/5. This bundle plugs the Airbrake API client into Symfony project. Prerequisites Th

Anton Minin 8 May 6, 2022
Simple and effective multi-format Web API Server to host your PHP API as Pragmatic REST and / or RESTful API

Luracast Restler ![Gitter](https://badges.gitter.im/Join Chat.svg) Version 3.0 Release Candidate 5 Restler is a simple and effective multi-format Web

Luracast 1.4k Dec 14, 2022