Usage
The current Alarm Ability SDK provides standard abstractions for the following two types of scenarios, allowing developers to use them according to their business needs:
- Built-in alarms (alarm switch)
- Custom alarms
Getting Started
Required to import
HomeKit, and can only be used in version>=3.0.1.
SmartAlarmAbility was introduced in @ray-js/panel-sdk@1.8.0 and has been included as a basic example in the Generic Abilities - Usage page.
Basic use
Here's an example of accessing generic abilities using basic JavaScript:
Ray & SDM
Here's an example of accessing generic abilities using Ray and SDM. By integrating with SDM, you can enjoy better TypeScript type hints and the development experience provided by React Hooks:
src/devices/index.ts
Create a smart device model for the sensor with built-in alarm capability
src/app.tsx
Access the React ecosystem through SdmProvider
src/pages/home.tsx
Fetch the alarm list and display it using TyList
Use Case
Built-in Alarms
Some sensor devices have built-in functionality to push alarm messages. For example, a door sensor may need to push a message to the user when the door is opened or closed. To handle such fixed push notifications, some product categories have predefined templates for easy use by IoT developers. Users can customize the enablement or disablement of such message notifications in the device panel on the consumer (C) app.
Related APIs
- Get device alarm configuration list: getBuiltInAlarmList
- Enable/disable alarms: setBuiltInAlarmStatus
- Hooks: useBuiltInAlarm
Workflow
Custom Alarms
For more complex alarm triggering rules that cannot be satisfied by the alarm switch, custom alarm scenarios are used. For example, in the temperature and humidity sensor category, users may want to adjust the upper and lower temperature limits and trigger alarms within the custom range. Users may also want to define other rules, such as triggering alarms based on specific functionalities, delayed push notifications, notification methods, and events.
Related APIs
- Query custom alarm rule list: getCustomAlarmList
- Add/modify custom alarm rule: addCustomAlarm
- Enable/disable custom alarm rule: setCustomAlarmStatus
- Delete custom alarm rule: deleteCustomAlarm
- Hooks: useCustomAlarm