uid: rules_tools:restartExpire label: Restart Expire description: On OH boot updates or commands Items with Expire metadata to restart the timers. configDescriptions: - name: expireState label: Use Expire State description: When checked the expire state is used to update/command the Item instead of the Item's current state. If checked and there is no state defined in the expire metadata UNDEF is used. type: BOOLEAN required: false defaultValue: false triggers: - id: "1" configuration: startlevel: 50 type: core.SystemStartlevelTrigger conditions: [] actions: - inputs: {} id: "2" configuration: type: application/javascript script: > // Version 1.0 var {helpers} = require('openhab_rules_tools'); console.loggerName = 'org.openhab.automation.rules_tools.Restart Expire.'+ruleUID; //osgi.getService('org.apache.karaf.log.core.LogService').setLevel(console.loggerName, 'DEBUG'); var useExpireState = {{expireState}}; helpers.validateLibraries('4.1.0', '2.0.1'); console.info('Restarting Expire timers'); var expireItems = items.getItems().filter(i => i.getMetadata('expire') !== null).forEach( i => { if(i.getMetadata('expire').configuration['ignoreStateUpdates'] == 'true' && !i.isUninitialized) { console.debug('Commanding Item ' + i.name + ' to ' + i.state); i.sendCommand(i.state); } else { const mdValue = i.getMetadata('expire').value.split(','); const expireState = (mdValue.length == 2) ? mdValue[1].replace('command=', '') : 'UNDEF'; const state = (useExpireState) ? expireState : i.state; console.debug('Updating Item ' + i.name + ' to ' + state + ' with use Expire State ' + useExpireState); i.postUpdate(state); } }); type: script.ScriptAction