Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save McDAlexander/56eb3f2e421e283460b3d641fd002ea8 to your computer and use it in GitHub Desktop.
Save McDAlexander/56eb3f2e421e283460b3d641fd002ea8 to your computer and use it in GitHub Desktop.
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
@Tanjohnson99
Copy link

Hello,
When use your blueprint, create an automation and save, it don't appear in the list o automation.
Thanks

@lobhater
Copy link

Is there a way to control the action when the notification itself is tapped on as opposed to one of the action options? In case that doesn't make sense I mean is it possible to control what happens when you tap inside the red square?
Screenshot
Love your blueprint! Thanks

@andy2002a
Copy link

The current template can get annoying with repeat notifications. I added a parameter to suppress notifications (do_not_notify_again_minutes) for X minutes:

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
          multiline: false
    trigger_entity:
      name: Trigger entity
      description: Send the notification when this boolean turns on
      selector:
        entity: {}
    do_not_notify_again_minutes:
      name: Repeat notification threshold
      description: Do not send notification if activity occured within X minutes
      default: 0
    doorbell_cam:
      name: Doorbell Cam
      description: The Camera from wich take photo for notification.
      selector:
        entity:
          domain:
            - camera
          multiple: false
    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_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_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_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: {}
  source_url: https://gist.github.com/McDAlexander/56eb3f2e421e283460b3d641fd002ea8
mode: single
max_exceeded: silent
variables:
  notify_device: !input notify_device
  trigger_entity: !input trigger_entity
  do_not_notify_again_minutes: !input do_not_notify_again_minutes
  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:
  - 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
  - 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 = []) %}\n{% for title in titles %}\n  {% if title|length
          %}\n    {% set uri = uris[loop.index - 1] %}\n    {% set action_name = \"action\"
          + loop.index|string %}\n    {% set action = {\n      \"action\": \"URI\" if
          uri|length else action_name,\n      \"title\": title,\n      \"uri\": uri
          \n      }\n    %}\n    {% set actions.data = actions.data + [action] %}\n
          \ {% endif %}\n{% endfor %} {{ actions.data }}\n"
  - wait_for_trigger:
      platform: event
      event_type: mobile_app_notification_action
  - 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
  - delay:
      hours: 0
      minutes: !input do_not_notify_again_minutes
      seconds: 0
      milliseconds: 0

@RafaelSchridi
Copy link

I added an action for what happens when when you select main notification (default opens homeassistant) and made it save to a file without a datetime because the old images never get removed.

blueprint:
  name: Send actionable notifications for Android with Camera Snapshot
  description: 'Send actionable notifications to an Android device.
    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
          multiline: false
    trigger_entity:
      name: Trigger entity
      description: Send the notification when this boolean turns on
      selector:
        entity: {}
    doorbell_cam:
      name: Doorbell Cam
      description: The Camera from wich take photo for notification.
      selector:
        entity:
          filter:
            - domain: camera
          multiple: false
    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: ''
    main_action:
      name: Main Action URI (Optional)
      description: What should happend when you click notification, leave empty to open Home Assistant
      default: ''
    persistent_notification:
      name: Create persistent notification?
      description: Persistent notifications cannot be dimissed by swiping away
      default: false
      selector:
        boolean: {}
    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_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_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: {}
  source_url: https://gist.github.com/McDAlexander/56eb3f2e421e283460b3d641fd002ea8
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
  main_action: !input main_action
  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/{{ trigger_entity }}.jpg
trigger:
  platform: state
  entity_id: !input trigger_entity
  from: 'off'
  to: 'on'
action:
- data_template:
    entity_id: !input doorbell_cam
    filename: /config/www/doorbell/{{ trigger_entity }}.jpg
  service: camera.snapshot
- 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
      url: '{{ main_action | default (none) }}'
      clickAction: '{{ main_action | default (none) }}'
      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 = []) %}\n{% for title in titles %}\n  {% if title|length
        %}\n    {% set uri = uris[loop.index - 1] %}\n    {% set action_name = \"action\"
        + loop.index|string %}\n    {% set action = {\n      \"action\": \"URI\" if
        uri|length else action_name,\n      \"title\": title,\n      \"uri\": uri
        \n      }\n    %}\n    {% set actions.data = actions.data + [action] %}\n
        \ {% endif %}\n{% endfor %} {{ actions.data }}\n"
- wait_for_trigger:
    platform: event
    event_type: mobile_app_notification_action
- 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

@andy2002a
Copy link

@RafaelSchridi Another alternative is to set set url: fb1675493782511558:// (in OS) (might be app://com.mcu.reolink in android ) and it will take you straight to the Reolink app (but not the camera itself).

@RafaelSchridi
Copy link

@RafaelSchridi Another alternative is to set set url: fb1675493782511558:// (in OS) (might be app://com.mcu.reolink in android ) and it will take you straight to the Reolink app (but not the camera itself).

Yeah I added the ability to add those uris to the main notification itself, not just actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment