WARNING: Users who have this template already installed for versions of OH 5.1 and before, after removing the old template and installing this new one, open your rule(s), click on the code tab, and change the ruleTemplate property to ohrt-expireUpdater before regenerating the rule.
There are circumstances where one might want to modify the Expire timeout duration from a rule. For example, maybe a light should stay on longer on weekends or when no one is home.
This rule template will create a Script type rule. It does not have any triggers of it’s own. It is intended to be called from another rule, passing the Item and the duration string as arguments.
| parameter | expected value |
|---|---|
item |
The Item Object or name of the Item to update the metadata |
newDuration |
A duration string supported by the expire binding. Note, Expire will accept just defining the parts of the duration you are using (e.g. 5s) but that confuses MainUI so always include all three fields (e.g.0h0m5s). Using capital letters also confuses MainUI. In both cases they are treated as an error by the rule. |
If newDuration is null or not passed, the rule will remove the expire metadata from the Item . Only the duration time is changed. All other parts of the expire metadata remains unchanged.
If the Item does not have expire metadata, it will be added.
Only the old Expire duration format is supported. ISO8601 formatttted durations are not supported.
An example in JS for calling the rule.
rules.runRule('dynamic_expire',
{item:'TestSwitch', newDuration:'0h2m3s'},
true);
Watch the logs for errors.
This rule template requires the openhab_rules_tools library to be installed. See openHAB Rules Tools Announcements for details. You can install it from openhabian-config and there is a rule template which may work for you to install it. See the announcements for all the ways to install this library.
Language: JavaScript
Dependencies:
- openhab-js 5.18.2+
- openhab_rules_tools 2.1.0+
Changelog
Version 1.0
- migrated to the YAML file format for OH 5.2
- use the wrapper
- standardize logger names
Version 0.2
- throws an exception if the openhab-js or openhab_rules_tools are not the right verisons
Version 0.1
- initial release
Sponsorship
If you want to send a tip my way or sponsor my work you can through Sponsor @rkoshak on GitHub or PayPal. It won’t change what I contribute to OH but it might keep me in coffee or let me buy hardware to test out new things.
