Previous Topic

Next Topic

Book Contents

Book Index

Template JSON Examples

Defining a JSON Template Definition

The template below defines the 'operationName' and 'propertyName' variables and links them to the instruction inputs so the user of the template can configure them when creating a rule from this template. Refer to the Rule JSON Examples guide to see how the rule looks like.

{

      "uid":"OnOffTemplate",

      "label":"On-Off Template",

      "description":"This template performs toggle operation on Functional Item with uid 'toggledFiName' when the state of Functional Item with uid 'triggerFIName' is changed.",

      "variables":[

         {

            "id":"triggerFIName",

            "name":"Trigger FI name",

            "description":"The name of the FI that triggers the rule",

            "type":"GENERIC",

            "classes":["java.lang.String"],

            "context":"item.uid",

            "required":true

         },

         {

            "id":"toggledFiName",

            "name":"Toggled FI name",

            "description":"The name of the FI on which the operation will be performed",

            "type":"GENERIC",

            "classes":["java.lang.String"],

            "context":"item.uid",

            "required":true

        }

      ],

      "triggers":[

        {

            "id":"FIPropertyChangedTrigger",

            "type":"trigger.ItemPropertyChanged",

            "bindings":[

            {

              "id":"uid",

              "source":"triggerFIName",

              "type":"VARIABLE"

            },

            {

              "id":"propertyName",

              "source":"state",

              "type":"CONSTANT"

            }

          ]

        }

      ],

      "flow":[

         {

            "id":"FIOperationAction",

            "type":"action.ItemInvokeOperation",

            "bindings":[

            {

              "id":"uid",

              "source":"toggledFiName",

              "type":"VARIABLE"

            },

            {

              "id":"operationName",

              "source":"toggle",

              "type":"CONSTANT"

            }

          ]

        }

      ]

   }

Turn Off Heating Template Example

The example below is a JSON representation of a template created by the Turn Off Heating demo rule.

[

  {

    "uid": "template.turn.off.heating",

    "name": "Turn Off Heating Template",

    "description": "Turns off the heating every work day at the set time. There is a variable which represents the work days and another one used for setting the time of leaving.",

    "variables": [

      {

        "id": "hour",

        "type": "NUMERIC",

        "classes": [

          "java.util.Set",

          "java.lang.Integer"

        ],

        "required": true,

        "description": "The hour of leaving your home.",

        "min": 0,

        "max": 23,

        "step": 1

      },

      {

        "id": "workDays",

        "type": "ENUM",

        "classes": [

          "java.util.Set",

          "java.lang.String"

        ],

        "required": true,

        "description": "The work days of your week.",

        "options": [

          "Monday",

          "Tuesday",

          "Wednesday",

          "Thursday",

          "Friday",

          "Saturday",

          "Sunday"

        ]

      }

    ],

    "triggers": [

      {

        "id": "triggerDailyTimer",

        "handlerUID": "trigger.RepeatingTime",

        "description": "Triggers every work day at the set time.",

        "bindings": [

          {

            "id": "seconds",

            "type": "CONSTANT",

            "source": [

              0

            ]

          },

          {

            "id": "hours",

            "type": "VARIABLE",

            "source": "hour"

          },

          {

            "id": "minutes",

            "type": "CONSTANT",

            "source": [

              0

            ]

          },

          {

            "id": "daysOfWeek",

            "type": "VARIABLE",

            "source": "workDays"

          },

          {

            "id": "frequency",

            "type": "CONSTANT",

            "source": "daily"

          }

        ]

      }

    ],

    "flow": [

      {

        "id": "actionTurnOffHeating",

        "handlerUID": "action.ItemInvokeOperation",

        "description": "Turns off the heating.",

        "bindings": [

          {

            "id": "name",

            "type": "CONSTANT",

            "source": "Heating Switch"

          },

          {

            "id": "operationName",

            "type": "CONSTANT",

            "source": "off"

          }

        ]

      }

    ]

  }

]