Expire Updater [4.0.0.0;4.1.0.0)

image

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.

An example in JS Scripting 11 for calling the rule.

rules.runRule('dynamic_expire', 
              {item:'TestSwitch', newDuration:'0h2m3s'}, 
              true);

Watch the logs for errors.

Language: JS Scripting 11

Dependencies:

  • openhab-js 4.1.0+
  • openhab_rules_tools 2.0.1+

Changelog

Version 0.2

  • throws an exception if the openhab-js or openhab_rules_tools are not the right verisons

Version 0.1

  • initial release

Resources

https://raw.githubusercontent.com/rkoshak/openhab-rules-tools/main/rule-templates/expire_updater/expire_updater.yaml

1 Like

FYI - Looks like you have an extra [ in the version range in the title.

I’m curious about this line. If the metadata doesn’t exist, the rule just puts the duration into the new value. But, is expire metadata valid without the command or state update portion? What happens when the expiration is triggered and there’s no command or state update to send?

I did have an error on the line above that one that I just fixed (a ternary operation doesn’t start with “if”).

OK, the version above works, at least in the main case. There’s lots of error case testing that needs to be done but it should be mostly functional now.

Yes, it will default to updating the Item to UNDEF when those are not present in the metadata.

I did not know that. Interesting.

Yeah, the if disappeared as I was highlighting it to add that to my comment. It was a neat trick. :hushed:

Sorry, I meant the version range in the topic title. Extra [ in [[4.0.0.0;4.1.0.0).