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

@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

:beetle: Bugfix: Version 1.3.1

This is an Android only fix, iOS users may ignore this patch.

  • Fixed: Enable Icon Color - No longer overrides icon colour if disabled.
  • Updated: Icon Color hex template - Remove unrequired code, minor change.

Apologies for the frequent update - similar bug to last time, incorrect flag for Enable Icon Color.

How to update

Things to check after updating:

  • Scripts with Enable Icon Color disabled, should not override icon colour on Android phones.
  • As per usual, existing scripts should be loaded.
2 Likes

:new: iOS Action Icons: Version 1.3.2

Fine to ignore if you donā€™t need icons for iOS, and wonā€™t be creating new scripts anytime soon.

How to update

Things to check after updating:

  • As per usual, existing scripts should be loaded
  • Script should show Version: 1.3.2

Known Issues:

  • iOS notifications do not respect Clear on Timeout since Version 1.3
    Version 1.4 beta testing is underway, to ensure Iā€™ve covered enough use cases before releasing - estimate mid of July.
1 Like

For your issues with iOS clear on timeoutā€¦ I donā€™t have apple devices so I canā€™t test, but with my modifications to use notify. groups instead of individual devices, I needed to add back in your old style of clearing notifications so that when one device chose an action or dismissed it would do so on all devices. So my modified blueprint has both the ā€œbuilt into the notificationā€ dismiss function as well as your older timer based clear notification.

Works great! That might be a good solution to cover all bases.

Yup thank you for the suggestion, thatā€™s also exactly what I did! Just wanted to test ithe changes extensively before the next release.

Thereā€™s also be some additional features coming up!

1 Like

:new: iOS Action Icons: Version 1.4

Fine to ignore if you donā€™t use iOS, new additions are optional.

  • iOS/macOS: Notifications will now clear after timeout
  • Added Subtitle, Notification Grouping, Lockscreen Visibility options, details in blueprint label.
  • šŸ·ļø Tag is no longer required for some features to work.
  • During a timeout event, the script throws error into logs even when working properly, this is now fixed.

How to update

Things to check after updating:

  • As per usual, existing scripts should be loaded.
  • Script should show Version: 1.4.
  • You may clear the tag field if you have added one previously
    It is no longer required unless using the script for complex cases.

Known Issues:

There is at least one case where a user is unable to receive notifications on their iOS device
The issue is not reproducible on my end, but is probably due to an optional feature.

If this is happening to you, you may try to use an older version of the blueprint.
Known working version: Version 1.0

good job to both.
What should I change to use another service, i.e. pushover, if already integrated in HA?
This is an example I use for Internet disconnection:

Sorry for the italian language but itā€™s pretty clear.
Thanks

Iā€™m assuming youā€™re trying to call another action besides sending the notification alert?

If so, you have a couple of options:

  1. You may simply add another action just like in this example below:

    This applies to all action fields.

  2. You may store all the actions you want into a separate script, then call the single script youā€™ve created to trigger all actions. The best part about this is it allows you to house more complex logic into that script and to compartmentalise functionality on your setup.