---
name: "addTimer"
mode: "kit"
versionRequirements:
  - { name: "DeviceKit", version: "1.2.6" }
platform:
  - "iOS"
  - "Android"
async: true
---

## addTimer

> [VERSION] DeviceKit >= 1.2.6

> [PLATFORM] iOS, Android

> ⚡ **Supports Promise** — Returns a Promise when success / fail / complete callbacks are omitted.

### Description

Add timer

### Parameters

| Property | Type | Required | Default | Since | Description |
| --- | --- | --- | --- | --- | --- |
| `deviceId` | `string` | No | - | `1.2.6` | deviceId Device ID; at least one of deviceId or groupId is required |
| `groupId` | `string` | No | - | `1.2.6` | groupId Group ID; at least one of deviceId or groupId is required |
| `category` | `string` | Yes | - | `1.2.6` | category Timer category |
| `timer` | `AddTimerModel` | Yes | - | `1.2.6` | timer Model for adding a timer |
| `complete` | `() => void` | No | - | - | Callback executed when the API call completes (runs on both success and failure) |
| `success` | `(params: Object) => void` ↓see below | No | - | - | Success callback |
| `fail` | `(params: Object) => void` ↓see below | No | - | - | Failure callback |

#### success callback parameters

| Property | Type | Since | Description |
| --- | --- | --- | --- |
| `timerId` | `string` | `3.3.0` | timerId Timer ID |

#### fail callback parameters

| Property | Type | Description |
| --- | --- | --- |
| `errorMsg` | `string` | Error message |
| `errorCode` | `string \| number` | Error code |
| `innerError` | `Object` | Error extensions |

##### fail(params).innerError properties

| Property | Type | Description |
| --- | --- | --- |
| `errorCode` | `string \| number` | Extended error code |
| `errorMsg` | `string` | Extended error information |


### Referenced Types

##### `interface` AddTimerModel

| Property | Type | Since | Description |
| --- | --- | --- | --- |
| `time` | `string` | `1.2.6` | time Time when the timer runs |
| `loops` | `string` | `1.2.6` | loops Seven-digit numeric string; "1000000" represents Sunday, "0100000" represents Monday |
| `dps` | `Record<string, Record<string, any>>` | `1.2.6` | dps DP data, for example: {     "1": true,     "2": false } |
| `aliasName` | `string` | `1.2.6` | aliasName Alias |
| `isAppPush` | `boolean` | `1.2.6` | isAppPush Whether to send execution notifications |


### Examples

#### Demo

```tsx
ty.device.addTimer({
  deviceId: "vdevo177319884964790",
  category: "category_timer",
  timer: { time: "16:38", loops: "0000000", dps: {20:0}, aliasName: "xx", isAppPush: false },
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});
```
