The Wi-Fi device linkage is implemented by creating a linkage rule between devices. When a device triggers the rule, the cloud issues control instructions to the associated devices. For example, the customer has a smart light and a smart air conditioner, for which a rule can be created based on the device linkage function provided by the Gizwits cloud. When the smart light is turned on, the smart air conditioner will be turned on, whose diagram is as follows.
Note: When creating linkage between two products, the two products must be associated with the same appid, otherwise, the error of appid does not exist will occur when requesting.
Pre-condition: The source device and target device must be associated to a same user. Then a rule set under the user will enable the linkage between devices.
The following is the flowchart of device linkage:
Description: Get all data point names and related variables of the device and product under the same pk associated with appid that can be used when creating rules.
Request URL: http://api.gizwits.com/app/rules/params?product_key=pk1,pk2
Request method: GET
Request Header:
Params | Data Type | Required | Param Type | Description |
---|---|---|---|---|
product_key | String | Yes | params | Provide a comma separated list of pk. When leaving blank, all pk associated to the appid are in use by default. When passing a pk that is not associated to the appid, the pk will be invalid. |
X-Gizwits-Application-Id | String | Yes | header | Gizwits APPID |
X-Gizwits-User-Token | String | Yes | header | User token |
Description: Create a device linkage rule.
1.Request URL: http://api.gizwits.com/app/rules
2.Request method: POST
3.Request parameters
Params | Data Type | Required | Param Type | Options | Description |
---|---|---|---|---|---|
X-Gizwits-Application-Id | String | Yes | header | Gizwits APPID | |
X-Gizwits-User-Token | String | Yes | header | User token | |
product_key | String | Yes | body | Product key | |
did | String | Yes | body | Device did | |
name | String | No | body | Product name | |
remark | String | No | body | Device alias | |
interval | Integer | No | body | The minimum trigger interval in seconds. After a rule with the parameter specified is triggered, it must wait until the specified interval elapses before next triggering. | |
event | String | Yes | body | online/offline/alert/fault/data/extern | Trigger mode. If this parameter is not set or set to empty, its value will be data by default. |
event_attr | Object | No | body | It’s required when the event parameter is set to alert or fault. | |
input | Array | No | body | Each object in the array represents the data of one device. Omit when you do not need to use device data. | |
condition | Array | No | body | Each sub array in the array represents a set of conditions. If this parameter is not set or set to empty, it means to trigger directly. | |
output | Array | Yes | body | Each sub array in the array represents a set of actions, of which at least one is required. |
Tips
a.event
Indicates the triggering method of the rule. The following is the meaning of the optional value:
If this parameter is not set or set to empty, its value will be data by default.
b.event_attr
When the trigger mode is alert/fault, the data point name for this alarm/fault, and the occurrence/recovery of the alarm/fault, are specified by this parameter:
1 | "event_attr": { |
Note:
The “occurrence” of the alarm/fault mentioned here means that the reported data point value of the last alarm/failure of the device is 0, and its reported value is 1 this time, then the alarm/failure occurs.
The “recovery” of the alarm/failure mentioned here means that the reported data point value of the last alarm/failure of the device is 1, and its reported value is 0 this time, then the alarm/failure recoveries.
Other cases are not “occurrence” and “recovery”.
c.did
When the trigger mode is online/offline/alert/fault/data, the device that fires this rule is specified by this parameter. The device is designated as the master device in the following.
d.input
Specifies the device data to be used in the rule. Each object in the array represents the data of one device. Omit if you do not need to use device data:
1 | [{ |
e.condition
Specify the conditions to be satisfied by the trigger rule. The conditions in the array will be checked on a group-by-group basis in the cloud processing. When any set of conditions is met, the rule is triggered.
1 | [ |
f.output
Specify what needs to be done when the conditions are met. The cloud can be thought of as performing all groups of actions in parallel. Each group does not affect each other.
1 | [ |
g.Body sample
1 | { |
4.Sample rule
When the data point Power_Switch of source device is switched on, the rule will be triggered to turn on the data point OnOff of the target device.
1 | { |
Description: Get all rules created by a user.
1.Request URL: http://api.gizwits.com/app/rules
2.Request method: GET
3.Request parameters
Params | Data Type | Required | Param Type | Description |
---|---|---|---|---|
X-Gizwits-Application-Id | String | Yes | Header | Gizwits APPID |
X-Gizwits-User-Token | String | Yes | Header | User token |
Description: Update a rule whose identifier value is rule_id.
1.Request URL: http://api.gizwits.com/app/rules/{rule_id}
2.Request method: PUT
3.Request parameters
Params | Data Type | Required | Param Type | Options | Description |
---|---|---|---|---|---|
X-Gizwits-Application-Id | String | Yes | header | Gizwits APPID | |
X-Gizwits-User-Token | String | Yes | header | User token | |
product_key | String | Yes | body | Product key | |
did | String | Yes | body | Device did | |
name | String | No | body | Product name | |
remark | String | No | body | Device alias | |
interval | Integer | No | body | The minimum trigger interval in seconds. After a rule with the parameter specified is triggered, it must wait until the specified interval elapses before next triggering. | |
event | String | Yes | body | online/offline/alert/fault/data/extern | Trigger mode. If this parameter is not set or set to empty, its value will be data by default. |
event_attr | Object | No | body | It’s required when the event parameter is set to alert or fault. | |
input | Array | No | body | Each object in the array represents the data of one device. Omit when you do not need to use device data. | |
condition | Array | No | body | Each sub array in the array represents a set of conditions. If this parameter is not set or set to empty, it means to trigger directly. | |
output | Array | Yes | body | Each sub array in the array represents a set of actions, of which at least one is required. |
4.Sample rule
1 | { |
5.Sample for updating a rule
When the data point Power_Switch of source device is switched on, the rule will be triggered to turn on the data point OnOff of the target device, and then wait 5s, and then set the data point Lightness of the target device to 25.
1 | { |
Description: Delete a rule whose identifier value is rule_id.
Request URL: http://api.gizwits.com/app/rules/{rule_id}
Request method: DELETE
Request parameters:
Params | Data Type | Required | Param Type | Options | Description |
---|---|---|---|---|---|
X-Gizwits-Application-Id | String | Yes | Header | Gizwits APPID | |
X-Gizwits-User-Token | String | Yes | Header | User token | |
rule_id | Integer | Yes | url | Rule ID |