šŸ”” Notifications - Actionable Mobile Notifications Script, with optional Timeout Feature and Camera Snapshots [works with iOS/Android]

Thank you for sharing such an advanced use case!

Hope it works out fine in terms of response time.
Iā€™m hear that for some Android users, they have to specifically enable the High Priority Mode feature.

As for the multidevice variant, it is just a convenient way to fire notifications to multiple devices without managing state between them. I donā€™t have a very high priority for it at this time due to potential complexities.

If you have your own automations or script that manages sending notifications to multiple devices, you can use a custom tag to handle the notifications and state between devices.

Personally I think you have done it perfect. As I said, as a script this is the way it should be.
The notification to me is a singular event (but could be to X device, Y device, etc.)

The automation can control other things.

As I have it implemented right now it is like:

Motion Happens:
    In parallel: 
        Call script send to Phone X
        Call script send to Phone Y
        .... because there could be many more devices ...
    Send TTS to Alexa's
    Send picture to Alexa with Screen

Ultimately, the actual devices in the parallel notification should be a dynamic group based on who is (or is not) at the winery. I will get there as we chip away.

1 Like

Hi,
this is a great blueprint, perfect - thanks for sharing!
When Iā€™m within my home wifi, the notifications work fine. However if Iā€™m not connected to the wifi, they are not brought to my device - also not if I reconnect to the wifi lateron. It seems that I have to be online in my home wifi in this exact moment, when the notification has been sent.
For me, this does not apply to notifications sent without the blueprint. These notifications are also received when my iphone is online with cellular only.

Do notifications sent by the blueprint work differently or is there an issue on my end?

Thanks & BR
Thomas

Hey @thk511, thanks for the kind words.

The blueprint primarily builds the configuration for the notification and sends them out via the notify service.

You could perhaps try to trigger a notification using the service template above, directly to a device with your wifi off, to test if the notification gets through using the same service the script does: notify.mobile_app_<Device_ID>

It might be due to some configuration of either the devices or something on the network. You can also refer to this documentation to see if any of the suggestions help.

How is you companion app configured and how do you access home assistant outside your home? Nabu Casa? DuckDNS?

If you do not have external access you canā€™t get a notification to Companion.

Hi
Very good job @samuelthng. Coud you help me with this?

I receive the notification and if I:

  • Do nothing ā†’ timeout actions are executed and script ends. OK
  • Swipe notification ā†’ script ends. OK
  • Press any option buttons ā†’ option actions are executed and script ends. OK
  • Press notification text ā†’ Companion app opens and shows notification link. OK except than timeout actions are executed after timeout.

I think the script should stop when pressing notification, don0t you think?

Thanks
Miguel

Hello @Miguel_Alvarez,

As far as I know, thereā€™s no event sent from device to Home Assistant when a user press notification text.

Only available events I am aware of:

  • mobile_app_notification_action
  • mobile_app_notification_cleared
  • mobile_app_notification_received

If you do happen to know of an event to listen for, or some trigger that is encapsulated within the domain of the mobile_app integration, Iā€™ll be happy to look into it. Otherwise, this will be a limitation of Home Assistant Companion app itself.

For what itā€™s worth - I agree with you, and have attempted a version to stop the script as well, but nothing promising came out of that endeavor. :sweat_smile:

Thank you for adding ā€œparallelā€ mode. I have tested it with my configuration and it has solved my problem!!

1 Like

I am a bit confused and possibly I have things set wrong.

I have this in YAML mode with the blueprint:|

alias: Gate Vehicle Motion Detection
use_blueprint:
  path: samuelthng/notifications.yaml
  input:
    notify_device: 9f8ff81591a0936eb19abc1b944fd120
    title: Vehicle Detected at Intercom
    message: A vehicle was detected at the Rio Crest gate intercom
    icon: mdi:motion-sensor
    confirm_uri: com.mcu.reolink
    confirm_text: Launch Reolink
    confirm_option_mode: action
    dismiss_enabled: false
    notification_link: app://com.mcu.reolink
    attachment_type: camera_entity
    attachment_camera_entity: camera.rc_intercom_fluent
    confirm_is_destructive: false
    timeout:
      hours: 0
      minutes: 2
      seconds: 0
    clear_on_timeout: true
    visibility: public
icon: mdi:motion-sensor

I do get a perfect screen and if I click ā€œLaunch Reolinkā€ it dismisses the notification and does nothing. If I click the image or anything else, it lanuches ā€œReolinkā€.

Why am I backwards?

I would have thought it was the other way.

Maybe the confirm uri is wrong and should be ā€œapp://com.mcu.reolinkā€ ā€¦ testing.

It has to be an ā€œapp://ā€ link for confirm_uri (for first action button), just like you have done for notification_link (for clicking anywhere else)

You can refer to the documentation here for more details about deep linking.

Yes, I did see that and stated at the end I likely missed that.
I an now (unsuccessfully so far) trying to implement a notification that would have three ā€œactionsā€

  1. Launch Reolink (works)
  2. Dismiss (canā€™t figure that out)
  3. Open Gate (Runs a webhook or script ā€¦ can;t figure that out either)

Given what I posted, it would be interesting to tell me the YAML behind. The reason I want the YAML (and not just the GUI) is because I use this in an automation that depends on the camera and also uses parallel mode to send to multiple devices.

To create a dismiss action, just give the second action a label and assign no actions to it. That should do exactly what you require.

Iā€™ll try to give an example when Iā€™m at my computer after work!

This is the most basic example for your requirements
use_blueprint:
  path: samuelthng/notifications_beta.yaml
  input:
    confirm_text: Launch Reolink
    confirm_option_mode: uri
    confirm_uri: app://com.mcu.reolink
    dismiss_text: Dismiss
    option_three_enabled: true
    option_three_text: Open Gate
    option_three_action:
      - service: script.toggle
        metadata: {}
        data: {}
1 Like

Thank you @samuelthng, all working.
One question though or perhaps enhancement request.

On my phone the three options look great, are equally spaced (and are black):

On my Android tablet, the options are left aligned and do not take up all the space (and are red):

Is this expected? Or is there any way of controlling this? It looks to me like the Android tablet has room for four options and the Android phone only three and perhaps this is the issue.

Sadly, thereā€™s no way to control this as this is dictated by the Companion app (or the OS) rather than the blueprint.

It could be because one of the OS only limits up to 3 options while the other supports 10. I canā€™t remember which, but thatā€™s the primary reason why the script only supports up to 3 (highest common factor).

Understood. I was playing a bit yesterday as I use an automation which is triggered by motion at one of some cameras. I can template that as the message (which camera) and I can style that message in case you are not aware of that.

As in, this works:

field_message: A vehicle was detected at the Rio Crest <b>{{camera_location}}</b>

Where camera_location is the trigger_id:

variables:
  camera_location: "{{trigger.id}}"

Simple formatting like bold, italic, probably colors works (at least in Android for phone and tablet). It is not clear to me what formatting is allowed in message body and if any at all is allowed in the option text fields but I will test later today and see.

1 Like

To be clear, this is 90% of what I want. So close. This automation (I of course changed some device ids):

alias: Gate Vehicle Camera Alerts
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.rc_intercom_vehicle
      - binary_sensor.rc_intercom_person
    id: intercom
    from: "off"
    to: "on"
  - platform: state
    entity_id:
      - binary_sensor.rc_gate_vehicle
      - binary_sensor.rc_gate_person
    id: gate
    from: "off"
    to: "on"
condition: []
action:
  - parallel:
      - service: script.gate_vehicle_motion_detection
        metadata: {}
        data:
          field_notify_device: 9f8ff81591afdfdfdfgdffdgdfgdfdfg
          field_title: "{{reason}} at <font color='red'>{{camera_location|title}}</font>"
          field_message: >-
            A {{reason}} was detected at the Rio Crest
            <b>{{camera_location|title}}</b>
          field_subtitle: ""
          field_attachment_type: camera_entity
          field_attachment_camera_entity: camera.rc_{{camera_location}}_fluent
          field_timeout:
            hours: 0
            minutes: 2
            seconds: 0
          field_notification_link: app://com.mcu.reolink
          field_confirm_uri: app://com.mcu.reolink
      - service: script.gate_vehicle_motion_detection
        metadata: {}
        data:
          field_notify_device: fc4d03d44446c9fdgdfgfdgfgfgfgfddfgdf
          field_title: "{{reason}} at <font color='red'>{{camera_location|title}}</font>"
          field_message: >-
            A {{reason}} was detected at the Rio Crest
            <b>{{camera_location|title}}</b>
          field_subtitle: ""
          field_attachment_type: camera_entity
          field_attachment_camera_entity: camera.rc_{{camera_location}}_fluent
          field_timeout:
            hours: 0
            minutes: 2
            seconds: 0
          field_notification_link: app://com.mcu.reolink
          field_confirm_uri: app://com.mcu.reolink
      - service: script.gate_vehicle_motion_detection
        metadata: {}
        data:
          field_notify_device: 4f39f9ccf30dedfgddgdgffgdfg
          field_title: "{{reason}} at <font color='red'>{{camera_location|title}}</font>"
          field_message: >-
            A {{reason}} was detected at the Rio Crest
            <b>{{camera_location|title}}</b>
          field_subtitle: ""
          field_attachment_type: camera_entity
          field_attachment_camera_entity: camera.rc_{{camera_location}}_fluent
          field_timeout:
            hours: 0
            minutes: 2
            seconds: 0
          field_notification_link: app://com.mcu.reolink
          field_confirm_uri: app://com.mcu.reolink
variables:
  camera_location: "{{trigger.id}}"
  reason: "{{trigger.entity_id.split('_')[3] | title}}"
mode: single

And the script is:

alias: Gate Vehicle Motion Detection
use_blueprint:
  path: samuelthng/notifications.yaml
  input:
    notify_device: 9f8ff81591a093sdsddfdsfdsfdfsdsfsdfsdf
    title: Vehicle Detected at Intercom
    message: A vehicle was detected at the Rio Crest gate intercom
    icon: mdi:camera-iris
    confirm_uri: app://com.mcu.reolink
    confirm_text: Reolink
    confirm_option_mode: uri
    dismiss_enabled: true
    notification_link: app://com.mcu.reolink
    attachment_type: camera_entity
    attachment_camera_entity: camera.rc_intercom_fluent
    confirm_is_destructive: false
    timeout:
      hours: 0
      minutes: 2
      seconds: 0
    clear_on_timeout: true
    visibility: public
    icon_color:
      - 249
      - 6
      - 31
    dismiss_text: Dismiss
    dismiss_option_mode: action
    enable_icon_color: true
    option_three_option_mode: action
    option_three_action:
      - service: script.open_gate
        data: {}
    option_three_enabled: true
    option_three_text: Open Gate
icon: mdi:motion-sensor

So the message and such have formatting (Bold, red. etc/.) and is custom content via templates,.I tried today simplifying to templatize the devices to allow multiples and failed because of the timeouts.

Goal:

I have a sensor that has everyoneā€™s phone who is working at the winery.
A vehicle arrives at the gate of the winery, triggering this notification.
MIssing: I can write very simply, send then all a message in parallel for someone to respond to.

Now I only am missing the send to multiple devices which are dynamic and come for a sensor which is a list of staff that on duty as I do not want that sent to those not on duty.

I would guess I could ā€œscriptize thisā€:

      - service: script.gate_vehicle_motion_detection
        metadata: {}
        data:
          field_notify_device: 9f8ff81591afdfdfdfgdffdgdfgdfdfg
          field_title: "{{reason}} at <font color='red'>{{camera_location|title}}</font>"
          field_message: >-
            A {{reason}} was detected at the Rio Crest
            <b>{{camera_location|title}}</b>
          field_subtitle: ""
          field_attachment_type: camera_entity
          field_attachment_camera_entity: camera.rc_{{camera_location}}_fluent
          field_timeout:
            hours: 0
            minutes: 2
            seconds: 0
          field_notification_link: app://com.mcu.reolink
          field_confirm_uri: app://com.mcu.reolink

And pass in appropriate variables for each of the devices.

Hi thanks for this.
How many times will the trigger action repeat i.e. how many notifications will I receive?
In my case the notification suggests turning on the AC when the temp rises. If I dismiss, But donā€™t turn on AC and donā€™t want more notifications,how can I achieve that?

Exactly once.

It will only send one when an automation calls the script.

If you are receiving more than one, it would mean your automation is triggering it multiple times. You might want to check your conditions on the automation instead.

First, thanks for sharing this awesome blueprint.
I would like ask how I need to set to ā€œClear Notificationā€ works. And Iā€™m testing on iOS.
This is the configuration that Iā€™m using:

alias: Abrir PortĆ£o? - Pedro
use_blueprint:
  path: samuelthng/notifications.yaml
  input:
    run_timeout_actions: true
    notify_device: e747c67a3da0e8ea73a2bb65a42908a1
    title: Abrir / Fechar PortĆ£o
    message: Deseja abrir o portĆ£o?
    confirm_option_mode: action
    confirm_icon: lock.open.fill
    confirm_text: Sim
    confirm_action:
      - service: notify.mobile_app_pedrao_iphone
        data:
          message: Abre portĆ£o
    dismiss_text: NĆ£o
    dismiss_option_mode: action
    dismiss_action: []
    dismiss_is_destructive: true
    timeout:
      hours: 0
      minutes: 0
      seconds: 15
    clear_on_timeout: true
    dismiss_icon: lock.fill
    enable_timeout: true
description: ""

After the timeout ends, itā€™s triggered, but the notification still there. What did I do wrong?

I was looking around about this problem and I found this

The app need to be running on background to clear the notification on iOS. If the app isnā€™t running, the notification will not be cleared.

1 Like