---
name: "addTimer"
mode: "kit"
versionRequirements:
  - { name: "DeviceKit", version: "1.2.6" }
  - { name: "@ray-js/ray", version: "0.6.23" }
platform:
  - "iOS"
  - "Android"
async: true
---

## addTimer

> [VERSION] DeviceKit >= 1.2.6 | @ray-js/ray >= 0.6.23

> [PLATFORM] iOS, Android

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

### Description

Add a 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 Timer model to add |
| `complete` | `() => void` | No | - | - | Completion callback (executed on both success and failure) |
| `success` | `(params: Object) => void` ↓see below | No | - | - | Callback on successful API call |
| `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 extension |

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

| Property | Type | Description |
| --- | --- | --- |
| `errorCode` | `string \| number` | Error extension code |
| `errorMsg` | `string` | Error extension message |


### Referenced Types

##### `interface` AddTimerModel

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


### Examples

#### Basic usage

```tsx
import { device } from '@ray-js/ray'

const { addTimer } = device;

addTimer({
  category: 'example',
  timer: { time: 'example', loops: 'example', dps: {} },
  success: (result) => {
    console.log('addTimer success', result);
  },
  fail: (error) => {
    console.log('addTimer fail', error.errorMsg);
  },
});
```
