trigger.template.create

The trigger.template.create command is used to create a new cloud trigger template.

TR50 Request


                        {
  "1": {
    "command": "trigger.template.create",
    "params": {
      "name": "My trigger template",
      "desc": "A sample trigger template",
      "group": "basic samples",
      "naturalDesc": "When the [[temperaturePropertyKey]] exceeds [[propertyValue]], change the [[temperatureAlarmKey]] state to [[temperatureAlarmState]]",
      "fields": [
        {
          "key": "temperaturePropertyKey",
          "desc": "The thing property key for a temperature",
          "type": "string"
        },
        {
          "key": "propertyValue",
          "desc": "The property value lower threshold",
          "type": "number"
        },
        {
          "key": "temperatureAlarmKey",
          "desc": "The thing alarm key for a temperature",
          "type": "string"
        },
        {
          "key": "temperatureAlarmState",
          "desc": "The alarm state",
          "type": "number"
        }
      ],
      "trigger": {
        "desc": "Too hot",
        "eventType": "property.change",
        "event": {
          "thingKey": "$(event.thing.key)",
          "propKey": "[[temperaturePropertyKey]]",
          "operator": "gt",
          "operand": [[propertyValue]]
        },
        "actions": {
          "0": {
            "type": "alarm.publish",
            "params": {
              "thingKey": "$(event.thing.key)",
              "alarmKey": "[[temperatureAlarmKey]]",
              "state": [[temperatureAlarmState]]
            },
            "canvas": {
              "left": "241.846",
              "top": "236.830",
              "success": "success-end0"
            },
            "routes": {
              "success": "$endSuccess",
              "failure": "$endFailure"
            }
          }
        },
        "firstAction": "0",
        "canvas": {
          "event": {
            "left": "50.000",
            "top": "50.000"
          },
          "success-end0": [
            {
              "left": "261.824",
              "top": "304.754"
            }
          ]
        }
      }
    }
  }
}
      

Request Parameters

Name

Type

Required

Description

name

String

Yes

The name of the trigger template.

desc

String

Yes

A description of the trigger template.

group

String

Yes

An arbitrary label used to group templates.

naturalDesc

String

Yes

A sentence (or set of sentences) that describe the trigger the template will generate, and how it's variables will be used.

fields

Array

 

An optional array containing a structure of variables used to customize a trigger based on the trigger template.

trigger

Array

Yes

The template used to create new triggers. For more information, see trigger.create.

sharedGlobal

Boolean

 

If this template should be globally available. Must have Super Ops permission to set this parameter.

Fields Parameters

Name

Type

Required

Description

key

String

Yes

The name of the variable used in the trigger template.

desc

String

 

A description of the contents of the variable.

type

String

Yes

The type of data the variable will contain.

options

Array

 

An array of possible options for the variable.

TR50 Response

If the command is sent successfully a success message and the id of the new trigger template is returned. Otherwise, an error and error message will be returned.


                        {
  "1": {
    "success": true,
    "params": {
      "id": "58b43ad4b2157c704f26005f"
    }
  }
}
      

Response Parameters

Name

Type

Description

id

String

The ID of the newly created trigger template.