How to send mobile notification through HA app with Nodered?

I see there’s a thread from December 2019 saying that the companion Android app can send notifications, but I can’t find how to actually do that from within Nodered. There’s no node that contains my phone’s name, and the ‘notify’ node seems to be only for the browser. Is there a way to do this?

1 Like

You need to call a service for that, like so:

This shows a notification on my tv, but it’s the same for the mobile app.

Check this out

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

2 Likes

Generally you do it the same way in Node red as in HA.

In HA you use call service as described here Introduction | Home Assistant Companion Docs (home-assistant.io)

In Node red you use the Call service node.
The data from the yaml needs to be converted to json in the call service node.

Example:

this yaml

automation:
  - alias: "Notify of Motion color"
    trigger:
      ...
    action:
      - service: notify.mobile_app_<your_device_id_here>
        data:
          title: "Motion Detected in Backyard"
          message: "Someone might be in the backyard."
          data:
            color: "#2DF56D" # or "red"

The “data” meaning:

        data:
          title: "Motion Detected in Backyard"
          message: "Someone might be in the backyard."
          data:
            color: "#2DF56D" # or "red"

Needs to be placed in the json field as

{
  "data": {
    "title": "Motion Detected in Backyard",
    "message": "Someone might be in the backyard.",
    "data": {
      "color": "#2DF56D" // or "red"
    }
  }
}
3 Likes

For anyone coming across this in 2023, the above json didn’t work for me. I had to remove the outer “data”.

{
    "title": "Motion Detected in Backyard",
    "message": "Someone might be in the backyard.",
    "data": {
      "color": "#2DF56D" // or "red"
    }
}
5 Likes

How do you include channels in this?

Edit: I got it, for anybody else wondering how to utilize channels in this logic. Once the first notification is sent, the new channel will be avail in the companion app for further changes for sounds.

{“title”:“Light Unavailable”,“message”:“{{topic}}”,“data”:{“color”:“red”,“channel”:“Alarm”,“priority”:“high”,“ttl”:0}}

{
“title”: “Light Unavailable”,
“message”: “{{topic}}”,
“data”: {
“color”: “red”,
“channel”: “Alarm”,
“priority”: “high”,
“ttl”: 0
}
}

1 Like

Hi,
I wrote an a node red automation to notify me if new updates are available.
Notification is send to Home Assistant and also to your mobile device (for me iOS Companion app).
And it works with all update entities :slight_smile:

[{"id":"9c281d05c5f133c7","type":"group","z":"24a64c4fef191855","style":{"stroke":"#2e333a","stroke-opacity":"1","fill":"#383c45","fill-opacity":"0.5","label":true,"label-position":"nw","color":"#dddddd"},"nodes":["7afc3f45105c6bd7","53d885a1c70ff02b","0a5123b1ef49bff9","b1bf11cedcf2a5bd","2ffc1d974deb6fa5","34915d2eee81bdd4","cd68f0379298dfe6","e4701fd4d0e1a6df","49af8690398bc67e"],"x":54,"y":1539,"w":972,"h":202},{"id":"7afc3f45105c6bd7","type":"api-call-service","z":"24a64c4fef191855","g":"9c281d05c5f133c7","name":"Notify iPhone","server":"f56de91.b429118","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_vitphone14","areaId":[],"deviceId":[],"entityId":[],"data":"{\t    \"message\": message,\t    \"title\": title,\t    \"data\":\t    {\t        \"tag\": notification_id,\t        \"url\": \"/config/updates\",\t        \"clickAction\": \"/config/updates\",\t        \"actions\":\t        [\t            {\t                \"action\": \"URI\", \t                \"title\": \"Open Dashboard\",\t                \"uri\": \"/config/dashboard\"\t            },\t            {\t                \"action\": \"URI\", \t                \"title\": \"Open Addons\",\t                \"uri\": \"/hassio/dashboard\"\t            },\t            {\t                \"action\": \"URI\", \t                \"title\": \"Open HACS\",\t                \"uri\": \"/hacs\"\t            }\t        ]\t    }\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":830,"y":1580,"wires":[[]]},{"id":"53d885a1c70ff02b","type":"api-call-service","z":"24a64c4fef191855","g":"9c281d05c5f133c7","name":"Notify Home Assistant","server":"f56de91.b429118","version":5,"debugenabled":false,"domain":"persistent_notification","service":"create","areaId":[],"deviceId":[],"entityId":[],"data":"{\t   \"message\": message,\t   \"title\": title,\t   \"notification_id\": notification_id\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":860,"y":1660,"wires":[[]]},{"id":"0a5123b1ef49bff9","type":"api-call-service","z":"24a64c4fef191855","g":"9c281d05c5f133c7","name":"Delete Notify iPhone","server":"f56de91.b429118","version":5,"debugenabled":false,"domain":"notify","service":"mobile_app_vitphone14","areaId":[],"deviceId":[],"entityId":[],"data":"{\t    \"message\":\"clear_notification\",\t    \"data\":\t    {\t       \"tag\": notification_id\t    }\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":860,"y":1620,"wires":[[]]},{"id":"b1bf11cedcf2a5bd","type":"api-call-service","z":"24a64c4fef191855","g":"9c281d05c5f133c7","name":"Delete Notify Home Assistant","server":"f56de91.b429118","version":5,"debugenabled":false,"domain":"persistent_notification","service":"dismiss","areaId":[],"deviceId":[],"entityId":[],"data":"{\t    \"notification_id\": notification_id\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":880,"y":1700,"wires":[[]]},{"id":"2ffc1d974deb6fa5","type":"ha-get-entities","z":"24a64c4fef191855","g":"9c281d05c5f133c7","name":"Get all active update entities","server":"f56de91.b429118","version":0,"rules":[{"property":"entity_id","logic":"is","value":"update\\..*","valueType":"re"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"array","output_empty_results":true,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":420,"y":1640,"wires":[["cd68f0379298dfe6","49af8690398bc67e"]]},{"id":"34915d2eee81bdd4","type":"inject","z":"24a64c4fef191855","g":"9c281d05c5f133c7","name":"Every Mo 12:00","props":[{"p":"payload"}],"repeat":"","crontab":"00 12 * * 1","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":1600,"wires":[["2ffc1d974deb6fa5"]]},{"id":"cd68f0379298dfe6","type":"function","z":"24a64c4fef191855","g":"9c281d05c5f133c7","name":"setMessage","func":"msg.notification_id = \"updates_available\";\nmsg.message = \"[Updates](/config/updates)\\n\\n\";\nmsg.title = \"🎊 Updates available 🎊\";\n\nfor (var i = 0; i < msg.payload.length; i++)\n{\n  var installed_version = msg.payload[i].attributes.installed_version;\n  var latest_version = msg.payload[i].attributes.latest_version;\n  var friendly_name = msg.payload[i].attributes.friendly_name;\n\n  msg.message += \"• **\" + friendly_name + \"**: v\" + installed_version + \" ➤ v\" + latest_version + \"\\n\";\n}\n\nif (msg.payload.length === 0)\n{\n  return [ null, msg ];\n}\nreturn [ msg, null ];","outputs":2,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":1660,"wires":[["53d885a1c70ff02b"],["b1bf11cedcf2a5bd"]],"outputLabels":["create message","delete message"]},{"id":"e4701fd4d0e1a6df","type":"server-state-changed","z":"24a64c4fef191855","g":"9c281d05c5f133c7","name":"On update change","server":"f56de91.b429118","version":5,"outputs":1,"exposeAsEntityConfig":"","entityId":"update\\..*","entityIdType":"regex","outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":170,"y":1640,"wires":[["2ffc1d974deb6fa5"]]},{"id":"49af8690398bc67e","type":"function","z":"24a64c4fef191855","g":"9c281d05c5f133c7","name":"setMessage","func":"msg.notification_id = \"updates_available\";\nmsg.message = \"\";\nmsg.title = \"🎊 Updates available 🎊\";\n\nfor (var i = 0; i < msg.payload.length; i++)\n{\n  var installed_version = msg.payload[i].attributes.installed_version;\n  var latest_version = msg.payload[i].attributes.latest_version;\n  var friendly_name = msg.payload[i].attributes.friendly_name;\n\n  msg.message += \"• \" + friendly_name + \": v\" + installed_version + \" ➤ v\" + latest_version + \"\\n\"\n}\n\nif (msg.payload.length === 0)\n{\n  return [ null, msg ];\n}\nreturn [ msg, null ];","outputs":2,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":1620,"wires":[["7afc3f45105c6bd7"],["0a5123b1ef49bff9"]],"outputLabels":["create message","delete message"]},{"id":"f56de91.b429118","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]