Skip to content

Commit

Permalink
Merge pull request #77 from rkoshak/thingStatus_rewrite
Browse files Browse the repository at this point in the history
Added rewrite of Thing status reporting which uses a GenericEventTrigger instead of polling.
  • Loading branch information
rkoshak authored Feb 7, 2023
2 parents ee75111 + 4984da6 commit 6e85c8c
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions rule-templates/thingStatus/thing_status2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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: "1"
label: GenericEventTrigger
description: GenericEventTrigger with filter
configuration:
eventSource: ""
eventTopic: openhab/things/*
eventTypes: ThingStatusInfoChangedEvent
type: core.GenericEventTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/javascript
script: |
console.loggerName = 'org.openhab.automation.rules_tools.Thing Status';
console.debug('ThingStatusInfoChangedEvent:' + event.toString());
var parsed = JSON.parse(event.payload);
var data = {};
data['thingID'] = event.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

0 comments on commit 6e85c8c

Please sign in to comment.