Smart air purifier control
更新时间:
复制 MD 格式
In this tutorial, you will create a business service to automatically control an air purifier. This service turns the air purifier off when the reported PM2.5 concentration is less than 100 and turns it on when the concentration is 100 or greater.
Prerequisites
You have created products and devices for air detection (Air Detector: airDetector) and purification (Air Purifier: airPurifier) in the Project_test project. For details, see Create products for air detection and purification in a project.Create an air purifier control service
- Create a business service in your project, for example, Air Purification. For details, see Create a business service.
- On the business logic development page, click the Node button on the left. Drag a Device trigger node onto the canvas. Configure the node to use the PM2.5 Concentration property from the airDetector device as input.
- Drag a Conditional node onto the canvas, connect it to the device trigger node, and configure it.Set Condition 1: The PM2.5 value from the device trigger is greater than or equal to 100.
- Drag two Air Purifier product nodes onto the canvas. Connect them to the success and failure branches of the Conditional node, respectively, and configure them.
Parameter Description Node name Enter a name for the node. Select device to control Select the airPurifier device. Select operation type Select the operation type. Options: Execute Device Action, Query Device Property, and Query Other Device Information. To send a command to control the power switch, select Execute Device Action.
Payload Set the PowerSwitchproperty in the payload. For the node on the success branch (condition met), set the value totrue. This turns on the air purifier when the PM2.5 value is 100 or greater. For the node on the failure branch, set the value tofalseto turn off the air purifier. - In the upper-right corner of the page, click Save
to save the service.
Debug and publish
- On the business service editing page, click Deploy & Debug
in the upper-right corner to deploy and start the service. - After the service is deployed successfully, click Deploy & Debug
in the upper-right corner to debug the service.- Click to open the product's device simulator page.
- Click Start virtual device.
- Select .
- In the default module, send a debug command.
In this example, a simulated PM2.5 value of 101 is sent. Because this value is greater than 100, the air purifier receives a command to turn on.
In the device simulator's uplink command debugging panel, select the Property report tab. Enter a value for the PM25 field and click Send Command. APROPERTY_REPORTrecord will appear in the device logs panel on the right, confirming a successful property report.
- On the project's Devices page, check the running status of the air purifier. The
PowerSwitchstatus is 1 (On).You can return to the service development page to view the related logs.
The workflow for the Control Air Purifier automation rule consists of Device trigger, Conditional, and Air Purifier nodes. In the log viewing area, you can check the Global Log to see the execution details for each node. For example, the log for the device trigger node shows that the reportedPM25property value was101. - On the service development page, click the Publish button
in the upper-right corner.You must publish the business service to the cloud before it can be invoked.
该文章对您有帮助吗?