Actionable notifications for Android w/ Cam Snapshot

This Blueprint is a remix of vorion’s Actionable notifications for Android located here:
:bell: Actionable notifications for Android

I modified their Blueprint so I could repurpose it for my Amcrest Doorbell. This should work with other camera entities and sensors as needed.


(Yes, I realize I have a typo in my screenshot above :slight_smile: )

Requirements

  • Home Assistant app on your Android phone
  • Camera entity to display in the notification

Notes

I tweaked a few things from vorion’s original Blueprint including:

  • Added a camera entity for display in the notification.
  • Removed input_boolean from the required domains for the trigger so that I could use the doorbell press on my Amcrest AD410. This means, if you use an input_boolean, it will not reset after the automation is run like vorion’s Blueprint.
  • Changed the notify device format to a notify service calls instead of a mobile_app domain device. This requires your notify device to be in the format of notify.<device>, such as notify.notify that notifies all devices with the app installed. I unfortunately couldn’t figure out how to setup a selector to give you a list of available notify service calls, so you will need to do a little digging on format given your particular implementation. This can be done from the Developer Tools → Services section of Home Assistant. From this area, put in notify. in the Service entry and it should show you a list of valid notify options.

See vorion’s original post for additional notes on configuring the 3 actions including how to find the name of the app you want to open (If you’re doing that).

Blueprint

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

blueprint:
  name: Send actionable notifications for Android with Camera Snapshot
  description: >
    Send actionable notifications to an Android device. Customized from vorion's blueprint.
    Changes
    - Remove notify_device integration requirement to allow notify groups to be used.
    - Removed trigger_entity domain input_boolean requirement. Removed reset of input_boolean from actions. (For use in detecting doorbell rings from sensor)
    - Added camera snapshot for doorbell capture (required).
    
    For each action, you can open an URL, an application on the device or load a lovelace view/dashboard.

    If you plan to use a lovelace view the format would be /lovelace/test where test is replaced by your defined path in the defined view.

    If you plan to use a lovelace dashboard the format would be /lovelace-dashboard/view where /lovelace-dashboard/ is replaced by your defined dashboard URL
    and view is replaced by the defined path within that dashboard.

    To pick the application to open, prefix app:// to the the package name.

    If the device does not have the application installed then the Home Assistant application will open to the default page.

    If you define an action and an URI for a button, URI will take precedence over action.
    
  domain: automation
  input:
    notify_device:
      name: Device to notify
      description: Device or group of devices for notification through mobile_app notification service. For example
        <notify.mobile_app_iphone>, <notify.all_devices>, <notify.notify>
      selector:
        text:
          type: search
          
    trigger_entity:
      name: Trigger entity
      description: Send the notification when this boolean turns on
      selector:
        entity:
#          domain: input_boolean

    doorbell_cam:
      name: Doorbell Cam
      description: The Camera from wich take photo for notification.
      selector:
        entity:
          domain: camera
      
    notification_title:
      name: Notification title (Optional)
      description: The title of the notification
      default: ""

    notification_message:
      name: Notification message (Optional)
      description: The message of the notification
      default: ""
    
    persistent_notification:
      name: Create persistent notification?
      description: Persistent notifications cannot be dimissed by swiping away
      default: false
      selector:
        boolean:

# Action 1

    action_1_title:
      name: First action name
      description: Name of the first button
      default: ""
      
    action_1_uri:
      name: URI for action 1 (Optional)
      description: Optional URI for the first action
      default: ""

    first_action:
      name: Action 1
      description: "Action to run when the first action is clicked"
      default: []
      selector:
        action:

# Action 2

    action_2_title:
      name: Second action name
      description: Name of the second button
      default: ""

    action_2_uri:
      name: URI for action 1 (Optional)
      description: Optional URI for the second action
      default: ""

    second_action:
      name: Action 2
      description: Action to run when the second action is clicked"
      default: []
      selector:
        action:

# Action 3
    
    action_3_title:
      name: Third action name
      description: Name of the third button
      default: ""
      
    action_3_uri:
      name: URI for action 3 (Optional)
      description: Optional URI for the third action
      default: ""

    third_action:
      name: Action 3
      description: "Action to run when the third action is clicked"
      default: []
      selector:
        action:

mode: restart
max_exceeded: silent

variables:
  notify_device: !input notify_device
  trigger_entity: !input trigger_entity
  doorbell_cam: !input doorbell_cam
  notification_title: !input notification_title
  notification_message: !input notification_message
  persistent_notification: !input persistent_notification
  action_1_title: !input action_1_title
  action_1_uri: !input action_1_uri
  first_action: !input first_action
  action_2_title: !input action_2_title
  action_2_uri: !input action_2_uri
  second_action: !input second_action
  action_3_title: !input action_3_title
  action_3_uri: !input action_3_uri
  third_action: !input third_action
  image_file: '/local/doorbell/{{ expand(trigger_entity)[0].last_changed | as_timestamp  | timestamp_custom("%Y-%m-%d_%H-%M-%S") }}.jpg'

trigger:
  platform: state
  entity_id: !input trigger_entity
  from: "off"
  to: "on"

action:
  # Create camera snapshot
  - data_template:
      entity_id: !input doorbell_cam
      filename: /config/www/doorbell/{{ expand(trigger_entity)[0].last_changed | as_timestamp  |
        timestamp_custom("%Y-%m-%d_%H-%M-%S") }}.jpg

    service: camera.snapshot

  # Send actionable notification
  - service: !input notify_device
    data:
      title: "{{ notification_title }}"
      message: "{{ notification_message }}"
      data: 
        tag: "{{ notification_title }}"
        persistent: "{{ persistent_notification }}"
        image: '{{ image_file }}'
        ttl: 0
        priority: high
        actions: >
          {% set titles = [action_1_title, action_2_title, action_3_title] %}
          {% set uris = [action_1_uri, action_2_uri, action_3_uri] %}
          {% set actions = namespace(data = []) %}
  
          {% for title in titles %}
            {% if title|length %}
              {% set uri = uris[loop.index - 1] %}
              {% set action_name = "action" + loop.index|string %}
              {% set action = {
                "action": "URI" if uri|length else action_name,
                "title": title,
                "uri": uri 
                }
              %}
              {% set actions.data = actions.data + [action] %}
            {% endif %}
          {% endfor %}
          {{ actions.data }}

  # Wait for the user to select an action
  - wait_for_trigger:
      platform: event
      event_type: mobile_app_notification_action

  # Do the action that the user selected
  - choose:
    - conditions: "{{ wait.trigger.event.data.action == 'action1' }}"
      sequence: !input first_action
    - conditions: "{{ wait.trigger.event.data.action == 'action2' }}"
      sequence: !input second_action
    - conditions: "{{ wait.trigger.event.data.action == 'action3' }}"
      sequence: !input third_action
5 Likes

Hello,
After create the automation, it don’t appear in the list of automation.
Any idea?
Thanks

Hi Tan, can you provide a screenshot of your configuration? It’s possible something is missing from your configuration and it’s causing the automation to not build correctly, or the format of an input doesn’t match how I configured things.

Hi Alexander:

Here is the code in automations.yaml:

- id: '1671563077764'
  alias: Send actionable notifications for Android with Camera Snapshot
  description: ''
  use_blueprint:
    path: McDAlexander/actionable_notifications_for_android_with_cam.yaml
    input:
      notify_device: <notify.all_devices>
      trigger_entity: binary_sensor.cam_intercomunicador_visitor
      doorbell_cam: camera.cam_intercomunicador_main
      notification_title: Title of the notification
      notification_message: Message of the notification
      action_1_title: Action 1
      first_action:
      - type: turn_on
        device_id: 794e0745a1985e264b28d0be0e1705ef
        entity_id: light.luz_cdb_1a_1
        domain: light
      action_2_title: Action 1
      action_3_title: Action 1
      second_action:
      - type: turn_on
        device_id: afcff0b65bdd188619fee2a56e8d95e9
        entity_id: light.luz_cdb_1a_2
        domain: light
      third_action:
      - type: turn_on
        device_id: 720e7c57be5046bb8ae6dbc2f0767f80
        entity_id: light.luz_cdb_1a_3
        domain: light

It’ works. I find how to solve the issue.

<notify.all_devices> without <>

Thanks

I was just going to point that out. I was trying to research the format to see if I just didn’t understand it could be put in like that :slight_smile: Glad you got it worked out.

1 Like

Hi Alexander,

how to add multiple device in yaml :

notify_device: notify.mobile_app_sm_s908b, more device here…

Thanks

You’ll want to look into notification groups. I think by default notify.notify sends notifications to all devices, but you can configure specific groups to notify. This is all done outside of automations.

Ok, I will take a look about notification groups.
Thanks
Best

This is awesome! Works well on iPhone with Reolink doorbell as well

1 Like

@McDAlexander is it possible for there to be a default action i.e. hit the notification anywhere does x? For me, Action 1 would be the default notification :slight_smile:

Is it possible to have an action that opens a large view of the image, or some way of getting back to the notification to see the image?

2 Likes

As a warning folks, this blueprint never cleans up the images so the storage keeps being eaten up!

You will find them in config/www/doorbell.

[edit]
To fix, you can use this delete integration (Delete files service) and add an extra action to clean up files.

[edit2]
If you want a card for the images I suggest this card Gallery Panel for images/videos

2 Likes

Hey, I’ve been trying to use your blueprint. It works fine, except that I don’t get a cam snapshot. Is there any prerequisite for that I may have missed?

Hi, snapshots are correctly saved on my side in the www folder. But not shown correctly in the notification.
Im wondering if its because the subfolders in which snapshots are saved got some blanks “space” in their names. Just replaced those by “_”. Let see if it works better now… waiting for next motion detection :slightly_smiling_face:

Looking for this as well, did you find a way? I’d like it to open a picture app where I can zoom in the snapshot if possible. Or maybe even save the snapshot to the phone’s gallery where I can open it.