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

Sorry, the problem was about “continue on timeout”

This is my proxy script.

It runs 3 times, the first is fired immediately, the other two at 20 seconds of delay.
If the answer is YES, dummy toggle is switched off
If the answer is NO the cycle continues
If there are no replies after three messages, dummy toggle is switched off

alias: Retry Notifications
sequence:
  - service: script.1709625314536
    metadata: {}
    data: {}
    response_variable: response
  - delay: "00:00:20"
  - condition: template
    value_template: "{{ is_state('input_boolean.dummy_toggle', 'on') }}"
  - service: script.1709625314536
    metadata: {}
    data: {}
    response_variable: response
  - delay: "00:00:20"
  - condition: template
    value_template: "{{ is_state('input_boolean.dummy_toggle', 'on') }}"
  - service: script.1709625314536
    metadata: {}
    data: {}
    response_variable: response
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ response is defined }}"
          - condition: template
            value_template: "{{ response.result == 'option_one' }}"
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.dummy_toggle
            data: {}
          - stop: User has responded
      - conditions:
          - condition: template
            value_template: "{{ response is defined }}"
          - condition: template
            value_template: "{{ response.result == 'option_two' }}"
        sequence:
          - stop: User has responded
      - conditions:
          - condition: template
            value_template: "{{ response is not defined }}"
        sequence:
          - service: input_boolean.turn_off
            target:
              entity_id: input_boolean.dummy_toggle
            data: {}
mode: single
fields: {}

Thank you!!

1 Like

Is it possible to add the ability to set the volume of the critical notification on iOS?

Could this be expanded to use other notification types such as Hass Agent or Fire TV notifications?

Hello @NateUT,

I’ve just pushed my local copy where I’ve been testing this change.
This is neither a release or pre-release due to the refactoring of payloads, so use at your own risk.

Do be sure to test your scripts before going about your day, won’t want to miss a notification!
Also be sure to set the Interruption Level to Critical for the volume options to be applied.

Version 2.0.2 Beta 2 - 23 March 2024

  • Added: Field for notification_link. #26 (Thanks to HNKNTA)
  • Fixed: Field enable_timeout.
  • Added: response_variable with payload and response.
  • Added: Android High Priority Notifications :link:
  • Added: iOS Critical Notifications Volume :link:
  • Updated: mode: parallel :link:
  • Refactor: Device specific payloads are now evaluated separately for future alternative device support :link:
  • Added: Optional Server URL input :link:

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

1 Like

Hey @Krispkiwi,

I have currently no plans to add other types of notification services as it will be difficult to maintain those payloads alone.

Hoever, in the above beta, I’ve refactored the code such it will be easy to add on support for those devices if you are able to:

  1. Identify the type of payload required for a given device
  2. Write a payload builder for the given device

I personally do not use either Hass Agent nor Fire TV, so any help will be greatly welcome!

Well, I am close but I cannot get any camera image in the notification.
This is the YAML I have:

alias: 🔔Send Motion Notification
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
icon: mdi:motion-sensor

The resulting notification is (no snapshot on the message):

Launching the Reolink app works perfect.

If I “build the URL” I would suspect it should be (NOTE: I use Nabu Casa as this is a remote Home Assistant), I get the image no problem:

https://xxxxxxxxxxxxxxxxxxxxxxxxxx.ui.nabu.casa/api/camera_proxy/camera.rc_intercom_fluent?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

A few words about what I am trying to do … I have a gate that is about 1 mile away from my winery. I want a notifications to folks when someone hits the gate. Home assistant exists in both places (winery and gate) but they are completely different systems even on different ISPs because of services that are available at the locations. Winery is on Starlink, gate is AT&T 5G so different routers, etc. And Home Assistant installed in both locations.

If the notification has something like “show image from local home assistant” that will not work, because the “viewer” might have Companion pointed to the winery. I would note that in examining the trace, I see this (token x’d out):

notification_data:
  apple_device: false
  subject: ''
  visibility: private
  importance: default
  priority: high
  ttl: 0
  clickAction: app://com.mcu.reolink
  image: >-
    /api/camera_proxy/camera.rc_intercom_fluent?token=xxxxxxxxxxxxxxxxxxxxxxxxxxx
  notification_icon: mdi:motion-sensor
  channel: General

So does this mean that the notification arrives on the phone and the Companion app goes to “/api/camera_proxy/…” to get the image. If this is true, then I can understand why I get no image because my companion app is pointed to the Winery and not the Gate (completely different Nabu Casa URLs and the cameras are at the gate, not at the winery).

Note I am using the latest blueprint “Notifications (Version 2.0.2 Beta)”

OR … is their some limit on the image size? I would note this is a dual lens Reolink camera so the image is 1536 x 576

Update: I have diagnosed and this is a correct statement:

… the notification arrives on the phone and the Companion app goes to “/api/camera_proxy/…” to get the image.

I had been testing with my phone pointed at the Winery, I changed the Companion App server to point at the Gate and lookie, lookie (I get an image like I want in the notification):

Unfortunately that is not acceptable as a solution because it means people need the companion app pointed to the Gate when at the Winery. And therefore could not control lights/music/etc. So I believe an option needs to be made for the image to be a full URL to a remote server.

I would think this should be modified, accepting like an input_boolean for internal (default) or external… If external, the link for the image should be built with some user-provided external server (assuming this works but I would think it would unless the companion app notification cannot deal with absolute URLs):

  - alias: Attachments
    variables:
      script_attachment_type: !input attachment_type
      attachment_type: "{{ iif(field_attachment_type is defined, field_attachment_type, script_attachment_type) }}"
      script_attachment_camera_entity: !input attachment_camera_entity
      attachment_camera_entity: "{{ iif(field_attachment_camera_entity is defined, field_attachment_camera_entity, script_attachment_camera_entity) }}"
      camera_image_url: >-
        {% if (attachment_camera_entity|length) %}
          {% if (state_attr(attachment_camera_entity,'entity_picture')|length) %}
            {{state_attr(attachment_camera_entity,'entity_picture')}}
          {% else %}
            {{"/api/camera_proxy/{id}".format(id=attachment_camera_entity)}}
          {%- endif %}
        {%- endif %}
      media_url: >-
        {{
          {
            'none': '',
            'camera_entity': iif(camera_image_url | length, camera_image_url)
          }.get(attachment_type)
        }}

As in:

variables:
  ...
  script_camera_remote: !input attachment_remote
  script_attachment_remote_server: !input attachment_remote_server
 ...

And then build the URL depending on whether you need an external HA camera source or an internal HA camera source. Given this from the notification service, I would think remote connections work as the first example is an absolute URL:

automation:
  - alias: Notify Mobile app attachment
    trigger:
      ...
    action:
      - service: notify.mobile_app_<your_device_id_here>
        data:
          message: "Something happened at home!"
          data:
            # an example of an absolute url
            image: "https://github.com/home-assistant/assets/blob/master/logo/logo.png?raw=true"
            # example of a relative url
            image: "/media/local/image.png"
            # the same works for video
            video: "/media/local/video.mp4"
            # and for audio
            audio: "/media/local/audio.mp3"

This makes it even more evident that that URL sent to the notification service is a relative URL and not an absolute URL.

One note: I tried with no success to do things opposite. Since I use the Remote Home Assistant integration to link the two together, I can trigger the script/automation locally on the Winery Home Assistant. Good start but no bueno, I cannot get the image from the remote camera … images do not work from cameras in Remote Home Assistant AFAIK.

I could come up with an optional text input to override relative links for the camera stream and see if that resolves your issue.

Could you also try if the same is happening on relative links to Lovelace dashboards? The same solution should work in that scenario as well and we could have a go to fix it as well in a beta.

The “dashboard” names are different in the two servers so what is sent through with “gate”, does not work if received on “winery”. Of course app launching works as the app is local to the phone and not dependent on the notification sender,

Just my thoughts, but it would need to be constructed and not a complete override. I am sure you know this but just pointing out that the token changes.

So therefore, I would see it like

use relative or absolute?
If relative, you already have this code
if absolute, prepend the input_text server URL to it

I would consider this as an edge case since this is an issue due to two remote instances.

So I would assume in either case, internal and external, you’d want to force the url to always point to a single instance of the target server.

Is this the wrong assumption?

Hey @kbrown01 one other question, it should work just fine if the notification script was executed from the gates instance of HA. Is there a limitation to your scenario preventing that option?

Perhaps I do not understand but the execution script is (of course) executed at the gate HA instance. IMHO … The gate instance script builds the notification and it uses relative URLs to do it. That notification is through Android and can be received by that Android phone. BUT … if that phone’s Android Companion App’s current server is not the sending one, no image. As in:

The script runs at the gate HA.
The script attaches “/whatever” to the Android notification as the image source.
The recipient (if their Companion app) is pointed to the gate sees the image.
The recipient (if their Companion app) is pointed to the winery does not see the image.
If the recipient received a notification to “https://blah/blah/blah” it should work (untested but according to the documentation the URL can be absolute).

Which makes total sense to me. The relative URL does not work because it is relative to the current Server in the Companion app. And of course, the relative URL derived from a remote instance is not relevant to the home instance.

That is exactly my test above.

And to answer the other question, I would be happy with a simple “prepend this to to URL” field. But there are other issues that possibly would need to be tested. This is not exactly correct I think:

So I would assume in either case, internal and external, you’d want to force the url to always point to a single instance of the target server.

I want it always to be absolute. Not any old server, but the server in which it is run. Because afterll, that is where the camera is and that is where the token makes sense. It is subtle but could be important and could possibly break things … I can only fork the code and test it and try I guess.

Edge? Perhaps. But we live on a two HA instance scenario. I could always write it sans blueprint which I guess I will need to do unless this is considered valuable.

Okay so according to your reply, my understanding is correct, maybe just confusion due to the terms used. No problem, I could churn out a simple input to prepend the URL. :+1:t2:

Do allow me some time, Sunday is a no work day for me. :joy:

No issues. It is the only thing that I do not get from this and the image would be killer.

Not knowing the entire implementation, it is likely not possible that it could be a simple boolean (use absolute or relative) …

It could be some Nabu Casa address.
It could be some other DuckDNS address.
It could be some local address

… I do not think you could actually guess at what it should be … so you are 100% correct it comes down to “prepend this”

No worries, I’ve tried to write a custom one where i can customize the message, title action etc in automations but I’m getting stuck when it comes to successfully referencing the fields for some field types.
Text and notification icons appear to work with “{{insertfieldvariablekeynamehere}}” in the sequence however booleans, rgb colour, and select types don’t.

Can anyone with more knowledge than me take a read over and let me know where I’m going wrong. I can’t find documentation on this.

service: notify.mobile_app_samsung_galaxy
data:
  message: "{{message}}"
  title: "{{title}}"
  data:
    notification_icon: "{{notification_icon}}"
    color: "{{colour}}"
    persistent: "{{persistent}}"
    tag: "{{tag}}"
    channel: "{{channel}}"
    importance: "{{importance}}"
alias: Send a notification to Richard's Samsung Galaxy

For colour, you can copy the snippet in my blueprint. The shape of the data being passed in the template matters.

I have a 1 liner designed for converting the RGB selector to the data shape required by the colour parameter.

Yeah I was trying to follow it to replicate, is it this part or the whole thing “{% endif %}\n {%
if enable_icon_color %}{% set p.d = dict(p.d, **{ ‘color’: icon_color_hex })”

That’s a part. I like to create a namespace because we can modify variables easily in a namespace.

The part you’ve copied is modifying the namespace p.

So you’d have to create the namespace before this part, and then return p.d as the result to be stored in the variable.

Edit: Actually, rather than this, you’d need the template used in icon_color_hex.

So something like
variable:
icon_color_hex: ‘{{ “#{:02x}{:02x}{:02x}”.format(icon_color_selector[0], icon_color_selector[1], icon_color_selector[2]) }}’

then in the notification
color: !input !icon_color_hex?

Just FYI, I have tested this in a simple script and I can confirm it works as expected (sensitive data x’d out but you get it). Prepending the address sends the image no matter what server my Companion app is pointed to). Simple automation added where the camera_location is passed in from one of the cameras (“gate”, “intercom”, “driveway”, …) as the trigger.id to send a notification with image from the proper camera. Now just adding multiple phones and all is wonderful although I would like it to be in the blueprint as I would use it for other things.

alias: Test Send Image
variables:
  server: https://xxxxxxxxxxxxxxxxxxx.ui.nabu.casa
  camera_location: gate
  camera_entity: camera.rc_{{camera_location}}_fluent
  image: "{{state_attr(camera_entity,'entity_picture')}}"
  camera_name: "{{state_attr(camera_entity,'friendly_name')}}"
  phone: kevin_phone
sequence:
  - service: notify.mobile_app_{{phone}}
    data:
      message: Current Status of {{camera_name}}
      data:
        image: "{{server}}{{image}}"
mode: single

Yup, remember to assign your selector value to a variable before hand.

In the notification it’ll just be color: "{{ icon_color_hex }}"