The rules for scene orchestrations allows you to automate complex workflows based on business logic. You can set the triggers and conditions for scene rules based on time and device properties. The rules then execute actions that change the state of other rules, devices or functions. This allows you to perform large-scale orchestrations of devices.

Create scene rules

  1. Log on to the IoT Platform console. In the left-side navigation pane, choose Rules > Scene Orchestration.
  2. Click Create Rule.Scene orchestration
  3. Configure the parameters, and click OK.
    Parameter Description
    Name The name of the rule. The name must be 1 to 30 characters in length and can contain letters, digits, underscores (_), and hyphens (-).
    Rule Description (Optional) The description of the rule.
  4. After the scene rule is created, click Edit to configure the scene rule.
    Alternatively, you can configure the scene rule by clicking View to the right of the rule name.

    For example, you can use a scene rule to automate an air conditioner. When the indoor temperature reported by the temperature sensor is lower than 16 degrees Celsius, the air conditioner automatically raises the indoor temperature to 26 degrees Celsius.

    The specific parameter settings are shown in the following figure.

    Set up scene orchestration parameters

    In the upper-right corner of the page, you click Edit to change the name of the scenario rule. For other parameters, see the following table.

    Parameter Description
    Trigger The triggers that set off the rule. You can select Device Trigger or Timed Trigger. When the reported device data or the current time meets the triggers, the system checks whether the conditions for triggering the rule are met. You can create one or more triggers for a rule. The rules are related by logic OR operations.
    • If you select Device Trigger, you must select a product name, a device name, and then the device property or event.
    • If you select Timed Trigger, you must specify the point of time. The time must be specified using a CRON expression. A CRON expression consists of five fields, minute, hour, day, month, day number of the week (0 or 7 represents Sunday and 1 to 6 represent Monday to Saturday). The fields are separated by a space. For example, the CRON expression for every day at 18:00 is 0 18 * * * and the expression for every Friday at 18:00 is 0 18 * * 5. The asterisk (*) are wildcards. For more information about how to write a CRON expression, visit CRONTAB.

      In the preceding example, Device Trigger is selected and the trigger is when the indoor temperature reported by the sensor is lower than 16 degrees Celsius.

    Condition The set of conditions. The rule is triggered only when the data meets all conditions. You can select Device Status or Time Range. You can create one or more conditions for a rule. The conditions are related by logical AND operations.
    • If you select Device Status, you must select a product name, a device name, and then the device property or event.
    • If you select Time Range, you must set the start time and end time in the format of yyyy-mm-dd hh24:mi:ss.

    In the preceding example, Time Range is selected and the rule can be triggered between 12:00 and 23:59.

    Action The operation that you want to perform. You can select Device Output or Rule Output. You can create one or more actions. When an action fails, it does not affect other actions.
    • If you select Device Output, you must select a product name, a device name, and then the device property or service. Only writable properties or services can be selected to perform the action. IoT Platform performs the actions based on the defined device properties or services when both the triggers and the conditions for the rule are met.
    • If you select Rule Output, you must select another rule and the action will invoke the selected rule. The triggers for the invoked rule are skipped and only the conditions of the rule are checked. If the conditions are met, the actions defined in the invoked rule is performed.

      For example, if Rule A is invoked, the Trigger of Rule A is skipped. The Condition is checked. If all conditions defined under Condition are met, IoT Platform will perform the Action of Rule A.

    In the preceding example, Device Output is selected, the air conditioner will set the temperature to 26 degrees Celsius.

    Delayed Execution The parameter that is available after you expand the advanced options. After the delay time is set, the execution of the Action will be delayed. Valid values: 0 to 86400. Unit: seconds.

Enable scene rules

After the scene rule is created, you can enable the rule on the Scene Orchestration page.

You perform the following steps to enable scene rules:

  1. Log on to the IoT Platform console. In the left-side navigation pane, choose Link IoT Edge > Edge Instances.
  2. Find the scene rule that you want to enable. Click Start and the status of the rule status becomes Running.
    Enable scene rules

After you enable the rule:

  • If the scene rule is running on the cloud, you must configure message routing for the devices of the scene rule, so that the device properties and events can be sent to the IoT Hub on the cloud. For more information about message routing, see Configure message routing.
  • If the scene rule is running at the edge, you must Stop the rule on the cloud and associate the scene rule with the edge instance. For more information about the association method, see the Other operations for scene orchestration section of this topic.

View logs

You can view the logs of scene rules and view the running results on the details page.

Note If a scene rule is running on the cloud and at the edge, you can view the logs by choosing Rules > Scene Orchestration.
  1. In the left-side navigation pane of the IoT Platform console, choose Rules > Scene Orchestration.
  2. Find the scene rule and click Logs.
  3. Click Details to view the log details.
    View scene orchestration logs
    Note If the Status of a log is Failure, you can click Details to view the details of the failed executions.

Other operations for scene orchestration

  • Delete scene rules:
    1. On the Scene Orchestration page, find the rule that you want to delete.
    2. Click Delete to the right of the rule name. In the dialog box that appears, click OK to delete the scene rule.
  • Trigger scene rules:

    After you Start a scene rule, you can perform the Trigger operation.

    1. On the Scene Orchestration page, find the rule that you want to trigger.
    2. Click Trigger to the right of the rule name, and the rule is manually triggered once. All actions of the rules are performed bypassing the predefined triggers and conditions.
  • Run scene orchestrations in an edge instance:
    Perform the following steps to deploy scene orchestrations to the edge instance.
    Notice Make sure that you have stopped the scene orchestrations that are running on the cloud.
    1. In the left-side navigation pane of the IoT Platform console, choose Link IoT Edge > Edge Instances, find the instance that you configured and click View to the right of the edge instance. For more information about configuring instance environments, see Set up environments.
    2. On the Instance Details page, select the Scenes tab and click Assign Scene.
    3. In Assign Scene dialog box, click Assign, and then click Close.Assign scene orchestrations to edge instances
    4. After assigning the scene orchestration, redeploy the edge instance.