Tuya Home SDK Flutter

Tuya

Introduction

Tuya Home SDK Flutter is a plugin for integrating Tuya IoT functionalities into Flutter applications. It provides a set of APIs for managing user authentication, controlling devices, managing homes and rooms, and more.

Installation

Step 1: Set Up Tuya Developer Account Go to the Tuya IoT Platform and create an account. Once logged in, create a new project: Click on "Create Cloud Project". Fill in the necessary details like project name, industry, and description. Choose the development method as "Smart Home" and region that matches your location. After creating the project, note down the Access ID and Access Secret from the "Project Overview" page.

Step 2: Register Your Mobile App Within the same project dashboard, go to "App Service" > "App SDK Development". Click on "Create App". Choose the platform (iOS, Android) and provide the necessary information like package name and app version. After creating the app, you will receive an AppKey and AppSecret which are needed for the SDK integration. To use Tuya Home SDK Flutter in your Flutter project, follow these steps:

  1. Add tuya_home_sdk_flutter as a dependency in your pubspec.yaml file:
dependencies:
  tuya_home_sdk_flutter: ^version_number

Usage

Initialization

To initialize the Tuya Home SDK, use the initSdk method:

import 'package:tuya_home_sdk_flutter/tuya_home_sdk_flutter.dart';

void main() async {
  await TuyaHomeSdkFlutter.instance.initSdk('your_app_key', 'your_app_secret');
}

User Authentication

You can authenticate users, send verification codes, register users, and login users using methods provided by the SDK. For example:

bool result = await TuyaHomeSdkFlutter.instance.sendVerifyCodeWithUserName(
  username: 'john',
  countryCode: '+1',
  type: 2,
);

Device Discovery

List<ThingSmartDeviceModel> devices = await TuyaHomeSdkFlutter.instance.discoverDeviceInfo();

Device Management

connect device via BLE

  var device = await startConfigBLEWifiDevice(
    ssid: 'MyWiFiNetwork',
    password: 'MyPassword',
    homeId: 123,
    deviceUuid: 'abcd1234',
    deviceProductId: 'xyz789',
    timeout: 200,
       );
  if (device != null) {
    // Device configuration successful
  } else {
    // Error occurred during device configuration
  }

Home and Room Management

Manage homes, rooms, and assign devices to rooms:

// Add a home
num? homeId = await TuyaHomeSdkFlutter.instance.addHomeWithName(
  name: 'My Home',
  geoName: 'My Geo',
  rooms: ['Living Room', 'Bedroom'],
  latitude: 37.7749,
  longitude: -122.4194,
);

// Get a list of rooms in a home
List<ThingSmartRoomModel> rooms = await TuyaHomeSdkFlutter.instance.getHomeRooms(
  homeId: homeId!,
);

// Assign a device to a room
bool assigned = await TuyaHomeSdkFlutter.instance.assignDeviceToRoom(
  deviceId: 'your_device_id',
  homeId: homeId,
  roomId: 1,
);

Purchasing a License Key

For purchasing and managing license keys please contact us on our Mail.