Notify Mobile Companion App Devices

Good one! I had a similar issue yesterday as well. Thanks for the feedback

I seem to have the same issue. I will have a look at it

TTS appears an Andriod only thingā€¦

In the docs it is also only mentioned for Andriod
Introduction | Home Assistant Companion Docs (home-assistant.io)

With Frigate blueprint TTS works in IOSā€¦. so it seems an issue in the Skript ?!

Can you share that blueprint? Because Iā€™m using the companion app features.

Sureā€¦.

When I look at there code they have the same limitations of the mobile app. So no, you canā€™t use TTS on iPhone. What their Blue print does, is that it make use of the build in sounds of iPhone/Homeassistant. This same thing can also be done in this blueprint. So please check this page: Sounds | Home Assistant Companion Docs and then use your custom sound file name in this script

So here are some examples

FYI: update the service name to what ever you have defined during the creation of the blueprint, mine is called script.notify_devices

Example 1
This will send an sound notification to all of the IOS devices which have the mobile app installed. By default the sound level is set to 50%

service: script.notify_devices
data:
  notify_message: There is somebody at the door!
  data_ios_sound: US-EN-Alexa-Motion-At-Front-Door.wav
  notify_home_or_away: Both
  notify_devices: >-
    {%set devices=namespace(id=[])%}
    {% for device in (expand(integration_entities('mobile_app'))|selectattr('domain','in','device_tracker')|map(attribute='entity_id')|list) %}
    {% if is_device_attr(device,'manufacturer','Apple')==true%}
    {%set devices.id=devices.id+[(device_id(device))]%}
    {%endif%}
    {%endfor%}
    {{devices.id}}

Example 2
This will send an sound notification to all of the IOS devices which have the mobile app installed. Volume MAX and a critical notification marker

service: script.notify_devices
data:
  notify_message: There is somebody at the door!
  data_ios_sound: US-EN-Alexa-Motion-At-Front-Door.wav
  notify_home_or_away: Both
  data_critical: true
  data_ios_sound_volumelevel: 1
  data_ios_interruption_level: critical
  data_ios_presentation_options:
    - alert
    - sound
  notify_devices: >-
    {%set devices=namespace(id=[])%}
    {% for device in (expand(integration_entities('mobile_app'))|selectattr('domain','in','device_tracker')|map(attribute='entity_id')|list) %}
    {% if is_device_attr(device,'manufacturer','Apple')==true%}
    {%set devices.id=devices.id+[(device_id(device))]%}
    {%endif%}
    {%endfor%}
    {{devices.id}}

1 Like

Just wanted to say thank you for this blueprint! I never digged in to the details of how to trigger notifications in the companion app, and thanks to your work, I donā€™t need to either. Great work! Very appreciated!

1 Like

Thanks for this!
I have been personally struggling with how to pass data into a script blueprint and eventually gave up. You have provided a roadmap for me.
I truly appreciate your contribution to the community!
Time for more BPā€™s!

1 Like

A new version has released Release 2023.06 Ā· Grumblezz/Home-Assistant-Notify-Mobile-Companion-App-Devices (github.com) check it out!

1 Like

Hi,

Thanks for this.

I have another question, related to the source of truth.

Rencently I have this in the script options:

Response variable This service can return a response, if you want to use the response, enter the name of a variable the response will be saved in 

However I cannot find this variable if in the github repo
`response_variable``

Hi zaggash,

The group feature is not supported by this automation, but there are a few options:

  • Make a feature requests at Home Assistant to be able to create a group with device_tracker objects. Because this is currently not supported.
  • Do not use the group option to call this script, but instead use a template , to filter for the devices and pass it on to this script, like:
{% set ns_devices=namespace( device_id=[] ) %}
{% for e in (integration_entities("mobile_app")|select("search","device_tracker")|list) %}
{% set ns_devices.device_id=ns_devices.device_id+[device_id(e)] %}
{% endfor %}
{{ ns_devices.device_id }}

And then add additional select() options to the second line

Orā€¦

{% set ns_devices=namespace( device_id=[] ) %}
{% for e in ['device_tracker.apple','device_tracker.android'] %}
{% set ns_devices.device_id=ns_devices.device_id+[device_id(e)] %}
{% endfor %}
{{ ns_devices.device_id }}

Secondly the TTL feature is already available in the script by enabling the Important Notification. That will set the TTL to 0.

What response feature are you referring to? Is there a website that has more details about this?

Or are you referring to the custom actions part of this script?

@Grumblezz
Thanks for the quick tips.

Regarding the feature, this is what I have in the script:

See the response variable

You allow mobile_app devices to be added and then look for device_tracker for location.

Would it be possible to search through a group of mobile_app_* service using the service name ?

Sorry if I misunderstand the complexity I didnā€™t work on the blueprint as much as you did

Ah yeah I see what you are meaningā€‹:face_with_peeking_eye: :smile:I have the same, since that is the newest feature introduced with 2023.7 :partying_face:

In this release, we have included two brand-new services to play with service responses:

conversation.process - This service allows you to ask Assist a command or question and get a response back.
calendar.list_events - This service enables you to ask Home Assistant for a list of events on your calendar.

So you can ignore this option, as there is no way to suppress this, since the notify service is not making use of this as of yet.

Short answer:
No sorry, Iā€™m not going to change the code to be able to utilize the notify group option

Long answer:
The notify.#### services can not tell where that device is nor that is knows any state(s) of the device. Let alone the group notification featureā€¦
So in order to get the states of your mobile device you would need the device_tracker.####.

The script does the following:

  1. Who do we need to inform? a list of device_tracker 1 / 2 / 3 / etc. or when nothing is selected it will search for all of them. Once determined it uses the device_id (because we need the information of the sensors later on).
  2. Where is each device? Home or Away?
  3. Based on item 1 and 2 it combines the information to determine whom shall be notified.
  4. Notify each device_id from step 3 and use the correct syntax per manufacturer, since iOS needs different notification information then Andriod devices do.

Now Iā€™m working on an additional option for devices based on their sensors, so what I want to tell you here is that the notify.### doesnā€™t give you any information what we are dealing with (Apple? Andriod? Home? Away?) whilst the device_tracker does.
Therefor Iā€™m not going to change the code.

So my question to you @zaggash is, what is your use case that you cannot fulfil with this script?

Examples

This notification is send to all devices with the Companion App installed

service: script.notify_devices
data:
  notify_message: >-
    This message is sent to every device with the Companion App, whether they
    are home or away from home.
  notify_home_or_away: Both

Or another example:
This notification is send only to two devices (device_tracker.apple & device_tracker.android) with the Companion App installed

service: script.notify_devices
data:
  notify_message: >-
    This message is sent to every device with the Companion App, whether they
    are home or away from home.
  notify_home_or_away: Both
  notify_devices: >-
    {% set ns_devices=namespace( device_id=[] ) %}
    {% for e in ['device_tracker.apple','device_tracker.android'] %}
    {% set ns_devices.device_id=ns_devices.device_id+[device_id(e)] %}
    {% endfor %}
    {{ ns_devices.device_id }}

Sorry for this question, Iā€™m feeling really dumb at this momentā€¦
I have imported the blueprint, clicked on Create script and entered name/icon/entity_id
But when I click Save script, nothing is saved? No script is created and the script isnā€™t visible in Dev tools.
What am I doing wrong here?