English
English
简体中文
Contact Us
Register
Log In

Smart Home Quick Start

Last Updated on : 2023-03-21 08:58:48download

This topic describes how to create and set up a cloud development project in the smart home system, and how to integrate it with Tuya’s cloud development.

Example

Authorize and link an OEM app to a new cloud project. Then, query user information and control devices by using OpenAPI and message queues.

  1. Become a developer on the Tuya IoT Development Platform.
  2. Create and set up a cloud development project.
  3. Link the project with an OEM app.
  4. Subscribe to the message queue service.
  5. Develop and debug.
    a. Get the token required to call OpenAPI.
    b. Get a list of users for a specified OEM app.
    c. Get a list of devices that belong to a specified user.
    d. Query the instructions supported by a device in the device list.
    e. Send an instruction to the device.
    f. With the message service, listen for the messages generated by this instruction.

Interaction logic

The following figure shows the interaction logic.

Smart Home Quick Start

The whole process is detailed step by step.

Become a developer

  1. Go to the account registration page on the Tuya IoT Development Platform.

  2. Follow the guide to register a developer account. The registered account is granted all respective permissions. Keep it properly.

    If you are an organization developer, you can follow instructions in Organization Verification and verify your organization’s identity.

Create and set up a cloud project

The cloud project is a carrier or collection of resources on the Tuya IoT Development Platform, including devices and users. Resources deployed for each project are isolated from those for other projects.

  1. Log in to the Cloud Development Platform.

  2. In the left-side navigation bar, choose Cloud > Development > Create Cloud Project.

    Smart Home Quick Start

  3. Enter the required information as prompted and click Create.

    To create a smart home project, you must select Smart Home in the Development Method field.

    Smart Home Quick Start

  4. On the Configuration Wizard page, click Authorize to subscribe to the API services and authorize the cloud project.

    Smart Home Quick Start

    By default, the APIs that support the specified development method are selected for the project on the platform. You can add or delete the default API services, or select other API services. For more information about API services, see Manage API Services.

  5. After you create and set up a project, you can view the project in the project list.

    Smart Home Quick Start

    For more information about cloud projects, see Manage Projects.

Link cloud project with business data

After creating a cloud project, you need to link your OEM app with the cloud project.

  1. On the page of Cloud Management, click a project to enter the details page.

  2. Choose Devices > Link My App > Add Apps.

    Smart Home Quick Start

  3. Select the desired OEM app and link it with the cloud project.

    The following figure shows the linking result.

    Smart Home Quick Start

    • If you have not created an OEM app, you can link a Tuya app account with the project.
    • During the linking with an OEM app or a Tuya app account, a window appears for you to select the device linking method and device permission. To get started quickly, select Automatic Link as the device linking method and Read, Write, and Manage as the device permission. For more information about linking, see Link Devices.

Enable message service

On the page of Cloud > Message Service, you can enable this service for the cloud project and configure parameters to get alerts of excessive messages.

Smart Home Quick Start

The following figure shows the result of enabling the message service.

Smart Home Quick Start

For more information about the message service, see Message Service.

Develop and debug

API calls

We will use the API Explorer to complete the above case.

  1. Call the Get User List API to get a list of app users.

    Smart Home Quick Start

    As shown above, there is a user with UID ay16600***ONz7 under the current OEM app.

  2. Call the Get User’s Device List API to get a list of devices that belong to the user.

    Smart Home Quick Start

    As shown above, there is a socket device with ID 87707085bcddc****fa3 that belongs to the user.

    If you have linked a Tuya app account with the project, you can find the user ID (UID) in the list of linked accounts.

  3. In the Device Control section, call the Get the instruction set supported by the device API to get the instructions supported by the device.

    Smart Home Quick Start

    The socket supports two functional instructions:

    • Switch
    • Countdown

    The code of the switch instruction is switch_1, and the value is of Boolean type. true: Turn on. false: Turn off. For more information about functional instructions, see Standard Instruction Set.

  4. Call the Control Device API to control the device and turn on the socket.

    Smart Home Quick Start

    The output window shows that the insruction has been sent to the device. The content of the instruction is as follows:

    [
        {
            "code":"switch_1",
            "value":true
        }
    ]
    

Message service

  1. On the Message Test tab, add the device to the message test channel and enable the Test Channel.

    Smart Home Quick Start

  2. Call the Control Device API again and observe the test channel.

    Smart Home Quick Start

    As you can see, the listener has returned the message that the socket was turned off.

    The message test channel is for trial and debugging only. If you add your device to the test channel, you will not receive messages in the production environment.

Now, you have completed the quick start and can dive deep into the smart home system.