uid: rules_tools:thing_status label: Thing Status Reporter description: Calls a user supplied script when a Thing changes it's status. configDescriptions: - name: script label: Rule to call description: Rule to call when one or more Things match the comparison. type: TEXT context: rule required: true triggers: - id: "3" label: A Thing Changes Status description: Triggers when any Thing changes status configuration: types: ThingStatusInfoChangedEvent payload: "" topic: openhab/things/** source: "" type: core.GenericEventTrigger conditions: [] actions: - inputs: {} id: "2" configuration: type: application/javascript script: | // Version 0.3 var {helpers} = require('openhab_rules_tools'); console.loggerName = 'org.openhab.automation.rules_tools.Thing Status'; //osgi.getService('org.apache.karaf.log.core.LogService').setLevel(console.loggerName, 'DEBUG'); helpers.validateLibraries('4.1.0', '2.0.1'); // Get the payload and the topic, the event Object might or might not be // wrapped in JS var parsed = (event.raw.get === undefined)? JSON.parse(event.payload) : event.payload; var topic = (event.topic !== undefined) ? event.topic : event.raw.get('event').getTopic().toString(); var data = {}; data['thingID'] = topic.split('/')[2]; data['thing'] = things.getThing(data['thingID']); data['oldStatus'] = parsed[1].status; data['oldDetail'] = parsed[1].statusDetail; data['newStatus'] = parsed[0].status; data['newDetail'] = parsed[0].statusDetail; rules.runRule("{{script}}", data, true); type: script.ScriptAction