The rules top-level key contains a map of rules, defined by their rule UIDs.
The main building blocks of rules are triggers, conditions and actions, collectively called modules.
rules:<rule_uid>:template: <rule_template_uid># Optional - only used when the rule is based on a rule templatelabel: <rule_label># Requireddescription: <rule_description># Optionaltags:# Optional- <tag_name>visibility: <VISIBLE|HIDDEN|EXPERT># Optional - defaults to VISIBLEconfig:# Optional - used when the rule is based on a rule template<config_key>: <config_value>triggers:-id: <trigger_id># Optional - module IDs are autogenerated if not specifiedlabel: <trigger_label># Optional description: <trigger_description># Optionaltype: StartLevel # Must be a valid trigger typeconfig:startlevel:80# Required properties depend on the trigger typeconditions:-id: <condition_id># Optional - module IDs are autogenerated if not specifiedlabel: <condition_label># Optionaldescription: <condition_description># Optionaltype: TimeOfDay # Must be a valid condition typeconfig:startTime:08:00# Required properties depend on the condition typeendTime:16:00actions:-id: <action_id># Optional - module IDs are autogenerated if not specifiedlabel: <action_label># Optionaldescription: <action_description># Optionaltype: Script # Must be a valid action typeconfig:type: Ruby # Required properties depend on the action typescript:|
puts "Hello world"
Key
Required
Description
<rule_uid>
☑
The UID of the rule being defined. The UID can be anything as long as it doesn't start or end with whitespace, and doesn't contain / or \.
template
☐
Contains the UID of the rule template if the rule is linked to one. This field is only relevant for template-based rules.
label
☑
The rule name/label.
description
☐
The rule description.
tags
☐
A list of tags to associate with the rule.
visibility
☐
Determines if the rule will be displayed in the UI. Rarely used, defaults to VISIBLE.
config
☐
A key-value map of the rule's configuration. Used with rule templates to specify the values of placeholders.
triggers
☐
Specify rule triggers. Triggers define when the rule should be executed.
conditions
☐
Specify rule conditions. Conditions control whether a rule should execute based on specific criteria.
actions
☐
Specify rule actions. Actions define what happens when a rule is triggered and its conditions are met.
The trigger ID. It must be unique within the rule, across triggers, conditions and actions (modules). Will be generated if not specified.
label
☐
The trigger label.
description
☐
The trigger description.
type
☑
The trigger type, which must be a valid/existing trigger type. This is what decides how the trigger works, what mechanism is in use, and which configuration properties must be present.
config
▧
A key-value map of the trigger's configuration. See the trigger type documentation for which keys exist, are mandatory, and what their values should be.
openHAB can be extended in various ways, so other trigger types than those listed here can be valid in a particular installation.
Here is a list of standard trigger types that exist in any installation.
The standard trigger types have been given simplified aliases for convenience, but can also be used with their "full ID".
The condition ID. It must be unique within the rule, across triggers, conditions and actions (modules). Will be generated if not specified.
label
☐
The condition label.
description
☐
The condition description.
type
☑
The condition type, which must be a valid/existing condition type. This is what decides how the condition works, what mechanism is in use, and which configuration properties must be present.
config
▧
A key-value map of the condition's configuration. See the condition type documentation for which keys exist, are mandatory, and what their values should be.
inputs
☐
Advanced: A key-value map for controlling mapping of inputs from other modules. Inputs are automatically mapped if not mapped explicitly.
openHAB can be extended in various ways, so other condition types than those listed here can be valid in a particular installation.
Here is a list of standard condition types that exist in any installation.
The standard condition types have been given simplified aliases for convenience, but can also be used with their "full ID".
The action ID. It must be unique within the rule, across triggers, conditions and actions (modules). Will be generated if not specified.
label
☐
The action label.
description
☐
The action description.
type
☑
The action type, which must be a valid/existing action type. This is what decides how the action works, what mechanism is in use, and which configuration properties must be present.
config
▧
A key-value map of the action's configuration. See the action type documentation for which keys exist, are mandatory, and what their values should be.
inputs
☐
Advanced: A key-value map for controlling mapping of inputs from other modules. Inputs are automatically mapped if not mapped explicitly.
openHAB can be extended in various ways, so other action types than those listed here can be valid in a particular installation.
Here is a list of standard action types that exist in any installation.
The standard action types have been given simplified aliases for convenience, but can also be used with their "full ID".
For scripted conditions and actions, there's an additional type parameter that must be specified under config, to identify the scripting language to use.
The identifiers are based on MIME-types(opens new window), but don't really adhere to any standard.
It's up to each scripting add-on to pick a code, and the resulting codes reflect that.
To make these easier to use and remember, the type field in a scripting module's config section supports aliases for the most commonly used type.
Either the alias or the full type code will work.
Other scripting languages can be specified, but the full type code must be used.
version:1rules:lights-on:label:"Turn on light at sunset"description:"This rule turns on the living room light when the sun sets."triggers:-type: ChannelEvent
label: Sunset
config:event: START
channelUID: astro:sun:local:set#eventactions:-type: SendCommand
config:item: LivingRoomLight
command: ON
welcome-rule:label: Welcome Rule
description: Welcomes daytime visitors if the house is heated.
tags:- Welcome
- Daytime
triggers:-id: startlevel
label: Start Level Trigger
description: This trigger triggers at start level 80.
type: StartLevel
config:startlevel:80-label: Regular Trigger
description: Triggers at every 30 minutes starting at minute :15, every hour between 08 and 20, of every day.
type: Cron
config:cronExpression: 0 15/30 8-20 ? * * *
conditions:-id: weekday
type: Weekday
-type: TimeOfDay
label: Daytime
config:startTime:08:00endTime:20:00-type: ItemState
label: Heating Power Sufficient
config:itemName: CurrentPower
operator:">"state:"50"actions:-label: Print
description: Gives a warm welcome.
config:type: Ruby
script:|
puts "Hello and welcome to a heated house"type: Script
-config:volume:80sink: enhancedjavasound
text: Welcome
type: Say