Thank you for sharing. I was looking for a smarter way of setting up my notifications and this is better than what I came up with myself.
I extended it a bit to fit my needs.
Whenever someone in my family has a new phone they also get a new mobile_app<your_device_id>. I don’t like to change all nodes again, and I’ll probably forget some. So what I did:
EDIT: I found an easier way. Read my reply below this one.
In Home Assistent on a dashboard I created a input_text per person, where I enter the device id. In node red I watch for changes on that input and if it changes it will fill a global.name . In the function node ‘create IOS alert’ (I use it for android) I added an if statement that fills msg.topic depending on the name I entered in the change node for target.
Now when someone has a new device the only thing I have to do is change it in home assistant.
var title = msg.title
var message1 = msg.message1
var message2 = msg.message2
var message3 = msg.message3
var sound = msg.sound
var critical = msg.critical
var volume = msg.volume
var target = msg.target
var final_msg = `${message1}` + `${message2}` + `${message3}`
var payload = {"data":
{
"message": `${final_msg}`,
"title": `${title}`,
"data": {
"push": {
"sound": {
"name": `${sound}`,
"critical": `${critical}`,
"volume": `${volume}`,
}
}
}
}
}
if (target == 'Person1'){
msg.topic = 'mobile_app_'+global.get("person1_phone_code")
}
if (target == 'Person2'){
msg.topic = 'mobile_app_'+global.get("person2_phone_code")
}
msg.payload = payload
return msg