uid: rules_tools:presence_sim label: Persistence Presence Simulation description: Triggers periodically when a given Item is ON and plays back the states of Items stored in persistence. configDescriptions: - name: enableSim type: TEXT context: item filterCriteria: - name: type value: Switch label: Enable Simulation required: true description: When not ON, the simulation rule will run (e.g. when Presence is OFF presence simulation will run). - name: simItems type: TEXT context: item filterCriteria: - name: type value: Group label: Simulation Items Group required: true description: The Group whose members are to have their behaviors simulated. - name: days type: INTEGER label: Num Days required: false description: The number of days to look back for playback (recommend multiples of 7). defaultValue: 7 min: 0 - name: minutes type: INTEGER label: Minutes required: false description: How frequently to run the simulation rule in minutes. defaultValue: 5 min: 0 triggers: - id: "1" configuration: cronExpression: "0 0/{{minutes}} * * * ? *" type: timer.GenericCronTrigger conditions: - inputs: {} id: "2" configuration: itemName: "{{enableSim}}" state: "ON" operator: "!=" type: core.ItemStateCondition actions: - inputs: {} id: "3" configuration: type: application/javascript script: >- // Version 0.2 var {helpers} = require('openhab_rules_tools'); console.loggerName = 'org.openhab.automation.rules_tools.Presence Sim'; // osgi.getService('org.apache.karaf.log.core.LogService').setLevel(console.loggerName, 'DEBUG'); helpers.validateLibraries('4.1.0', '2.0.1'); items.{{simItems}}.members.forEach((i) => { const hState = i.history.historicState(time.toZDT().minusDays({{days}})); if(hState === undefined || hState === null) { console.warn(i.name + ' does not have a historic state for ' + '{{days}}' + ' days ago'); } else { console.debug('Commanding ' + i.name + ' to ' + hState.state); if(i.state != hState.state) { i.sendCommand(hState.state.toString()); } else { console.debug(i.name + ' is already ' + hState.state); } } }); type: script.ScriptAction