Skip to content

Commit 52d0a0e

Browse files
author
Ravi Nadahar
committed
more templates
1 parent c5e98bf commit 52d0a0e

1 file changed

Lines changed: 68 additions & 24 deletions

File tree

configuration/yaml/ruletemplates.md

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This page describes the `ruleTemplates` element for [YAML Configuration](./).
1111

1212
The `ruleTemplates` top-level key contains a map of rule templates, defined by their template UIDs.
1313
The main building blocks of rules are triggers, conditions and actions, collectively called modules.
14-
Rule templates lets you reuse the same definition in multiple rules, reducing duplication and improving maintainability, by using placeholders in the module configurations.
14+
Rule templates let you reuse the same definition in multiple rules, reducing duplication and improving maintainability, by using placeholders in the module configurations.
1515
When instantiating/generating a rule from a rule template, you define the values of the placeholders, which will then be substituted before the rule template becomes a rule.
1616
That way you can apply the same logic to several situations.
1717

@@ -100,30 +100,30 @@ ruleTemplates:
100100
A rule template uses placeholders in the module configurations.
101101
These placeholders must be substituted with actual values before a rule can be instantiated from a rule template.
102102
The `configDescriptions` section defines these placeholders as configuration description parameters.
103-
There must be one configuration description parameters per placeholder, and their names must match.
103+
There must be one configuration description parameter per placeholder, and their names must match.
104104
Otherwise, generating rules from the rule template will fail.
105105

106-
| Key | Required | Description |
107-
|:-----------------|:--------:|:-----------------------------------------------------------------------------------------------------------|
108-
| `label` | ☐ | The parameter label. |
109-
| `description` | ☐ | The parameter description. |
110-
| `type` | ☑ | The parameter type, One of `TEXT`, `INTEGER`, `DECIMAL` and `BOOLEAN`. |
111-
| `context` | ☐ | The parameter context, triggers special behavior in the UI like a lookup or syntax validation. |
112-
| `default` | ☐ | The default parameter value. |
113-
| `required` | | Whether the parameter is required. Defaults to `false`, but should be `true` for rule template parameters. |
114-
| `min` | ☐ | The minimum parameter value, applies to `INTEGER` parameters only. |
115-
| `max` | ☐ | The maximum parameter value, applies to `INTEGER` parameters only. |
116-
| `step` | ☐ | The parameter value step size, applies to `INTEGER` parameters only. |
117-
| `pattern` | ☐ | A regular expression used for validation, applies to `TEXT` parameters only. |
118-
| `readOnly` | ☐ | Makes the parameter read-only. Defaults to `false`. |
119-
| `advanced` | ☐ | Makes the parameter hidden unless advanced parameters are shown. Defaults to `false`. |
120-
| `unit` | ☐ | The parameter value unit. |
121-
| `unitLabel` | ☐ | The parameter value unit label. |
122-
| `options` | ☐ | A list of predefined parameter values. Each option have a `value` and an optional `label`. |
123-
| `multiple` | ☐ | Allows selecting more than one option if `options` are defined. Defaults to `false`. |
124-
| `multipleLimit` | ☐ | Defines the maximum number of selectable options, if `options` are defined and `multiple` is `true`. |
125-
| `limitToOptions` | ☐ | Allows custom values in addition to the predefined `options` if `false`. Defaults to `true`. |
126-
| `filterCriteria` | ☐ | Can be used in combination with certain `context`s to filter e.g. `Item`s that are shown in the lookup. |
106+
| Key | Required | Description |
107+
|:-----------------|:--------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
108+
| `label` | ☐ | The parameter label. |
109+
| `description` | ☐ | The parameter description. |
110+
| `type` | ☑ | The parameter type, One of `TEXT`, `INTEGER`, `DECIMAL` and `BOOLEAN`. |
111+
| `context` | ☐ | The parameter context, triggers special behavior in the UI like a lookup or syntax validation. See [Supported Contexts](../../developers/addons/config-xml.md#supported-contexts) for details. |
112+
| `filterCriteria` | ☐ | Can be used in combination with certain `context`s to filter e.g. `Item`s that are shown in the lookup. See [Supported Contexts](../../developers/addons/config-xml.md#supported-contexts) for details. |
113+
| `default` | | The default parameter value. |
114+
| `required` | | Whether the parameter is required. Defaults to `false`, but should be `true` for rule template parameters. |
115+
| `min` | ☐ | The minimum parameter value, applies to `INTEGER` parameters only. |
116+
| `max` | ☐ | The maximum parameter value, applies to `INTEGER` parameters only. |
117+
| `step` | ☐ | The parameter value step size, applies to `INTEGER` parameters only. |
118+
| `pattern` | ☐ | A regular expression used for validation, applies to `TEXT` parameters only. |
119+
| `readOnly` | ☐ | Makes the parameter read-only. Defaults to `false`. |
120+
| `advanced` | ☐ | Makes the parameter hidden unless advanced parameters are shown. Defaults to `false`. |
121+
| `unit` | ☐ | The parameter value unit. |
122+
| `unitLabel` | ☐ | The parameter value unit label. |
123+
| `options` | ☐ | A list of predefined parameter values. Each option have a `value` and an optional `label`. |
124+
| `multiple` | ☐ | Allows selecting more than one option if `options` are defined. Defaults to `false`. |
125+
| `multipleLimit` | ☐ | Defines the maximum number of selectable options, if `options` are defined and `multiple` is `true`. |
126+
| `limitToOptions` | ☐ | Allows custom values in addition to the predefined `options` if `false`. Defaults to `true`. |
127127

128128
### Modules Sections
129129

@@ -135,7 +135,7 @@ The only difference is that the `config` sections can contain placeholders of th
135135
```yaml
136136
version: 1
137137
138-
rules:
138+
ruleTemplates:
139139
lights-on:
140140
label: "Turn on light at sunset"
141141
description: "This rule turns on the living room light when the sun sets."
@@ -195,4 +195,48 @@ rules:
195195
sink: enhancedjavasound
196196
text: Welcome
197197
type: Say
198+
light_control_template:
199+
label: Light Control Template
200+
description: A template for controlling lights based on time.
201+
configDescriptions:
202+
room_name:
203+
type: TEXT
204+
required: true
205+
label: Room Name
206+
description: The name of the room where the light is located.
207+
start_time:
208+
type: TEXT
209+
required: true
210+
pattern: '^([01]\\d|2[0-3]):?([0-5]\\d)$'
211+
label: Start Time
212+
description: The time to turn on the light (HH:mm).
213+
end_time:
214+
type: TEXT
215+
required: true
216+
pattern: '^([01]\\d|2[0-3]):?([0-5]\\d)$'
217+
label: End Time
218+
description: The time to turn off the light (HH:mm).
219+
triggers:
220+
- id: time_trigger
221+
type: timer.GenericCronTrigger
222+
config:
223+
cronExpression: "0 0/1 * 1/1 * ? *" # Every minute
224+
conditions:
225+
- id: time_condition
226+
type: core.TimeOfDayCondition
227+
config:
228+
start: "{{start_time}}"
229+
end: "{{end_time}}"
230+
actions:
231+
- id: light_action
232+
type: script.JSAction
233+
config:
234+
script: |
235+
var room = items.getItem("g{{room_name}}");
236+
if (now().isAfter(now().withTimeAtStartOfDay().plusHours(parseInt(config.start.split(':')[0])).plusMinutes(parseInt(config.start.split(':')[1]))) &&
237+
now().isBefore(now().withTimeAtStartOfDay().plusHours(parseInt(config.end.split(':')[0])).plusMinutes(parseInt(config.end.split(':')[1])))) {
238+
room.members.forEach(function(item) { item.sendCommand(ON); });
239+
} else {
240+
room.members.forEach(function(item) { item.sendCommand(OFF); });
241+
}
198242
```

0 commit comments

Comments
 (0)