{"id":23338952,"url":"https://github.com/aymkdn/tuyacloud-php","last_synced_at":"2025-04-09T22:32:27.958Z","repository":{"id":43999016,"uuid":"260688994","full_name":"Aymkdn/tuyacloud-php","owner":"Aymkdn","description":"PHP Library to access to the SmartLife / Tuya objects using the Tuya Cloud API","archived":false,"fork":false,"pushed_at":"2024-09-28T14:34:01.000Z","size":28,"stargazers_count":31,"open_issues_count":0,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-24T00:25:45.232Z","etag":null,"topics":["php","smartlife","smartlife-api","tuya","tuya-api"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Aymkdn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-02T13:07:30.000Z","updated_at":"2024-11-14T17:00:17.000Z","dependencies_parsed_at":"2023-01-19T14:01:13.070Z","dependency_job_id":null,"html_url":"https://github.com/Aymkdn/tuyacloud-php","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aymkdn%2Ftuyacloud-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aymkdn%2Ftuyacloud-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aymkdn%2Ftuyacloud-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aymkdn%2Ftuyacloud-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Aymkdn","download_url":"https://codeload.github.com/Aymkdn/tuyacloud-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248123778,"owners_count":21051532,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","smartlife","smartlife-api","tuya","tuya-api"],"created_at":"2024-12-21T03:17:19.874Z","updated_at":"2025-04-09T22:32:27.936Z","avatar_url":"https://github.com/Aymkdn.png","language":"PHP","readme":"# tuyacloud-php\n\nPHP Library to access to the SmartLife / Tuya objects using the Tuya Cloud API.\n\nNote: you need a Smartlife Account created with an email, not with Google Connection or similar third party. You could also create a new account from email and then invite this account to the \"family\" of your main Smartlife Account.\n\n## Required\n\nA developer account must be created on the [Tuya platform](https://eu.platform.tuya.com/). I'm not sure how the details, but from the menu, access to [`Cloud` \u003e `Development`](https://eu.platform.tuya.com/cloud/) and create a cloud project.\n\nOnce the project is created, it will show you the **access key** and **access secret**.\n\nUnder the tab `devices`, you can tie the project with your Tuya/SmartLife app by scanning a QR Code. If it worked, you will see all your devices listed on this page (with their `device_id`).\n\nYou need to know which region/server you're using, and then you have to use the correct URL:\n - China Data Center: https://openapi.tuyacn.com\n - Western America Data Center: https://openapi.tuyaus.com\n - Central Europe Data Center: https://openapi.tuyaeu.com\n - India Data Center: https://openapi.tuyain.com\n\n\n## Usage\n\n```php\n\u003c?php\nrequire 'TuyaCloud.php';\n\n$options = [\n  'baseUrl' =\u003e 'https://openapi.tuyaeu.com', // URL API of Tuya\n  'accessKey' =\u003e 'nhepe4mrrtz8wju45mk3', // access key of your app\n  'secretKey' =\u003e 'sf94ryyrfvg3awvg4174m88wjpksytre', // access secret of your app\n];\n\n$tuya = new TuyaCloud($options);\ntry {\n  // to get the device status\n  // you must pass the device_id\n  $response = $tuya-\u003egetDevice('bfa18afnfyre87eb7ne0');\n  echo '\u003cpre\u003e';\n  print_r($response);\n  echo '\u003c/pre\u003e';\n  \n  // to send a command \n  // you can pass a JSON string: '{\"commands\":[{\"code\":\"switch_led\",\"value\":true}]}'\n  // or a strClass object\n  // or an array like the below one:\n  $commands = [\n    \"commands\" =\u003e [\n      [\n        \"code\" =\u003e \"switch_led\",\n        \"value\" =\u003e true\n      ]\n    ]\n  ];\n  $response = $tuya-\u003esetDevice('bfa18afnfyre87eb7ne0', $commands);\n  \n  // we can retrieve all the scenes (including their id)\n  $response = $tuya-\u003egetScenes();\n  echo '\u003cpre\u003e';\n  print_r($response);\n  echo '\u003c/pre\u003e';\n  \n  // and we can start a scene\n  $response = $tuya-\u003estartScene('the_scene_id');\n} catch (Exception $e) {\n  echo 'Error: ' . $e-\u003egetMessage();\n}\n?\u003e\n```\n\nThe different commands can be foundby going to your project in the [Tuya Cloud Development platform](https://eu.platform.tuya.com/cloud/), then click on the device and you can find the options.\n\nExamples:\n  - a curtain can have the `command` `open`, `close`, or `stop`\n  - a light will have `switch_led` with `true` or `false`\n  - a power strip with 2 outlets will have `switch_1` with `true` or `false`, and the same for `switch_2`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faymkdn%2Ftuyacloud-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faymkdn%2Ftuyacloud-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faymkdn%2Ftuyacloud-php/lists"}