Hardware: 4vCPU (E5-2690v4)/ 6 GB of RAM / 35GB SAS Flash
OS: Debian Linux Buster SMP Debian 4.19.249-2 amd64
Java Runtime Environment: openjdk 11.0.16 x64
openHAB version: 3.3.0
Hello folks
Since some time I try myself on openHAB in interaction with HomeMatic IP. Now I have everything so far recorded and set up Android Push. This all works fine, but now I am quite confused and despite intensive search I have not found a suitable answer. How do I get the Label of the TriggerItem in a push message when I have created this under the Rules? I will get a push message like this “(label of triggering item) + hat alarm ausgelöst!”
Hi there - I had messed around with that in the past…Maybe there is a way to do it but I couldn’t figure it out…
So instead of using ‘Send a notitifcation’ within the rule, I just get the rule to ‘Execute a Script’ and selected ECMA2021… The script to send the triggering item is below (ignore the console.log line - I have that for diags).
//Script to send alerts to users when Alarm is set. Items to trigger alerts are selected via the rule config, and the "Alarm Set" constraint is also defined there too
if(this.event != undefined) {
//Stops script from running if triggered via OpenHAB console - Event would be undefined, and fail
console.log("Rule Alarm Notification triggered - Sending notification to OH Apps - Item triggered is",items.getItem(event.itemName).label);
actions.NotificationAction.sendBroadcastNotification(items.getItem(event.itemName).label + " opened while alarm set", "alarm", "HIGH")
;
}
Thanks for the fast replay. I tried but it fails anyway.
Log say’s:
2022-09-07 14:58:34.179 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '0359182ba6' failed: TypeError: Cannot read property "sendBroadcastNotification" from undefined in <eval> at line number 2
And my code look’s like this now:
configuration: {}
triggers:
- id: "1"
configuration:
itemName: UGTechnikraumWiredEingang_1_STATE
state: ON
previousState: OFF
type: core.ItemStateChangeTrigger
- id: "2"
configuration:
itemName: UGTechnikraumWiredEingang_2_STATE
state: ON
previousState: OFF
type: core.ItemStateChangeTrigger
- id: "3"
...
...
conditions:
- inputs: {}
id: "31"
configuration:
itemName: GATEWAYEXTRAS_Anwesenheit
state: OFF
operator: =
type: core.ItemStateCondition
actions:
- inputs: {}
id: "30"
configuration:
type: application/javascript
script: >-
//Script to send alerts to users when Alarm is set. Items to trigger alerts are selected via the rule config, and the "Alarm Set" constraint is also defined there too
if(this.event != undefined) {
//Stops script from running if triggered via OpenHAB console - Event would be undefined, and fail
actions.NotificationAction.sendBroadcastNotification(items.getItem(event.itemName).label + " opened while alarm set", "alarm", "HIGH") ;
}
type: script.ScriptAction