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

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

Oh thatā€™s a bummer, it used to work fine on my wifeā€™s iPhone.

Iā€™ll look into it when I next work on the script!

I just recalled, thereā€™s a known case where timeouts causes a bug in the script that Iā€™ve yet to address.

You can do a check on traces, just in case the script failed silently.

I have a strange issue. It seems if I create a new notification it tends to work. If I make any changes to the script afterwards, it stops working and logs the following:

ā€œThe length of [apns-collapse-id] header must not exceed [64] bytes. This message is generated externally to Home Assistant.ā€

It doesnā€™t really matter what I then change hereafter, I can strip it of any actions, camera entity, etc. it still fails.

Below is an example notification script. Any idea what I might be doing wrong here? Thanks.

alias: Notify MIC - Garage door opening
use_blueprint:
  path: samuelthng/notifications.yaml
  input:
    notify_device: 09340e0b2a2f10f30fa447f79aa45932
    title: Garage
    message: Garage door 1 opening
    confirm_text: Close garage door 1
    confirm_option_mode: action
    confirm_action:
      - service: cover.close_cover
        metadata: {}
        data: {}
        target:
          entity_id: cover.garage_port_1_garage_door
    dismiss_action: []
    dismiss_enabled: false
    attachment_type: camera_entity
    attachment_camera_entity: camera.driveway
description: ""```

@mickeynygaard, it might not be due to your configuration. I suspect it might be a compatibility issue with the new collapsible sections feature.

Iā€™ll have a look into this soon, overseas this year for work.

Uh, ok - Thanks for clearing that up. Appreciate your efforts, really a cool blueprint :ok_hand:

Thank you so much for this blueprint! Unfortunately, itā€™s not working in my case. I am using HA 2024.8.2, but I didnā€™t get any notifications via the mobile app. If I send a custom notification manually, the notification is working fine. Do you have any ideas what could be the issue here? Iā€™d really appreciate your help!

You should include whatever error is in the system log.
Most likely youā€™re running into the same error as me.

I have two major usecases but Iā€™m not sure if this blueprint can handle it. So any hints are welcome :slight_smile:

1:
I want to sent a notification to all mobile apps (of my family) if e.g. the front door is open to long. So someone need to go and close the door.
In this case I want to periodically (re)sent the notification as long as the door is open but let the notifcation disappear on all mobile devices as soon as the door has been closed.
Currently I donā€™t know how to a) setup the resent part and b) call the script to make the notification disappear (clear).

2:
If e.g. the washing maschine is ready I want to sent a notifcation with an ā€œI took the laundryā€-action. As soon as someone pressed this action I want the notification to disappear from all devices.
In this case I donā€™t know how to make the action sent the clear message.

Hello @Eimeel, The script is primarily focused at sending message to 1 device.

You can achieve the following by calling the script through other automations with helpers.
Since the second use case is simpler, let me use that as an example.

You could have an automation triggered by the washing machine that does the following:

  1. If washing machine is done, trigger all scripts (1 notification script per device)

  2. Save the response of each script into variables (response.result will be set if option selected)

  3. Wait for a timeout

  4. After the timeout, check all of the variables if anyone has responded.

  5. If someone has responded, you may optionally send a clear command to all devices.

  6. If nobody has responded, send the notification again.

Youā€™ll need quite a bit of templating magic to get this to work, but itā€™s possible to do it without any helpers or python script.

I would like to take this chance to let everyone know, I have been on a haitus due to a really hectic year.
Will need some more time before I can continue with my hobbies. :cry:

Apologies for any inconvenience caused.

2 Likes

For #1 you can use this example:

alias: Upstairs Bathroom Door Left Open
description: ""
mode: single
triggers:
  - entity_id:
      - binary_sensor.upstairs_bathroom_door_contact
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 30
    trigger: state
conditions:
  - condition: state
    entity_id: binary_sensor.cat_room_door_sensor_contact
    state: "on"
actions:
  - alias: Repeat the sequence UNTIL true
    repeat:
      sequence:
        - data:
            title: Upstairs Bathroom Door Was left Open
            message: Rajah might be in the Upstairs Bathroom
            data:
              push:
                sound:
                  name: default
                  critical: 0
                  volume: 1
          action: notify.all_ios_devices
        - data:
            target: media_player.sonos_1_right_side
            data:
              type: tts
            message: Upstairs Bathroom Door is Open
          action: notify.alexa_media
        - delay:
            minutes: 1
      until:
        - condition: state
          entity_id: binary_sensor.upstairs_bathroom_door_contact
          state: "off"
1 Like

Hello, just wanted to say thanks for the great blueprint, itā€™s ticked all the boxes I needed, and this bit of info was the last little key! My only suggestion would be it took me a while to find this info about accessing the screenshot, so it would be great if this was in the main instructions/documentation as well as for camera applications I feel like this would be common. Thanks again! :slight_smile:

Edit: Should have kept reading, Iā€™ve run into the same issue with the token expiring after restart. It would be great to be able to access a larger image from the notification one day. :slight_smile:

1 Like

Is it possible to use a custom sound for iOS notifications?

You can try this branch by pedropaislopes:

Full credits to pedropaislopes. Not merging to main for reasons, Iā€™ve got a few changes stashed that includes this but isnā€™t ready for production.