OH4.2.0 Notifications with Android App - ACTIONS

Hi All

I have been trying out the new openHAB 4,2 notifications enhancements with my setup.

I am running on openHAB4.2.0 with Android App version 3.15

I have been looking at the Actions enhancements - but am not sure if these are fully implemented in the App at this stage?
I managed to get the following to work:

*New TAG to create Notification Categories
*Title
*referenceID to overwrite a notification

I am however stuck on the ACTIONS (onClickAction).

I did get the command action to send a command to my item

actions.NotificationAction.sendBroadcastNotification('***Gate has Opened! ***','presence','MvGTest','Gate Action','refID','command:ShellyGarageDoorshelly1a4cf12f486ac10163199232_Power:ON','null','null','null','null');

However have had no luck with the ui:navigate: syntax.

This could well be an issue with my Syntax - though I have tried to follow the documentation and tried many options.

The syntax that I believe SHOULD work is:

actions.NotificationAction.sendBroadcastNotification('***Gate has Opened! ***','presence','MvGTest','Gate Action','refID','ui:navigate:/page/OverviewOLD:','null','null','null','null');

This opens up the APP to the default page (SiteMap) but does not navigate to my requested Main UI page, which I have confirmed to be correct.

I have also tried the https syntax. In this case the App doe snot even open:

actions.NotificationAction.sendBroadcastNotification('***Gate has Opened! ***','presence','MvGTest','Gate Action','refID','https://openhab.org','null','null','null','null');

Any advise / pointers would be appreciated?

Thanks
Mark

The following works for me:

actions.notificationBuilder('My Message 2')
.addUserId('mail@mymail.com')
.withReferenceId('refId111')
.withOnClickAction('command:AZ_Govee_Light_Strip_Power:ON')
.send();

I guess you are missing the “send()” at the end.

Thank you, however the following does work:

actions.NotificationAction.sendBroadcastNotification('***Gate has Opened! ***','presence','MvGTest','Gate Action','refID','command:ShellyGarageDoorshelly1a4cf12f486ac10163199232_Power:ON','null','null','null','null');

What I have a problem with is the ui and http/s actions.

I am testing using an inline script in blockly:

image

console.debug('Gate has Opened! ');
actions.NotificationAction.sendBroadcastNotification('***Gate has Opened! ***','presence','MvGTest','Gate Action','refID','command:ShellyGarageDoorshelly1a4cf12f486ac10163199232_Power:ON','null','null','null','null');

Hi Stefan,
I have tried the same code:

rules.JSRule({
    id: "Notification_Test",
    name: "Notification Test Rule",
    description: "Rule to test new Notifications",
    triggers: [],
    execute: (event) => {
        actions.notificationBuilder('My Message 2')
        .addUserId('mail@mymail.com')
        .withReferenceId('refId111')
        .withOnClickAction('command:AZ_Govee_Light_Strip_Power:ON')
        .send();
    },
    tags: ["Test", "Notification", "JSRule"],
  });

but I receive following error in the logs:

2024-07-17 14:59:44.459 [WARN ] [e.automation.internal.RuleEngineImpl] - Failed to execute action: 1(Error: Failed to execute rule Notification_Test: TypeError: (intermediate value).notificationBuilder is not a function: TypeError: (intermediate value).notificationBuilder is not a function

running: openHAB 4.2.0.M1

I think it is not included in M1…
New notifications have been added later…

The advanced notifications was only added in 4.2.0.M4

1 Like

My fault. thanks guys

but there is still something not working.
I’m on the 4.2.0 Release Version now.

e.g. the media is not working:

rules.JSRule({
    id: "Notification_Test",
    name: "Notification Test Rule",
    description: "Rule to test new Notifications",
    triggers: [],
    execute: (event) => {
        actions.notificationBuilder('Test')
        .withMediaAttachment('https://www.....png')
        .send();
    },
    tags: ["Test", "Notification", "JSRule"],
  });
2024-07-17 16:11:06.678 [WARN ] [e.automation.internal.RuleEngineImpl] - Failed to execute action: 1(Error: Failed to execute rule Notification_Test: TypeError: (intermediate value).notificationBuilder(...).withMediaAttachment is not a function: TypeError: (intermediate value).notificationBuilder(...).withMediaAttachment is not a function

Or If I add an action button it is not shown in the Android App. Is there a Android beta version needed or the latest version from the playstore?

rules.JSRule({
    id: "Notification_Test",
    name: "Notification Test Rule",
    description: "Rule to test new Notifications",
    triggers: [],
    execute: (event) => {
        actions.notificationBuilder('Test')
        .addActionButton('Turn on the light', 'command:Apartment_Light:ON')  
        .send();
    },
    tags: ["Test", "Notification", "JSRule"],
  });

the notificationBuilder itself is working now

You should read the release notes/blog posts, it describes the prerequisites.

You need the latest version of the Android App as well - I have some of the functionality working in 3.15.0 (not working for me is the ui and https actions).

The media url definitely is working on Android. While implementing the Blocklies I checked that and you can even see this in PR in the example.

1 Like

I could not refresh the app via play store. therefore I have downloaded the apk file from the repo. Now it is working with the manual installed version 3.15.2

I have now manually installed the 3.15.2 version but still not getting the following to work (via inline script in Blockly):

Opens APP to default SiteMap

actions.NotificationAction.sendBroadcastNotification('***Gate has Opened! ***','presence','MvGTest','Gate Action','refID','ui:navigate:/page/FloorPlanTest','null','null','null','null');

Doesn’t Even open APP:

actions.NotificationAction.sendBroadcastNotification('***Gate has Opened! ***','presence','MvGTest','Gate Action','refID','https://openhab.org','null','null','null','null');

Is it possible to address the message with the “notificationBuilder” for a specific user or adding the additional features to the “sendNotification(emailAddress, message, icon, tag)” function?

From what I understand from the docs there is sendNotification as well as sendBroadcastNotification and they seem to use identical syntax for the enhanced notifications.

EDIT: _ Other than the requirement for the emailAddress in the sendNotification version

I have updated Android App to 3.15.3-beta and now I can get the ui novation to work, so the following works as expected:

actions.NotificationAction.sendBroadcastNotification('***Gate has Opened! ***','presence','MvGTest','GateAction','refID','ui:navigate:/page/FloorPlanTest','null','null','null','null');

However still no luck with the ```https`` navigation:

actions.NotificationAction.sendBroadcastNotification('***Gate has Opened! ***','presence','MvGTest','Gate Action','refID','https://openhab.org','null','null','null','null');
2 Likes

But what is the purpose of the Notification builder then, if it is not possible to define the recipient?
It is much more convenient to define a notification with the builder, in stead of using a function with 10 parameters

Sorry, way above me :slight_smile: I will be using Blockly when that is complete, so to see the features I just used an inline script to test.

I don’t even know what the Notification builder is and how to access. Hopefully someone else will be of more help.

I also only use the Broadcast option at this stage (all come to me anyway).

I use Javascript and have created a function to send notifications with the notification builder. It works well and I don’t always have to pass all the parameters.
I have the function in my own library so that I can use it in all Javascript files.
There is certainly still room for improvement (other messengers like Signal and Telegram), but I am happy at the moment.

// *********** Function sendMessage for OH Notification
exports.sendMessage = function (message, recipient, mediaAttachmentUrl, icon, tag, title, referenceId, onClickAction, actionButton1, actionButton2, actionButton3) {

    recipient = recipient || null;
	icon = icon || null;
    tag = tag || null;
    title = title || null;
    referenceId = referenceId || null;
    onClickAction = onClickAction || null;
    mediaAttachmentUrl = mediaAttachmentUrl || null;
    actionButton1 = actionButton1 || null;
    actionButton2 = actionButton2 || null;
    actionButton3 = actionButton3 || null;

	notification = actions.notificationBuilder(message);
	if (icon !== null) { notification.withIcon(icon); }
	if (tag !== null) { notification.withTag(tag); }
	if (title !== null) { notification.withTitle(title); }
	if (onClickAction !== null) { notification.withOnClickAction(onClickAction); }
	if (mediaAttachmentUrl !== null) { notification.withMediaAttachmentUrl(mediaAttachmentUrl); }
	if (actionButton1 !== null) { notification.addActionButton(actionButton1.split("=")[0], actionButton1.split("=")[1]); }
	if (actionButton2 !== null) { notification.addActionButton(actionButton2.split("=")[0], actionButton2.split("=")[1]); }
	if (actionButton3 !== null) { notification.addActionButton(actionButton3.split("=")[0], actionButton3.split("=")[1]); }

	if (recipient !== null) {
		const emails = recipient.split(";");
		for (element of emails) { notification.addUserId(element); }
	}
	notification.send();

    return;
}

You can define a recipient and even multiple ones:

actions.notificationBuilder("foo")
	.addUserId("one_user")
	.addUserId("another_user")
    .send()