Home Assistant Notification flow
I've created a very simple sub flow for using Home Asssistant notifications using Node-Red.
After import just drag and drop it to the flow you want to use it in. After that double click on it and enter the correct information:
Title: The title of the message
Message: Of course the message it self
User: Use all
of enter the entitie of device that should recieve the notification
Critical?: Turn on (set it to true
) if it should be deliverd as a critical notification
Location?: Turn on the request the latest location of the user you defined in User
Update's:
31-01-2022:
- Ignore message if payload has contents
[{"id":"85ed41d1b523eda1","type":"subflow","name":"Notification","info":"Hi!","category":"","in":[{"x":40,"y":40,"wires":[{"id":"b43de5f2819711c2"}]}],"out":[],"env":[{"name":"title","type":"str","value":"","ui":{"icon":"font-awesome/fa-header","type":"input","opts":{"types":["str"]}}},{"name":"message","type":"str","value":"","ui":{"icon":"font-awesome/fa-envelope-o","type":"input","opts":{"types":["str"]}}},{"name":"user","type":"str","value":"","ui":{"icon":"font-awesome/fa-users","type":"input","opts":{"types":["str"]}}},{"name":"critical?","type":"bool","value":"false","ui":{"icon":"font-awesome/fa-warning","type":"input","opts":{"types":["bool"]}}},{"name":"location","type":"bool","value":"false","ui":{"icon":"font-awesome/fa-location-arrow","type":"input","opts":{"types":["bool"]}}}],"meta":{"module":"homeassistant-notification","author":"Toppe <[email protected]>","license":"Apache-2.0"},"color":"#3FADB5","inputLabels":["Connect to node that start notification"],"icon":"font-awesome/fa-mobile-phone"},{"id":"5a5d26f88b8ad3d4","type":"api-call-service","z":"85ed41d1b523eda1","name":"","server":"1d523c9b04aaa68e","version":3,"debugenabled":false,"service_domain":"notify","service":"","entityId":"","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":330,"y":40,"wires":[[]]},{"id":"b43de5f2819711c2","type":"function","z":"85ed41d1b523eda1","name":"Get env","func":"//Get environment variables\n//Get all the environment variables \nmsg.title = env.get(\"title\");\nmsg.message = env.get(\"message\");\nmsg.receiver = env.get(\"user\");\nmsg.critical = env.get(\"critical?\");\nmsg.locationupdate = env.get(\"location\");\n\n//Check if all loggedin devices should recieve notification\n//Groups can be created in the configuration.yaml file of HA\nif(msg.receiver == 'all'){\n msg.receiver = 'notify'\n} else if(msg.receiver == 'USER GROUP'){\n msg.receiver = 'ALL_DEVICES'\n}\n\n//Check if input requested a location update\nif(msg.locationupdate){ msg.message = 'request_location_update' }\n\n//Check if input requested a critical notification \nif(msg.critical) { msg.setCritical = 1 } else { msg.setCritical = 0 }\n\n//Check if msg.payload has content. If so, ignore msg.message\nif(msg.payload) { msg.message = msg.payload }\n\n msg.payload = {\n data :{ \n title : msg.title,\n message : msg.message,\n data: {\n push: {\n sound: {\n name: 'default',\n critical: msg.setCritical,\n volume: 1\n }\n }\n }\n },\n service : msg.receiver\n }\n\n\n\n//Return payload\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":160,"y":40,"wires":[["5a5d26f88b8ad3d4"]]},{"id":"1d523c9b04aaa68e","type":"server","name":"Home Assistant","version":2,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]