-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from rkoshak/ruleDelay
Added rule start delay template
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Delay Start | ||
Initially triggers at system runlevel 40 and disables a user selected list of rules. | ||
Triggers again at system runlevel 100 plus a user configurable delay to reenable the rules. | ||
See the [Marketplace posting](https://community.openhab.org/t/delay-start-4-0-0-0-4-1-0-0/144884) for full details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
uid: rules_tools:delay_start | ||
label: Delay Start | ||
description: Triggers at system runlevel 40 and disables a set of rules. Then triggers at a user selected system runlevel and reenables those rules. | ||
configDescriptions: | ||
- name: rules | ||
label: Rules | ||
description: Rules to disable during startup. | ||
type: TEXT | ||
context: rule | ||
required: true | ||
multiple: true | ||
- name: pause | ||
label: Reenable Delay | ||
description: How long after the second trigger to wait before reenabling the rules, ISO8601 duration format. Defaults to reenable them immediately. | ||
type: TEXT | ||
defaultValue: '' | ||
required: false | ||
triggers: | ||
- id: "1" | ||
configuration: | ||
startlevel: 40 | ||
type: core.SystemStartlevelTrigger | ||
- id: "2" | ||
configuration: | ||
startlevel: 100 | ||
type: core.SystemStartlevelTrigger | ||
conditions: [] | ||
actions: | ||
- inputs: {} | ||
id: "3" | ||
configuration: | ||
type: application/javascript | ||
script: >- | ||
var {helpers} = require('openhab_rules_tools'); | ||
console.loggerName = 'org.openhab.automation.rules_tools.Delayed Start'; | ||
helpers.validateLibraries('4.1.0', '2.0.1'); | ||
// Properties | ||
var disabledRules = '{{rules}}'.replace('[','').replace(']', '').split(', '); | ||
var delay = '{{pause}}'; | ||
// First time the rule is called at runlevel 40 the flag will be initialized to false | ||
var alreadyCalled = cache.private.get('flag', () => false); | ||
var timerTime = (alreadyCalled) ? delay : 0; // run immediately the first run of the rule | ||
var activity = (alreadyCalled) ? 'enabling' : 'disabling'; | ||
var when = (alreadyCalled) ? 'after ' + delay : 'immediately'; | ||
console.info('Delayed Start triggered, ' + activity + ' rules ' + when); | ||
helpers.createTimer(timerTime, () => disabledRules.forEach(rule => { | ||
console.info(activity, rule); | ||
try { | ||
rules.setEnabled(rule, alreadyCalled); | ||
} | ||
catch(e) { | ||
console.error('Failed to disable rule ' + rule + ': ' + e); | ||
} | ||
}), 'delayedStart'); | ||
cache.private.put('flag', true); | ||
type: script.ScriptAction |