Notify Mobile Companion App Devices

Struggling to make use of the notification options of the Home Assistant Companion App on your mobile device? Then this script can help you in the right direction.
Ever gone through all of the options of the Companion app?, then you may have lost your self :thinking: in all of the options you can pick you might be dazzled :dizzy_face: what you can do with it, let alone reapply it in another automation :confused:.

And so I noticed over the last year or so that I made more and more use of the notifications via the Home Assistant Companion App on the various mobile devices, and I loved it so much that I applied it for many automations. During that journey I was struggling with adding and fixing the code in various automations (there are +/- 40 automations where I was using it) so maintaining all of it was a nightmare. And thus I made one script that has all the logic in it to notify all or specific devices, which have the app installed, and let the automation call the script. And meanwhile use the selectors to have a UI to guide the process with all sorts of options.

Where to start?
First thing is of course following the Getting Started to configure and install the Home Assistant Companion App

Once the Home Assistant Companion App is installed and connected you should have one or more devices in the Integrations section Open your Home Assistant instance and show your integrations.

Features of this script

  • Use an UI to select options instead of reading the documentation :face_with_spiral_eyes::woozy_face::thinking::smiling_face_with_tear::yawning_face::tired_face::stuck_out_tongue_closed_eyes:

  • Able to send notifications to one or more specific device(s) or all devices

  • Send notifications based on the device(s) state:

    • Home
    • Away
    • Both (Home and Away)
  • Send notifications to Android and iOS devices (!). The script then filters the input to what is supported per platform. Thus Android features are not send to iOS devices and visa versa.

  • Send notifications with actionable actions. The script then filters the actions per platform. Thus Android actions are not send to iOS devices and visa versa.

  • Support notifications with camera images/live feed for camera devices, also for Google Nest camera devices (!).

Then what?

  • Click on this link to Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.
  • Follow the instuctions to create a new script.
  • Go to the Developer Tools → Services and test the new script Open your Home Assistant instance and show your service developer tools.
    • Use the ‘Go to YAML mode’ and click on the “Fill example data” to send notification example to all mobile devices :nerd_face:
    • Try out the examples (at the end of this article)
  • Use the script in your automation to send notifications to your mobile device :partying_face: :partying_face: :partying_face:

Usefull examples

Example 1: Send a persistent notification, that the user can’t remove

service: script.notify_devices
data:
  notify_home_or_away: Both
  data_notification_icon: mdi:human-greeting-variant
  notify_title: Example 1
  notify_message: Send a persistent notification, that the user can't remove
  data_group: Example
  data_tag: Use this tag when you need to remove it
  data_importance: high
  data_sticky: true
  data_persistent: true

Example 2: Send a clean_persistent notification, so the notification is removed

service: script.notify_devices
data:
  notify_home_or_away: Both
  data_tag: Use this tag when you need to remove it
  data_importance: high
  notify_message: clear_notification

Example 3: Send a persistent notification, that the user can’t remove, but automatically is removed

service: script.notify_devices
data:
  notify_home_or_away: Both
  data_notification_icon: mdi:human-greeting-variant
  notify_title: Example 3
  notify_message: Send a persistent notification, that the user can't remove
  data_group: Example
  data_tag: Use this tag when you need to remove it
  data_importance: high
  data_sticky: true
  data_persistent: true
  data_timeout: 30

I hope that it helps you as much as it did for me :robot:. Happy notifying!

:rocket:CHANGELOG

  • Release 2024.04 Feat: Android Only - Alert Once
  • Release 2024.2 This version packs various fixes, breaking changes, and updates to the documentation/descriptions of the various selectors
  • Release 2023.7.20 Fixes to the double notification issue for Android Auto
22 Likes

Truly great script, and sorely needed to handle more advanced notifications without wanting to kill yourself. Thx a bunch.

1 Like

Is it possible to implement custom audible alerts with your script? I use custom audio files for some alerts. For instance a fire alarm alert uses fire alarm audio, security alerts use siren, etc.

1 Like

What I can see on the documentation is that sounds is an IOS feature: Sounds | Home Assistant Companion Docs
So are are you sending notifications to IOS devices?

Yes. It’s the iPhone companion app.

I haven’t used that feature, but what I can see in the docs it that there are a bunch of settings to create something like your asking. I have one iPhone (latest iOS), so I’ll need some time to test it, to get the right combination

1 Like

Thanks for your time.:+1:

Can you give the new one a try? Due to new options I’ve exceeded the length of the post, therefor I added the contents in Github: Grumblezz/Home-Assistant-Notify-Mobile-Companion-App-Devices: Struggling to make use of the notification options of the Home Assistant Companion App on your mobile device? Then this script can help you in the right direction. (github.com)

There are now two new options:

  • iOS Only - Sounds? (Optional)
  • iOS Only - Sound Volume Level (Optional)

It worked for my iPhone. I added all of the supported sounds. The iOS only - Sounds? (Optional) is an suggestive list, so feel free to add your own audio file. I haven’t tested a custom audio file, but all of those instructions can be found in the docs.

I’ve converted the whole script to an Blueprint to make the import & update easier. Some iOS features are now fleshed out and several bugs were smashed :thinking::woozy_face::sunglasses:

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

1 Like

This is a great script! Saved me a lot of time to send some fancy notifications!

I have one suggestion. I would preferer to send notifications to all devices by default. So I changed the code lines from 912 to 917:

notify_devices: >-
        {# Finally, let the value "notify_home_or_away" control which list should used #}
        {% if notify_home_or_away == "Home" %}{{ notify_devices_home }}
        {% elif notify_home_or_away == "Away" %}{{ notify_devices_away }}
        {% elif notify_home_or_away == "Both" %}{{ all_devices }}
        {% else %}{{ all_devices }}{% endif %}

(916 could also be removed…)

And 208 to 210 accordingly:

notify_home_or_away:
    name: Notify those that are Home or Away? (Default is Both)
    required: false

Just an idea :slight_smile:

Hi, in the current state it already works, you would only need to include the option notify_home_or_away: Both , which will send out a message to all devices.

Try this one out :grinning_face_with_smiling_eyes: (I named mine notify_devices, please update it to your value that you choose when importing the Blue print )

service: script.notify_devices
data:
  notify_home_or_away: Both

I could make the notify_home_or_away an optional field, and thus use Both as an default value when it is not specified. Because your suggestion will throw warnings and will error since the variable notify_home_or_away would not be defined when it is a non mandatory field.

Thank you!

Are Template Messages supported?

1 Like

Thanks for the reply. I have already tried that, but would prefer the default option.
I haven’t gotten that warning yet since I put in my changes. But I think you are right.

Sorry for the long wait, due to the Mariadb requirements changes I had to rebuild my entire HA setup :sob: . Anyway your suggestion has been implemented and the notify_home_or_away is not required anymore. It will prefer to send an message to all devices.

While testing I came across some unwanted behaviour. All of the sudden I had data_chronometer: undefined 00:00:00 in my service request. So now the script can handle that scenario as well.

1 Like

@Grumblezz So I guess after I imported the blueprint I have to go to blueprints and create a script?
I then enter as entity ID the id of my mobile phone of the companion app (notify.mobile_app_pixel_6 → so I enter just pixel_6).
Then a script named pixel_6 is created and I can go to the developer tools.
After I selected script.pixel_6 and filled the request with example data I executed the service and got the error:
Fehler beim Aufrufen des Diensts script.pixel_6. Unable to find service notify.mobile_app_pixel_6_2

Why is it trying to call the mobile_app_pixel_6_2 instead of mobile_app_pixel_6?
Did I anything wrong?

I have taken a few screenshots that show how to import and use the script. I hope that helps

  1. Import the Blueprint : Click here

  2. Click on Preview and followed by Import Blueprint

  3. Create the script by clicking on Create Script

  4. Enter the Name, Icon and “Entity ID”. The “Entity ID” will become script.<entity_id>. So in this case script.notify_mobile_app_devices . Click on Save Script

    .

  5. Check you mobile app devices

  6. Navigate to the developer tools to validate the imported script. So in this case script.notify_mobile_app_devices where the “Device to notify” should be the same as the previous step.

  7. Enter a “Notification message” click on Call Service.

  8. Check your phone and you should see the notification

That should be it :slight_smile:

1 Like

I consistently get a ‘timeout’ when trying to import your blueprint using the button, which I do not experience with other blueprints. Any clue what might cause this?

Have you tried pasting the GitHub url? Maybe Pi Hole or another service is blocking this action?

The file is hosted on GitHub, so not some random webserver or so… The links that I have used where generated via the Home Assistant (Create a link – My Home Assistant) Link generator. So all of it refers to services that should be generally be accessible

HI , TTS on iOS does not work? Any idea?

Well, turns out disabling IPv6 did the trick. No clue why that didn’t interfere with other blueprints, but that does not matter now, it’s solved. Found the solution here: Timeout error while importing blueprint - #6 by Mr-Beat