You can achieve that by being creative with the next-gen rule engine (NGRE) and the core.GenericEventTrigger module type and listen to a certain type of event, here ThingStatusInfoChangedEvent.
Unfortunately the trick is, this module type is “internal” so you can’t see it in Paper UI.
But you can use the Karaf console to add the rule anyway.
- Create a file somewhere on your filesystem, for instance
/tmp/thingstatus.json
with this content:
[
{
"uid": "thingStatusChanged",
"name": "React to thing status changes",
"description": "",
"visibility": "VISIBLE",
"enabled": true,
"triggers": [
{
"id": 1,
"label": "When an ThingStatusInfoChangedEvent is received on a thing",
"configuration": {
"eventTopic": "smarthome/*",
"eventSource": "",
"eventTypes": "ThingStatusInfoChangedEvent"
},
"type": "core.GenericEventTrigger"
}
],
"conditions": [],
"actions": [
{
"id": 2,
"label": "execute a given script",
"inputs": {},
"configuration": {
"type": "application/javascript",
"script": "print(event.topic.split('/')[2]); print(JSON.stringify(event.payload)); print(event.toString());"
},
"type": "script.ScriptAction"
}
]
}
]
- From the Karaf console, run:
smarthome:automation importRules /tmp/thingstatus.json
(replace the file path accordingly) - You should now see the rule in Paper UI - though you can’t configure the trigger with the UI - and in this example every status change on (any) Thing will result in three lines printed on your log - the thing ID, the payload, and a human-readable message.
- If this works (you can try it by disabling/renabling a thing), since there is no way afaik to call actions like Telegram, you’ll have to use an item to pass the message - replace the
"script"
value in the action by"events.postUpdate('LastThingStatusUpdate', event.toString());"
You can change it in the file and callsmarthome:automation importRules
again.
Then you can react on a change to the LastThingStatusUpdate item with a regular rule.