Restart Expire [;]


On openHAB restart updates/commands the restored state/current state of Items with expire metadata back to the Item to kick off the Expire timers again (Expire doesn’t get reset with restoreOnStartup).

If the expire has ignoreStateUpdates set to true a command will be sent. Otherwise an update will be sent.

This rule template has one property. When “Use Expire State” is checked, instead of using the Item’s current state to update the Item the state configured in the “expire” metadata is used, essentially initializing the Item to the expire state.

When ignoreStateUpdates is set to true, this property does nothing and the Item’s current state is commanded to the Item. This is a deliberate decision because this rule template shouldn’t cause things to happen during startup.

Language: GraalVM JS Scripting



Version 1.0

  • Graduating to 1.0 status
  • added property to select whether to update the Item to it’s current state or to the configured expire state

Version 0.1

  • initial release


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.


1 Like

I have items that have relatively long expiration time (eg 5min or 30min), reflecting how long the measurement is “valid” for automation

Would it be possible for the rule to have configurable mode where it commands/updates the item with the “expiration state” instead?

Now it would take 5min for item to actually expire…

All things are possible. It shouldn’t be hard. I think I just need to add a boolean parameter and an if statement that pulls the state/command to send from the expire instead of the Item’s current state.

The new 1.0 version of the rule supports this feature request. I’ve done some limited testing and didn’t find any bugs. Let me know if something doesn’t work.

1 Like

I am still on OH 3.0 but this looks like it actually would work with the old version as well? openhab-js 4.7.0 can be used with OH3

If you can get the right openhab-js version working it should work. However notice that it also requires openhab-rules-tools, which uses openhab-js too so it should be fine as well.

Yeah, seems like it worked, I adapted to script a bit further to cover my needs. Thanks for sharing!

Of course due to the >4.0.0 version range listed in this topic it is not installable using UI…

I don’t remember if OH 3 had this option or not. But if you go to Settings → Community Marketplace there is an option to show unpublished entries. If enabled you should see every post in the marketplace, not just those with the published flag and versioning for your version of OH.

The usual warnings apply. An unpublished version or a version outside the ones listed may not work.