Actionable notifications for Android when entering or leaving a zone

Tags: #<Tag:0x00007fc40edb20c0> #<Tag:0x00007fc40edb1e90> #<Tag:0x00007fc40edb1d50>

This Blueprint helps you send actionable notifications to your Android device, when a person enters a zone.
I use this to fire a notification when entering my home zone, asking if HA should open my garage door.

This is heavily based on Vorions blueprint for actionable notification for android: Link

Requirements

  • Home Assistant app on your device
  • A person with a device tracker (eg person.Martin where the person has an attached device tracker)
  • a pre-defined zone

Notes

To add a tracker to a person, got to: ConfigurationPeopleThe person → Select “Pick device to track”.
To add a zone, got to: ConfigurationZones → click the “Add Zone
configure High accuracy mode to only be enabled under special circumstances beneath on the same page.

If you set up your HA Companion app to use high precision location service, this will work more instantly. That way, it will report location data to HA apprx. every 5 seconds. This can be set to only be active under certain circumstances. Eg when connected to your cars Bluetooth.
To activate high precision location data, open the HA app on your android device, and go to: App ConfigurationSensorsLocation sensorHigh accuracy mode

You can add up to 3 actions, but all 3 are optional.
For each action, you can do something the same way as for an Automation or open a 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. How to find 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.

Blueprint

Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)

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

Or you can import this Blueprint by using the forum topic URL:

Copy to clipboard

blueprint:
  name: Send actionable notifications when entering a zone for Android
  description: 'Send actionable notifications to an Android device, when an entity enters a zone.

    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 needs to run the official Home Assistant app to receive
        notifications
      selector:
        device:
          integration: mobile_app
    trigger_entity:
      name: Trigger entity
      description: The entity that will trigger the notification
      selector:
        entity:
          domain: person
    trigger_event:
      name: Trigger Event
      description: Select if the notification should be activated upod entering or leaving the zone
      selector:
        select:
          options:
            - leave
            - enter
    trigger_zone:
      name: Trigger Zone
      description: Select the zone used for triggering
      selector:
        entity:
          domain: zone
    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://community.home-assistant.io/t/actionable-notifications-for-android/256773
mode: restart
max_exceeded: silent
variables:
  notify_device: !input 'notify_device'
  trigger_entity: !input 'trigger_entity'
  trigger_event: !input 'trigger_event'
  trigger_zone: !input 'trigger_zone'
  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'
trigger:
  - platform: zone
    entity_id: !input 'trigger_entity'
    zone: !input 'trigger_zone'
    event: !input 'trigger_event'
action:
- domain: mobile_app
  type: notify
  device_id: !input 'notify_device'
  title: '{{ notification_title }}'
  message: '{{ notification_message }}'
  data:
    tag: '{{ notification_title }}'
    persistent: '{{ persistent_notification }}'
    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'