Formatting (Android) Notification in Function

Like the title says, I am trying to pre-format a notification using a function node in Node-RED, but formatting it based upon what variables I have declared.
For this situation, possible messages are:

  • msg.title (will always be declared)
  • msg.message (will always be declared)
  • msg.image
  • msg. actionable_data_title_1
  • msg.actionable_data_title_2

This is the code I currently have, that tries to paste values in there, whether I declare them or not. It works, it just adds some whitespace in the notification if the other 3 msg.whatever are not declared:

{
    "title": "{{title}}",
    "message": "{{message}}",
    "data": {
        "image": "{{image}}",
        "actions": [
            {
                "action": "{{actionable_data_action_1}}",
                "title": "{{actionable_data_title_1}}"
            },
            {
                "action": "{{actionable_data_action_2}}",
                "title": "{{actionable_data_title_2}}"
            }
        ]
    }
}

So I thought to use a function node to look through all of the messages to see what has and hasnt been declared.

My first thought is to make an empty array, and then check to see what msg.whatever have been declared, and add them to the array, and then format the notification based on the items in the array. This works, however, I cannot figure out how to pass it onto the ‘call service’ node ‘data’ field.

elements = []

if (msg.image != null){
    elements.push(msg.image)
}
else if (msg.actionable_data_title_1 != null){
    elements.push(msg.actionable_data_title_1, msg.actionable_data_action_1)
}
else if (msg.actionable_data_title_2 != null){
    elements.push(msg.actionable_data_title_2, msg.actionable_data_action_2);
}
//check to see if elements contains msg.image AND msg.actionable_data_title_1
if (elements.includes(msg.image) && elements.includes(msg.actionable_data_title_1)){
   msg.notification = "{\"title\":\"{{title}}\",\"message\":\"{{message}}\",\"data\":{\"image\":\"{{image}}\",\"actions\":[{\"action\":\"{{actionable_data_action_1}}\",\"title\":\"{{actionable_data_title_1}}\"},{\"action\":\"{{actionable_data_action_2}}\",\"title\":\"{{actionable_data_title_2}}\"}]}}"
}
//check to see if elements contains msg.whatever but DOES NOT contain msg.image
else if (!elements.includes(msg.image) && elements.includes(msg.actionable_data_title_1)){
   msg.notification = "{\"title\":\"{{title}}\",\"message\":\"{{message}}\",\"data\":{\"actions\":[{\"action\":\"{{actionable_data_action_1}}\",\"title\":\"{{actionable_data_title_1}}\"},{\"action\":\"{{actionable_data_action_2}}\",\"title\":\"{{actionable_data_title_2}}\"}]}}"
}
if (elements.includes(msg.image) && !elements.includes(msg.actionable_data_title_1)){
   msg.notification = "{\"title\":\"{{title}}\",\"message\":\"{{message}}\",\"data\":{\"image\":\"{{image}}\"}}"
}
else {
    msg.notification = "{\"title\": \"{{title}}\",\"message\": \"{{message}}\"}";
}

return msg;

If I enter {{notification}} into the data field, it gives me an API error. If I enter {}, I just get blank notifications. If I enter {“message”:"{{notification}}"}, I just get blank notifications.

Here is the flow

[{"id":"8158ab0b731cfa04","type":"inject","z":"9003fcc3.08f48","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":955,"y":280,"wires":[["8a8b1a3d6d5ff2f5"]],"l":false},{"id":"4d64f59ce4eaf3d1","type":"inject","z":"9003fcc3.08f48","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":955,"y":320,"wires":[["1f72036f5402d9f8"]],"l":false},{"id":"4d84c50e9eeb2cca","type":"inject","z":"9003fcc3.08f48","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":955,"y":360,"wires":[["c6a6cfe3c25c81c8"]],"l":false},{"id":"c6a6cfe3c25c81c8","type":"change","z":"9003fcc3.08f48","name":"Set Notification msg","rules":[{"t":"set","p":"title","pt":"msg","to":"Actionable With Image","tot":"str"},{"t":"set","p":"message","pt":"msg","to":"This is a test","tot":"str"},{"t":"set","p":"actionable_data_title_1","pt":"msg","to":"Test 1!","tot":"str"},{"t":"set","p":"actionable_data_action_1","pt":"msg","to":"restart_coffee_timer","tot":"str"},{"t":"set","p":"actionable_data_title_2","pt":"msg","to":"Test 2!","tot":"str"},{"t":"set","p":"actionable_data_action_2","pt":"msg","to":"dont_restart_coffee_timer","tot":"str"},{"t":"set","p":"image","pt":"msg","to":"/media/local/abstract.jpg","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1015,"y":360,"wires":[["3d677e1e9a53d4cf"]],"l":false,"info":"Changes the person entity to a simple name\n\nexample: person.joe -> Joe"},{"id":"1f72036f5402d9f8","type":"change","z":"9003fcc3.08f48","name":"Set Notification msg","rules":[{"t":"set","p":"title","pt":"msg","to":"Just Image","tot":"str"},{"t":"set","p":"message","pt":"msg","to":"This is a test","tot":"str"},{"t":"set","p":"image","pt":"msg","to":"/media/local/abstract.jpg","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1015,"y":320,"wires":[["3d677e1e9a53d4cf"]],"l":false,"info":"Changes the person entity to a simple name\n\nexample: person.joe -> Joe"},{"id":"8a8b1a3d6d5ff2f5","type":"change","z":"9003fcc3.08f48","name":"Set Notification msg","rules":[{"t":"set","p":"title","pt":"msg","to":"Actionable No Image","tot":"str"},{"t":"set","p":"message","pt":"msg","to":"This is a test","tot":"str"},{"t":"set","p":"actionable_data_title_1","pt":"msg","to":"Test 1!","tot":"str"},{"t":"set","p":"actionable_data_action_1","pt":"msg","to":"restart_coffee_timer","tot":"str"},{"t":"set","p":"actionable_data_title_2","pt":"msg","to":"Test 2!","tot":"str"},{"t":"set","p":"actionable_data_action_2","pt":"msg","to":"dont_restart_coffee_timer","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1015,"y":280,"wires":[["3d677e1e9a53d4cf"]],"l":false,"info":"Changes the person entity to a simple name\n\nexample: person.joe -> Joe"},{"id":"3d677e1e9a53d4cf","type":"function","z":"9003fcc3.08f48","name":"Check Speaker Selection","func":"elements = []\n\nif (msg.image != null){\n    elements.push(msg.image)\n}\nelse if (msg.actionable_data_title_1 != null){\n    elements.push(msg.actionable_data_title_1, msg.actionable_data_action_1)\n}\nelse if (msg.actionable_data_title_2 != null){\n    elements.push(msg.actionable_data_title_2, msg.actionable_data_action_2);\n}\n//check to see if elements contains msg.image AND msg.actionable_data_title_1\nif (elements.includes(msg.image) && elements.includes(msg.actionable_data_title_1)){\n   msg.notification = \"{\\\"title\\\":\\\"{{title}}\\\",\\\"message\\\":\\\"{{message}}\\\",\\\"data\\\":{\\\"image\\\":\\\"{{image}}\\\",\\\"actions\\\":[{\\\"action\\\":\\\"{{actionable_data_action_1}}\\\",\\\"title\\\":\\\"{{actionable_data_title_1}}\\\"},{\\\"action\\\":\\\"{{actionable_data_action_2}}\\\",\\\"title\\\":\\\"{{actionable_data_title_2}}\\\"}]}}\"\n}\n//check to see if elements contains msg.whatever but DOES NOT contain msg.image\nelse if (!elements.includes(msg.image) && elements.includes(msg.actionable_data_title_1)){\n   msg.notification = \"{\\\"title\\\":\\\"{{title}}\\\",\\\"message\\\":\\\"{{message}}\\\",\\\"data\\\":{\\\"actions\\\":[{\\\"action\\\":\\\"{{actionable_data_action_1}}\\\",\\\"title\\\":\\\"{{actionable_data_title_1}}\\\"},{\\\"action\\\":\\\"{{actionable_data_action_2}}\\\",\\\"title\\\":\\\"{{actionable_data_title_2}}\\\"}]}}\"\n}\nif (elements.includes(msg.image) && !elements.includes(msg.actionable_data_title_1)){\n   msg.notification = \"{\\\"title\\\":\\\"{{title}}\\\",\\\"message\\\":\\\"{{message}}\\\",\\\"data\\\":{\\\"image\\\":\\\"{{image}}\\\"}}\"\n}\nelse {\n    msg.notification = \"{\\\"title\\\": \\\"{{title}}\\\",\\\"message\\\": \\\"{{message}}\\\"}\";\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1095,"y":320,"wires":[["b9ef32fc182a4942"]],"l":false},{"id":"b9ef32fc182a4942","type":"api-call-service","z":"9003fcc3.08f48","name":"Send Notification","server":"","version":3,"debugenabled":true,"service_domain":"notify","service":"","entityId":"","data":"{\"message\":\"{{notification}}\"}","dataType":"jsonata","mergecontext":"","mustacheAltTags":true,"outputProperties":[],"queue":"none","x":1230,"y":320,"wires":[[]]}]

Change the data type to json from j expression

Tried that and still no bueno

Perhaps using the J expression format for messages would be better for this application. Instead of {{ }} use " & data.attributes.friendly_name & "

{ "message": "The " & data.attributes.friendly_name & " has been opened." }

That format won’t work for me unfortunately. I declare a whole bunch of variable through the flow and call them in the notification node.

I can’t find any examples using /, if I structure the message like this, it passes the varibles through your example.

if (elements.includes(msg.image) && !elements.includes(msg.actionable_data_title_1)){
   msg.notification = {
    title: msg.title,
    message: msg.message,
    data:{
        image: msg.image},
    }
}
[{"id":"3d677e1e9a53d4cf","type":"function","z":"f80b6c338afd5483","name":"Check Speaker Selection","func":"elements = []\n\nif (msg.image != null){\n    elements.push(msg.image)\n}\nelse if (msg.actionable_data_title_1 != null){\n    elements.push(msg.actionable_data_title_1, msg.actionable_data_action_1)\n}\nelse if (msg.actionable_data_title_2 != null){\n    elements.push(msg.actionable_data_title_2, msg.actionable_data_action_2);\n}\n//check to see if elements contains msg.image AND msg.actionable_data_title_1\nif (elements.includes(msg.image) && elements.includes(msg.actionable_data_title_1)){\n   msg.notification = \"{\\\"title\\\":\\\" + msg.title + \\\",\\\"message\\\":\\\"{{message}}\\\",\\\"data\\\":{\\\"image\\\":\\\"{{image}}\\\",\\\"actions\\\":[{\\\"action\\\":\\\"{{actionable_data_action_1}}\\\",\\\"title\\\":\\\"{{actionable_data_title_1}}\\\"},{\\\"action\\\":\\\"{{actionable_data_action_2}}\\\",\\\"title\\\":\\\"{{actionable_data_title_2}}\\\"}]}}\"\n}\n//check to see if elements contains msg.whatever but DOES NOT contain msg.image\nelse if (!elements.includes(msg.image) && elements.includes(msg.actionable_data_title_1)){\n   msg.notification = \"{\\\"title\\\":\\\" + msg.title + \\\",\\\"message\\\":\\\"{{message}}\\\",\\\"data\\\":{\\\"actions\\\":[{\\\"action\\\":\\\"{{actionable_data_action_1}}\\\",\\\"title\\\":\\\"{{actionable_data_title_1}}\\\"},{\\\"action\\\":\\\"{{actionable_data_action_2}}\\\",\\\"title\\\":\\\"{{actionable_data_title_2}}\\\"}]}}\"\n}\nif (elements.includes(msg.image) && !elements.includes(msg.actionable_data_title_1)){\n   msg.notification = {\n    title: msg.title,\n    message: msg.message,\n    data:{\n        image: msg.image},\n   }\n}\n\n\nreturn msg;\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1115,"y":2760,"wires":[["f3130b823f35920d"]],"l":false}]

Weird its still not working for me, could you paste the whole flow?

JSON keys need " " or do I misunderstand you?

[{"id":"8158ab0b731cfa04","type":"inject","z":"f80b6c338afd5483","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":975,"y":2720,"wires":[["8a8b1a3d6d5ff2f5"]],"l":false},{"id":"4d64f59ce4eaf3d1","type":"inject","z":"f80b6c338afd5483","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":975,"y":2760,"wires":[["1f72036f5402d9f8"]],"l":false},{"id":"4d84c50e9eeb2cca","type":"inject","z":"f80b6c338afd5483","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":975,"y":2800,"wires":[["c6a6cfe3c25c81c8"]],"l":false},{"id":"c6a6cfe3c25c81c8","type":"change","z":"f80b6c338afd5483","name":"Set Notification msg","rules":[{"t":"set","p":"title","pt":"msg","to":"Actionable With Image","tot":"str"},{"t":"set","p":"message","pt":"msg","to":"This is a test","tot":"str"},{"t":"set","p":"actionable_data_title_1","pt":"msg","to":"Test 1!","tot":"str"},{"t":"set","p":"actionable_data_action_1","pt":"msg","to":"restart_coffee_timer","tot":"str"},{"t":"set","p":"actionable_data_title_2","pt":"msg","to":"Test 2!","tot":"str"},{"t":"set","p":"actionable_data_action_2","pt":"msg","to":"dont_restart_coffee_timer","tot":"str"},{"t":"set","p":"image","pt":"msg","to":"/media/local/abstract.jpg","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1035,"y":2800,"wires":[["3d677e1e9a53d4cf"]],"l":false,"info":"Changes the person entity to a simple name\n\nexample: person.joe -> Joe"},{"id":"1f72036f5402d9f8","type":"change","z":"f80b6c338afd5483","name":"Set Notification msg","rules":[{"t":"set","p":"title","pt":"msg","to":"Just Image","tot":"str"},{"t":"set","p":"message","pt":"msg","to":"This is a test","tot":"str"},{"t":"set","p":"image","pt":"msg","to":"/media/local/abstract.jpg","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1035,"y":2760,"wires":[["3d677e1e9a53d4cf"]],"l":false,"info":"Changes the person entity to a simple name\n\nexample: person.joe -> Joe"},{"id":"8a8b1a3d6d5ff2f5","type":"change","z":"f80b6c338afd5483","name":"Set Notification msg","rules":[{"t":"set","p":"title","pt":"msg","to":"Actionable No Image","tot":"str"},{"t":"set","p":"message","pt":"msg","to":"This is a test","tot":"str"},{"t":"set","p":"actionable_data_title_1","pt":"msg","to":"Test 1!","tot":"str"},{"t":"set","p":"actionable_data_action_1","pt":"msg","to":"restart_coffee_timer","tot":"str"},{"t":"set","p":"actionable_data_title_2","pt":"msg","to":"Test 2!","tot":"str"},{"t":"set","p":"actionable_data_action_2","pt":"msg","to":"dont_restart_coffee_timer","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1035,"y":2720,"wires":[["3d677e1e9a53d4cf"]],"l":false,"info":"Changes the person entity to a simple name\n\nexample: person.joe -> Joe"},{"id":"3d677e1e9a53d4cf","type":"function","z":"f80b6c338afd5483","name":"Check Speaker Selection","func":"elements = []\n\nif (msg.image != null){\n    elements.push(msg.image)\n}\nelse if (msg.actionable_data_title_1 != null){\n    elements.push(msg.actionable_data_title_1, msg.actionable_data_action_1)\n}\nelse if (msg.actionable_data_title_2 != null){\n    elements.push(msg.actionable_data_title_2, msg.actionable_data_action_2);\n}\n//check to see if elements contains msg.image AND msg.actionable_data_title_1\nif (elements.includes(msg.image) && elements.includes(msg.actionable_data_title_1)){\n   msg.notification = \"{\\\"title\\\":\\\" + msg.title + \\\",\\\"message\\\":\\\"{{message}}\\\",\\\"data\\\":{\\\"image\\\":\\\"{{image}}\\\",\\\"actions\\\":[{\\\"action\\\":\\\"{{actionable_data_action_1}}\\\",\\\"title\\\":\\\"{{actionable_data_title_1}}\\\"},{\\\"action\\\":\\\"{{actionable_data_action_2}}\\\",\\\"title\\\":\\\"{{actionable_data_title_2}}\\\"}]}}\"\n}\n//check to see if elements contains msg.whatever but DOES NOT contain msg.image\nelse if (!elements.includes(msg.image) && elements.includes(msg.actionable_data_title_1)){\n   msg.notification = \"{\\\"title\\\":\\\" + msg.title + \\\",\\\"message\\\":\\\"{{message}}\\\",\\\"data\\\":{\\\"actions\\\":[{\\\"action\\\":\\\"{{actionable_data_action_1}}\\\",\\\"title\\\":\\\"{{actionable_data_title_1}}\\\"},{\\\"action\\\":\\\"{{actionable_data_action_2}}\\\",\\\"title\\\":\\\"{{actionable_data_title_2}}\\\"}]}}\"\n}\nif (elements.includes(msg.image) && !elements.includes(msg.actionable_data_title_1)){\n   msg.notification = {\n    title: msg.title,\n    message: msg.message,\n    data:{\n        image: msg.image},\n   }\n}\n\n\nreturn msg;\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1215,"y":2760,"wires":[["f3130b823f35920d"]],"l":false},{"id":"f3130b823f35920d","type":"debug","z":"f80b6c338afd5483","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1370,"y":2760,"wires":[]}]

Gives me this in the debug

image

@Hellis81

I agree, I copied an example from somewhere else I can’t seem to find rn.

[{"id":"8158ab0b731cfa04","type":"inject","z":"f80b6c338afd5483","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":975,"y":2720,"wires":[["8a8b1a3d6d5ff2f5"]],"l":false},{"id":"4d64f59ce4eaf3d1","type":"inject","z":"f80b6c338afd5483","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":975,"y":2760,"wires":[["1f72036f5402d9f8"]],"l":false},{"id":"4d84c50e9eeb2cca","type":"inject","z":"f80b6c338afd5483","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":975,"y":2800,"wires":[["c6a6cfe3c25c81c8"]],"l":false},{"id":"c6a6cfe3c25c81c8","type":"change","z":"f80b6c338afd5483","name":"Set Notification msg","rules":[{"t":"set","p":"title","pt":"msg","to":"Actionable With Image","tot":"str"},{"t":"set","p":"message","pt":"msg","to":"This is a test","tot":"str"},{"t":"set","p":"actionable_data_title_1","pt":"msg","to":"Test 1!","tot":"str"},{"t":"set","p":"actionable_data_action_1","pt":"msg","to":"restart_coffee_timer","tot":"str"},{"t":"set","p":"actionable_data_title_2","pt":"msg","to":"Test 2!","tot":"str"},{"t":"set","p":"actionable_data_action_2","pt":"msg","to":"dont_restart_coffee_timer","tot":"str"},{"t":"set","p":"image","pt":"msg","to":"/media/local/abstract.jpg","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1035,"y":2800,"wires":[["3d677e1e9a53d4cf"]],"l":false,"info":"Changes the person entity to a simple name\n\nexample: person.joe -> Joe"},{"id":"1f72036f5402d9f8","type":"change","z":"f80b6c338afd5483","name":"Set Notification msg","rules":[{"t":"set","p":"title","pt":"msg","to":"Just Image","tot":"str"},{"t":"set","p":"message","pt":"msg","to":"This is a test","tot":"str"},{"t":"set","p":"image","pt":"msg","to":"/media/local/abstract.jpg","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1035,"y":2760,"wires":[["3d677e1e9a53d4cf"]],"l":false,"info":"Changes the person entity to a simple name\n\nexample: person.joe -> Joe"},{"id":"8a8b1a3d6d5ff2f5","type":"change","z":"f80b6c338afd5483","name":"Set Notification msg","rules":[{"t":"set","p":"title","pt":"msg","to":"Actionable No Image","tot":"str"},{"t":"set","p":"message","pt":"msg","to":"This is a test","tot":"str"},{"t":"set","p":"actionable_data_title_1","pt":"msg","to":"Test 1!","tot":"str"},{"t":"set","p":"actionable_data_action_1","pt":"msg","to":"restart_coffee_timer","tot":"str"},{"t":"set","p":"actionable_data_title_2","pt":"msg","to":"Test 2!","tot":"str"},{"t":"set","p":"actionable_data_action_2","pt":"msg","to":"dont_restart_coffee_timer","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1035,"y":2720,"wires":[["3d677e1e9a53d4cf"]],"l":false,"info":"Changes the person entity to a simple name\n\nexample: person.joe -> Joe"},{"id":"3d677e1e9a53d4cf","type":"function","z":"f80b6c338afd5483","name":"Check Speaker Selection","func":"elements = []\n\nif (msg.image != null){\n    elements.push(msg.image)\n}\nelse if (msg.actionable_data_title_1 != null){\n    elements.push(msg.actionable_data_title_1, msg.actionable_data_action_1)\n}\nelse if (msg.actionable_data_title_2 != null){\n    elements.push(msg.actionable_data_title_2, msg.actionable_data_action_2);\n}\n//check to see if elements contains msg.image AND msg.actionable_data_title_1\nif (elements.includes(msg.image) && elements.includes(msg.actionable_data_title_1)){\n   msg.notification = \"{\\\"title\\\":\\\" + msg.title + \\\",\\\"message\\\":\\\"{{message}}\\\",\\\"data\\\":{\\\"image\\\":\\\"{{image}}\\\",\\\"actions\\\":[{\\\"action\\\":\\\"{{actionable_data_action_1}}\\\",\\\"title\\\":\\\"{{actionable_data_title_1}}\\\"},{\\\"action\\\":\\\"{{actionable_data_action_2}}\\\",\\\"title\\\":\\\"{{actionable_data_title_2}}\\\"}]}}\"\n}\n//check to see if elements contains msg.whatever but DOES NOT contain msg.image\nelse if (!elements.includes(msg.image) && elements.includes(msg.actionable_data_title_1)){\n   msg.notification = \"{\\\"title\\\":\\\" + msg.title + \\\",\\\"message\\\":\\\"{{message}}\\\",\\\"data\\\":{\\\"actions\\\":[{\\\"action\\\":\\\"{{actionable_data_action_1}}\\\",\\\"title\\\":\\\"{{actionable_data_title_1}}\\\"},{\\\"action\\\":\\\"{{actionable_data_action_2}}\\\",\\\"title\\\":\\\"{{actionable_data_title_2}}\\\"}]}}\"\n}\nif (elements.includes(msg.image) && !elements.includes(msg.actionable_data_title_1)){\n   msg.notification = {\n    title: msg.title,\n    message: msg.message,\n    data:{\n        image: msg.image},\n   }\n}\n\n\nreturn msg;\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1215,"y":2760,"wires":[["f3130b823f35920d"]],"l":false},{"id":"f3130b823f35920d","type":"debug","z":"f80b6c338afd5483","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1370,"y":2760,"wires":[]}]

Gives me this in the debug

image

@Hellis81

The example was taken from a how to build an mqtt message, which works for me.

if (msg.payload.event_type != "zwave.scene_activated")
 return null;

var scene_id = msg.payload.event.scene_id;
var scene_data = msg.payload.event.scene_data;
var scene_state = scene_id == 1 ? "on" : "off";
var scene_action = ""; var scene_tap; var scene_hold = false; var scene_release = false;
switch(scene_data) {
 case 0:
 case 7680:
 scene_action = "Single tap";
 scene_tap = 1;
 break;
 case 1:
 case 7740:
 scene_action = "Release";
 scene_release = true;
 break;
 case 2:
 case 7800:
 scene_action = "Tap and hold";
 scene_hold = true;
 break;
 case 3:
 case 7860:
 scene_action = "Double tap";
 scene_tap = 2;
 break;
 case 4: 
 case 7920:
 scene_action = "Triple tap";
 scene_tap = 3;
 break;
 case 7980:
 scene_action = "Four tap";
 scene_tap = 4;
 break;
 case 8040:
 scene_action = "five tap";
 scene_tap = 5;
 break;
}

var nodes = global.get("zwave-lights");
var matchingNode = nodes.find(x => x.node_id === msg.payload.event.node_id);

 
msg.topic = "scene/" + matchingNode.entity_id; 
msg.payload = { 
 entity_id: matchingNode.entity_id, 
 node_id: matchingNode.node_id,
 scene: {
 text: scene_action,
 state: scene_state,
 tap: scene_tap,
 hold: scene_hold,
 release: scene_release
 }
};
 
return msg; 

 
// Action	 scene_id	scene_data
// Single tap on	 1	 0
// Single tap off	 2	 0
// Double tap on	 1	 3
// Double tap off	 2	 3
// Triple tap on	 1	 4
// Triple tap off	 2	 4
// Tap and hold on	 1	 2
// Tap and hold off	 2	 2

I can pass the values into a debug node just fine, and the values are as expected. I just cant figure out the correct thing to put into the ‘data’ field for a call service node to get it to work

It’s the message composition. It all needs to come in under msg.payload. the only thing that needs to be in the call service node is notify in domain.

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/cookbook/actionable-notifications-subflow-for-android.html#demo-flow

I’ve noticed I need to put

{"message":"{{payload}}"}

in the data field to get whatever is in the msg.payload to go through and notify me. Also in the drop down you have to change it from “expression” to “JSON”