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

✋🏼 Development Paused for 2024 😔

Version 2.0.1

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

:arrow_double_down: Latest Version | :link: Github Link | :male_detective:t2: Compare Changes

Forked from Home Assistant’s Confirmable Notifications


Features:

   📲 Sends notification to Home Assistant Companion

   :three: Up to 3 customisable, action buttons (Previously: :white_check_mark: Confirm and :x: Dismiss Button)

   ⌛️ Timeout actions with custom duration, fired if no option response received

   🧹 Clear notification after timeout

   📸 Camera Snapshots

   🔗 Custom Notification Link

   📜 Flexible script fields

   🍎 Supports iOS

   🤖 Supports Android


:bulb: Inspiration:

  • Easy to create actionable notifications with a timeout feature.
  • Simple script blueprint, to be used with other automations or scripts.
  • Compatible with iOS and Android.

:warning: Notes:

  • Use at your own risk, no guarantees provided; it’s my first publicly shared blueprint. :grimacing:
  • Instructions and explanations are provided for each input.
  • Requirements:
    • Home Assistant 2023.11.0 or newer
    • iOS: Home Assistant Companion 2023.4 or newer
    • Android: Home Assistant Companion 2023.8.2 or newer

:question: How To Use:

TL;DR
Create a notification script from this blueprint, then call the created notification script from other automations/scripts.

This blueprint is a script that makes configuration of notifications easier.
It is meant to be paired with a separate automation or script of your choosing.

Show/Hide: How to create a notification script
  1. Import this blueprint using the Import Blueprint links.
    Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

  2. Navigate to your blueprints dashboard:
    Open your Home Assistant instance and show your blueprints.

  3. Create a new script using the blueprint you’ve just imported by clicking on it:

  4. Give your new script a meaningful name, and configure your required features.
    Quick Example:

    • Name: “My Test Notification”
    • Device to notify: “My iPhone”
    • Message: “This is a test notification!”
  5. Click on Save Script to ensure your new script is created. Once your script has been created and saved, the Save Script button should slide out of your screen.

  6. Now, test that your script is working!
    You may do so from the dropdown menu found on the top right of your script’s configuration page.

  7. Optionally configure the other options based on your requirements.


Show/Hide: How to use this notification script from other automations or scripts
  1. Ensure that you have a working script that has already been configured.
    If you need help on creating your script, refer to the collapsible section above.

  2. Navigate to the automation or script that will trigger your notification.
    In the following examples, an empty automation will be used as a guide, feel free to tweak as required.

  3. Add an action, this action can be nested in other conditional actions if required, as per normal automation or script behaviour.

  4. Search for your script in the menu.

  5. You may now save your automation

  6. Test that your automation successfully sends the notification by running it manually.
    Similar to testing your notification script, you can run the automation actions manually without having any triggers or conditions checked.
    The actions can be run manually via the dropdown menu, on the top right of the configuration page.

  7. Feel free to modify your automation, or create as many as you require.


Examples:

When the last user leaves home, send a notification to last user:

Show/Hide: Simple leave home alert
  • Title: My Awesome Home
  • Message: Turning off lights and appliances in 5 minutes
  • First Action Text: Leave it on
  • First Action Action: Do nothing
  • Second Action Text: Turn off now
  • Second Action Action: Run turn off script
  • Timeout Duration: 5 minutes
  • Timeout Action: Run turn off script
  • Clear on Timeout: Clear Notification

Other examples:


:test_tube: Experimental Variants

Experimental variants are versions spun off to support specifically requested features.
These variants may or may not be merged to the main branch
These variants might affect stability of other core features.


Changelog and previous versions

Version 2.0.1 - 20 Dec 2023

:arrow_double_down: Import Version | :link: Github Link | :male_detective:t2: Compare Changes

  • Fixed: Custom Tag and Groups not being set properly.
See previous changelogs

Version 2 - 12 Dec 2023

:arrow_double_down: Import Version | :link: Github Link | :male_detective:t2: Compare Changes

Version 2.0 Changelog
  • Fixed: iOS showing Failed to load attachment
  • Refactor: Build payload in templates
  • Deprecated: 📲 Notification Strategy due to refactor.
  • Deprecated: 📲 Service to notify due to refactor.
  • Added: Support for fields
    • Added: 🏷️ Title field
    • Added: 💬 Message field
    • Added: 🏷️ Subtitle field
    • Added: 📸 Attachment: Camera Entity: Camera Entity field
    • Added: Options show/hide fields
    • Added: ⌛️ Enable Timeout and ⌛️ Enable Timeout Action(s) fields.
  • Added: 🚘 Show on Android Auto option.
  • Added: ⌛️ Enable Timeout Action(s) option and field.

Notes:

  • When enabling boolean fields with value of false, be sure to toggle them to true once, and then to false.
    There seems to be a bug where the boolean value is not passed if it’s enabled and value is false without the toggle.
  • If you rely on 📲 Service to notify, do not upgrade, Version 1.6.1 will be the last version supporting that feature.

Version 1.6.1 - 26 Oct 2023

:arrow_double_down: Import Version | :link: Github Link | :male_detective:t2: Compare Changes

  • Fixed: Camera Snapshots not showing

Version 1.6 - 26 Oct 2023

:arrow_double_down: Import Version | :link: Github Link | :male_detective:t2: Compare Changes

Version 1.6 Changelog
  • Added: Show/Hide options toggle
  • Added: URI action options and iOS specific action options
  • Added: Third option

Version 1.5 - 11 Oct 2023

:arrow_double_down: Import Version | :link: Github Link | :male_detective:t2: Compare Changes

Version 1.5 Changelog
  • Updated: Deprecated device selector
  • Added: Notification Attachments
  • Added: Notification Strategy
  • Added: Prefix for option icons
  • Updated: Blueprint descriptions

Version 1.4 - 7 Jul 2023

:arrow_double_down: Import Version | :link: Github Link | :male_detective:t2: Compare Changes

Version 1.4 Changelog
  • Reverted: Send clear notification command - for iOS compatibility.
  • Added: subtitle, group, visibility.
  • Refactor: tag is no longer recommended, will use entity_id by default.
  • Fixed: During a timeout, the script throws error into logs due to checking attribs of None type.

Version 1.3.2 - 28 Jun 2023

:arrow_double_down: Import Version | :link: Github Link | :male_detective:t2: Compare Changes

Version 1.3.2 Changelog

Known Issues:

  • iOS Notifications do not respect Clear after Timeout, issue since version 1.3, slated for fix in version 1.4 (Mid July)
  • Scripts created from blueprint always defaults to mode: single, bug raised with Home Assistant and fixed, hopefully this will be resolved in future releases.
    Update your instances manually if you’re facing any issues with sending multiple notifications within your timeout duration.

Version 1.3.1 - 10 Jun 2023

:arrow_double_down: Import Version | :link: Github Link | :male_detective:t2: Compare Changes

Version 1.3.1 Changelog
  • Fixed: Enable Icon Color
  • Updated: Icon Color hex template

Version 1.3 - 9 Jun 2023

:arrow_double_down: Import Version | :link: Github Link | :male_detective:t2: Compare Changes

Version 1.3 Changelog

Again, thanks to joe.cole1 for the insights in this minor release.

Also, thanks to RemyyB for identifying the incorrect variable and raising a PR, sorry for taking a week to fix this.

(:crossed_fingers:t2: Color picker is easy enough to configure, so it shouldn’t be absolutely breaking to warrant a major)


Version 1.2 - 30 May 2023

:arrow_double_down: Import Version | :link: Github Link | :male_detective:t2: Compare Changes

Version 1.2 Changelog

Version 1.1 - 25 March 2023

:arrow_double_down: Import Version | :link: Github Link | :male_detective:t2: Compare Changes

Version 1.1 Changelog
  • Updated: Clear on Timeout as boolean field
  • Fixed: Persistent notifications not working
  • Fixed: Clear on Timeout did not clear if a timeout happened

Version 1.0 - 24 March 2023

:arrow_double_down: Import Version | :link: Github Link

Version 1.0 Changelog
  • Initial Release
25 Likes

Thanks for sharing

1 Like

Thanks for sharing I will give it a try!

This is very nice and very clean!

Only feature I would like to see is the ability to notify a group of mobile devices instead of one individual. It’s not a big deal to set up 2 scripts for myself and my wife, but it would be slightly easier to be able to use a notify group.

Thanks! I love the timeout feature.

Edit: I modified and created my own version based off of this. I added the ability to choose a notify service in order to send the same notification to my notifcation groups. I also added a notification icon and icon color (Android only)

blueprint:
  name: My Notifications
  description: Forked from v1.1 of https://github.com/samuelthng/t-house-blueprints/blob/main/notifications.yaml
  domain: script
  input:
    notify_device:
      name: "Notify service (use 'notify.*'. Create a group for multiple)"
      description: Device needs to run the official Home Assistant app to receive
        notifications.
      selector:
        text:
            type: search
    title:
      name: "Title"
      description: The notification title.
      default: ''
      selector:
        text: {}
    message:
      name: "Message"
      description: The notification message body
      selector:
        text: {}
    icon:
      name: "Icon (Android Only)"
      selector:
        icon: {}
    icon_color:
      name: "Icon Color (Android Only, hex or color name)"
      selector:
        text: {}
    confirm_text:
      name: Confirmation Text
      description: Text to show on the confirmation button
      default: Confirm
      selector:
        text: {}
    confirm_action:
      name: Confirmation Action
      description: Action to run when notification is confirmed
      default: []
      selector:
        action: {}
    dismiss_text:
      name: Dismiss Text
      description: Text to show on the dismiss button
      default: Dismiss
      selector:
        text: {}
    dismiss_action:
      name: Dismiss Action
      description: Action to run when notification is dismissed
      default: []
      selector:
        action: {}
    timeout:
      name: Timeout Duration
      description: Amount of time to wait for a confirm/dismiss response before firing
        timeout action.
      selector:
        duration:
          enable_day: false
    timeout_action:
      name: Timeout Action
      description: Action to run when notification response is timed out.
      default: []
      selector:
        action: {}
    tag:
      name: Tag
      description: Used for unique identification of the notification. Must not use underscores.
      selector:
        text: {}
    clear_on_timeout:
      name: "Clear notification on timeout - ⚠️ Tag Required"
      description: Dismiss the notification after action selection times out.
      default: leave_notification
      selector:
        boolean: {}
    persist:
      name: "(Android Only) Persistent Notification - ⚠️ Tag Required"
      description: Ensures that notification cannot be dismissed by swiping away.
      default: false
      selector:
        boolean: {}
    channel:
      name: (Android Only) Notification Channel
      description: Defines the channel, to be used with Importance. Relates to the
        importance of the notification.
      default: General
      selector:
        select:
          options:
          - label: General
            value: General
          - label: Alarm
            value: Alarm
          - label: Brewery
            value: Brewery
          - label: Door
            value: Door
          multiple: false
          custom_value: true
    importance:
      name: (Android Only) Notification Channel Importance
      description: https://companion.home-assistant.io/docs/notifications/notifications-basic/#notification-channel-importance
      default: default
      selector:
        select:
          options:
          - label: Urgent (Makes a sound with heads-up notification)
            value: high
          - label: Default (Makes a sound)
            value: default
          - label: Silent (Makes no sound)
            value: low
          - label: Low (Makes no sound, doesn't appear in status bar)
            value: min
          multiple: false
          custom_value: false
    interruption_level:
      name: (IOS Only) Interruption Level
      description: https://companion.home-assistant.io/docs/notifications/notifications-basic/#interruption-level
      default: active
      selector:
        select:
          options:
          - label: Silent (Makes no sound, does not wake screen)
            value: passive
          - label: Default
            value: active
          - label: Important (Overrides Focus)
            value: time-sensitive
          - label: Critical (Overrides Focus and Mute, restricted features)
            value: critical
          multiple: false
          custom_value: false
mode: restart
sequence:
- alias: Set up variables
  variables:
    action_confirm: '{{ ''CONFIRM_'' ~ context.id }}'
    action_dismiss: '{{ ''DISMISS_'' ~ context.id }}'
    clear_on_timeout: !input clear_on_timeout
    persist: !input persist
- alias: Send notification
  service: !input notify_device
  data:
    title: !input title
    message: !input message
    data:
      actions:
      - action: '{{ action_confirm }}'
        title: !input confirm_text
      - action: '{{ action_dismiss }}'
        title: !input dismiss_text
      tag: !input tag
      notification_icon: !input icon
      color: !input icon_color
      persistent: !input persist
      timeout: !input timeout
      channel: !input channel
      importance: !input importance
      push:
        interruption-level: !input interruption_level
- alias: Awaiting response
  wait_for_trigger:
  - platform: event
    event_type: mobile_app_notification_action
    event_data:
      action: '{{ action_confirm }}'
  - platform: event
    event_type: mobile_app_notification_action
    event_data:
      action: '{{ action_dismiss }}'
  timeout: !input timeout
  continue_on_timeout: true
- choose:
  - conditions: '{{ wait.trigger.event.data.action == action_confirm }}'
    sequence: !input confirm_action
  - conditions: '{{ wait.trigger.event.data.action == action_dismiss }}'
    sequence: !input dismiss_action
  - conditions: '{{ wait.trigger == none }}'
    sequence: !input timeout_action
- if:
  - alias: Clear Notification Enabled
    condition: template
    value_template: '{{ clear_on_timeout == true }}'
  then:
  - alias: Send notification
    service: !input notify_device
    data:
      message: "clear_notification"
      data:
        tag: !input tag
2 Likes

Where should I set the condition ?
I want to send a notification if my garage door is open for more than 2h or if it’s any time after 10pm.
Thank you.

@ablyes this is just a script that you need to call from something else. So in your case, create an automation with triggers for garage door state open for 2 hours and another trigger for after 10pm with condition garage door open. Then in the action, you would simply call this script that you created and saved.

Super easy!

Makes sens. It’s working fine now :slightly_smiling_face:
Why is the iOS notification so tricky ? I have to click on it for 3 sec to see the actions.

Can we enhance the human interaction ? Like a click on the notification that show the big button to do the action if we miss the 3 sec ?

@ablyes Sadly it’s the default behaviour of the companion app :frowning:
My wife has the same complaint… :sob:

Maybe it would be wise for the notification to open HA instead when it is clicked.

Thank you for sharing your changes! Have added a link to your comment under the forks subheader, and will review the changes to be added in future versions!

P.S. may take awhile, got a bad case of COVID :frowning:, will do testing and changes after I’m back.

Sounds good! I’m certainly no power user, so I’m sure it could be done better.

Another frustration I have that I don’t see a way to fix is the timeout function.

If you don’t clear the notification on timeout, the action buttons no longer work. But a timeout is required, so you either have to set a very long timeout (for example 24 hours) and don’t clear the notification, or you have to use a timeout action.

I think the answer for me is going to be create a blueprint without the timeout functionality for when I don’t need it, but I was curious of your thoughts.

Edit: For now I’ve created another blueprint without any timeout functions. I’m sure there’s a way to set a variable to either use or not use the timeout function if it’s set, but I don’t have the know-how to do that!

That’s a good point that I did not face in my use case.

I’ll have to do some digging into the docs to see if we can use some data payloads when triggering the script.

It’s a great suggestion and valid use case, I’ll add that to the list of things to think about! :+1:t2:

Maybe just to help me understand better, could you go into a little more detail for your use case? The ideal flow you’re expecting the script to be capable of, and the context would be helpful!

Sure thing!

I have this triggered from my garage door opening. I have it set to persistent, with the actions being Close Door and Dismiss.

I don’t want the notification to timeout, and there’s no action I want to perform after a timeout.

So I left timeout action blank and timeout time set to the default, 0.

The problem is the actions didn’t work, as it would see that as timing out immediately and the “triggered by” would run with the timeout action (none)

So my other action buttons didn’t work, as the timeout action already “ran” and the script was no longer listening for the other actions.

:partying_face: Update: Version 1.2

  • Added: Icon and Icon Color options for Android, big thanks to @joe.cole1 for adding it!
  • Added: Option to enable or disable the timeout.
    • For cases where command buttons should work indefinitely.
    • :warning: When enabled, will not trigger Timeout Actions.

I’m glad to say the changes this time are all backwards compatible.

How to update:

Before Home Assistant Core 2023.12:

  1. Replace blueprint file at config/blueprints/script/samuelthng/notifications.yaml with intended version.

  2. Reload your scripts on the Developer Tools Yaml page, or use this button:
    Open your Home Assistant instance and show your service developer tools with a specific service selected.

  3. Check your scripts!
    It should show the new options and trigger properly if the upgrade went well.

After Home Assistant Core 2023.12:

  1. Simply import the version you’d like (look out for this icon: :arrow_double_down:)
2 Likes

This is an amazing blueprint, thanks a lot for sharing!

How is Timeout supposed to work on iOS? I’m setting tag, timeout action and timeout duration but the action is never triggered

Looks like clear_on_timeout is not properly initialized so turning it off and back on fixed the issue.

Changing line 131 from

default: "leave_notification"

to

default: true

Fixes the variable and creating a new notification executes the timeout action correctly

EDIT 2: I see you already had a PR for this issue, nice!

2 Likes

Good eye! Yeah I missed that in the initial commit, should be fixed after V1.1

1 Like

@samuelthng I have a few other ideas I’d like to see about implementing. Namely a clickAction so that if you tap on the notification it opens a URL/navigates to a specific spot in the app.

It’s a simple call under data, in the same spot as the icon and color. Unfortunately, it’s named clickAction for Android, and just url for iPhone… so there’s probably not a good way to implement this universally and easily.

clickAction: "lovelace/home" #Android
url: "lovelace/home" #iPhone

Another idea I had is in regards to timeouts.

I had a weird case today where the timeout occurred when my phone was without reception. It did not receive the clear_notification notification from the automation timing out, so the notification remained even though the script had already timed out.

It might be a bit cleaner to include the following in the notification itself if timeout is enabled. That way the app on the phone removes the notification instead of relying on home assistant to send a clear_notification to the device. This is also under data: in the notification setup and would only be set if clear_on_timeout and timeout_duration are both set.

timeout: 600 # How many seconds the notification should be received by the device

I’ve had a few different blueprints for notifications and this has quickly become my favorite by far!

2 Likes

Great suggestions yet again! Yeah we could probably work those in.

We might still need the current timeout just for the sake of triggering timeout action HA side, but using the same timeout variable.

I’ll give it some brain cell time :joy:

2 Likes

Exactly. I didn’t come up with a clean solution myself… I’m more of an ideas guy!

Eventually it could get so complicated you might as well just copy and paste all the code anyway! :stuck_out_tongue:

:partying_face: Update: Version 1.3

Again, thanks to joe.cole1 for the insights in this minor release.
Also, thanks to RemyyB for identifying the incorrect variable and raising a PR.
Sorry to everyone for taking a week to fix this. 🙇🏻‍♂️

(:crossed_fingers:t2: Color picker is easy enough to configure, so it shouldn’t be absolutely breaking to warrant a major)

How to update

Things to check after updating:

  • Clear Notification is correctly set/unset
  • Icon Color and Enable Icon Color are correctly set/unset
  • All scripts using this blueprint are loaded in the scripts list
    • If they are missing, don’t worry, do drop a message here with me tagged and we’ll get it fixed.
1 Like

Usage Example: Notification script for Home Assistant Core Updates

This script would notify the user that a new update is available, with an option to call the update service, or the skip update service.

Upon clicking the notification - not the action buttons - it will navigate the user to the Home Assistant updates page.

If nothing has been selected for 30 minutes, the notification will be cleared automatically without taking any actions.

Code
notify_home_assistant_core_update:
  alias: "\U0001F514 Home Assistant Core Update Notification"
  use_blueprint:
    path: samuelthng/notifications.yaml
    input:
      notify_device: <my_device_entity_id>
      title: My Awesome Home
      message: New update available!
      timeout:
        hours: 0
        minutes: 30
        seconds: 0
      tag: ha_core_update
      clear_on_timeout: true
      notification_link: /config/updates
      icon: mdi:archive-arrow-up
      enable_icon_color: true
      icon_color:
      - 98
      - 234
      - 125
      confirm_text: Update Now
      confirm_action:
      - service: update.install
        data:
          backup: true
        target:
          entity_id: update.home_assistant_core_update
      dismiss_text: Skip
      dismiss_action:
      - service: update.skip
        data: {}
        target:
          entity_id: update.home_assistant_core_update