Text and Item Label in the push message

  • Platform information: VM
    • 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!”

The code looks like this:

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:
      icon: siren.map
      severity: ALARM
      message: '<triggeringItem.label> + Fenster hat alarm ausgelöst'
    type: notification.SendExtendedBroadcastNotification

message: ‘<triggeringItem.label> + Fenster hat alarm ausgelöst’

I can’t find any helpful information how it works here.

Thank you all for your effort.

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")
  ;
}

Hope that helps…

1 Like

Thanks for the fast replay. I tried but it fails anyway. :frowning:

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

Any idea what I do wrong again?

Thank you

Do you have the openHAB Cloud Connector add-on installed and have you set up a myopenhab.org account linked to your OH instance?

Also, pay attention to the details of what @glen_m said.

The bolding is mine.

You’ve selected ECMAScript 5.1. If you don’t have a ECMAScript 2021 option, you need to install the JS Scripting automation add-on.

1 Like

Oh… Thank you both!

I missed JS Scripting automation add-on!!!

Now the push message works as expected and yes over the openhab cloud.