Sharing my subflow to dynamically handle notifications to android smartphones. One issue remains

TLDR: I created a subflow in Node Red which can be called by other automations to send notifications to the Android Home Assistant Companion App. I have one issue remaining with the split node which I use in the subflow to send a notification to multiple recipients. In my tests it randomly sends the messages to one or both recipients. How can I solve this?

One of the messages I feed into the subflow is msg.who which contains the names of who I want to send the notification to.
If msg.who is “john&jane” it will split it into two messages “john” and “jane” and both receive a notification on their mobile. Obviously if msg.who is “john” then the split doesn’t split anything but just passes on everything. It then continues down the rest of the sequence where the messages can be sent in various modes (a high priority mode which sets my volume high etc before sending the notifications, a text to speech mode, and a normal mode).

The problem is that more than half of the time, the messages are only sent to one of the two phones.
I assume that somehow having two simultaneus activations of the same sequence (one for “john” and one for “jane”) is causing the issue.
How can I solve this?

A solution which I tried but failed: “each instance of the subflow is independent of the others” according to the documentation. I tried to leverage this by putting the “split” functionality in one subflow and then once john and jane have been split pass them into anoher subflow which does the notifications. However things still seem to get messed up and I don’t consistently get notifications on the mobile phones of both john and jane.

Because I think my subflow can be usefull inspiration for others I want to share it. Here is my subflow together with some explanations:

The subflow is not 100% generic so you may want to adapt it to your needs.

it can handle the following inputs:

  • msg.imageretrieveURL: if you want to send for example a screenshot of a security camera
  • msg.NotifyType: allowing you to specify whether it is a security notification (fire/burglar so high priority notification. The built in functionality of using the alarm_stream_max channel does not have any effect fo me, so I created my own logic that overrides do not disturb and silent mode and sets a long and annoying buzzer), a text to speech notification, a normal notification, or both.
  • msg.title: the title of the notification
  • msg.message: the message of the notification
  • msg.TTSmessage: the message for the text to speech notification to say
  • msg.who: who needs to receive the message. for example “john&jane” would result in both receiving the notifications. It expects that in the android HA companion app the names set are in the format “mobile jane”.
  • msg.actions: for actionable notifications

Caveats:

  • The text to speech notifications use the music/media volume level which is quite randomly set most of the time in my case. As a result it can for example work even if my phone is on silent, or inversely not work when my ringer volume is up high. To solve this I do a check if my phone is on silent, if so it doesn’t do anything, otherwise it turns up the mediavolume before sending the notification.
  • The home assistant android companion app can set the notification volume, but unfortunately cannot read the value in the phone. So here the sequence is quite dumb and it just turns up the notification volume before sending out the notification.
  • It only works if your phone’s language is set to english when you install the home assistant companion app. You can manually rename all the sensors etc if you want. Also make sure all the necessary sensors in the app are turned on and it has the necessary rights (e.g. to overrule do not disturb).
  • In the notification nodes, the JSON formatting doesn’ like how I inserted msg.actions to provide the actionable notifications functionality. So it shows as single line instead of multiline. I couldn’t find a solution for that but it does work :slight_smile:

As a bonus I will also include a little sequence which shows how I currently feed it with security events. For motion sensors near a camera it will map the sensor to the right camera and then take a snapshot as well.

1 Like

Here’s the code for the subflow and the sequence of the security camera’s (apparently there’s a limit of how much code I can share directly on this forum):

I hope this was usefull for someone, and that someone can help me solve my remaining problem.

I can now confirm that indeed it is the simultaneous sequences for john and jane that is causing problems. I have also found a solution.

Right after the split I have added a delay node which I feed with msg.delay set to parts.index*6000.
the split node sets parts.index to be 0 for the first message (john) and 1 for the second (jane) (and if there would be a third message it would have value 2).

So effectifely I set a delay of 0 seconds for the message to be sent to john’s mobile and 6 seconds for the message to be sent to jane’s mobile.
This way both john and jane’s mobile receive the notifications consistently.

So I now have a working generic subflow for notifications.
Ideally I would like to get rid of the 6 seconds delay for Jane (and 12 seconds if one of my kids get a mobile phone later on), but I don’t understand the problem so don’t know how to solve it.
Does anyone understand why these messages can’t pass trough at the same time trough the sequence?