There are several ways to create a new Rule Template:
Define a Rule Template in a JSON file. The format of such JSON file is described with a JSON Scheme .
The JSON file can be provided packed into a bundle. The bundle simply can be a resource bundle, providing resource directory /src/main/resources/ESH-INF/automation/templates. The system has available Bundle Resource Template Provider that tracks such resources and injects them to the system.
Put the JSON file into the local file system in default automation directory /runtime/osgi/automation/templates. The system has available File Resource Template Provider that watches this directory and will load this file automatically.
Use Java API to create java objects. The created by Java API Rule Template objects can be injected to the system by:
Registering a Template Provider service to provide the created Templates. The Template Providers (org.eclipse.smarthome.automation.template.TemplateProvider) are designed to provide basic functionality that gives access to provided templates of the Template Registry. They can be used to:
Get localized template by using method getTemplate(String UID, Locale locale). When the localization is not specified or it is not supported a templates with default locale is returned.
Get all available localized templates by using method getTemplates(Locale locale). When the localization is not specified or it is not supported the templates with default locale are returned.
Using Template Registry (org.eclipse.smarthome.automation.template.TemplateRegistry) service, that provides add() method for this purpose.
Using Template Admin (com.prosyst.mbs.services.automation.items.RuleTemplateAdmin) service, that provides add() method for this purpose
Defining a JSON Rule Template Definition
The template below configures the 'operationName' and 'propertyName' properties and links the other required properties so the user of the template can configure them. It is available in the Automation ESH JSON Rules Demo and you can install it and see how it works.
[
{
"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.",
"configDescriptions":[
{
"name":"triggerFIName",
"label":"Trigger FI name",
"description":"The name of the FI that triggers the rule",
"type":"TEXT",
"context":"fi_uid",
"required":true
},
{
"name":"toggledFiName",
"label":"Toggled FI name",
"description":"The name of the FI on which the operation will be performed",