Android Intent to Google Maps

I am trying to get an Android to be sent from home assistant which includes an address and sets google maps to navigation mode. I have found documentation here:

however I can’t seem to get it to work. Here is my attempt:

alias: Send Map Location
sequence:
- service: notify.mobile_app_nathaniel_mobile
  data:
    message: command_activity
    data:
      intent_action: com.google.android.apps.maps
      intent_extras: >-
        INTENT.ACTION_VIEW:"q=" + (state_attr('sensor.google_alarm_event', 'address'))
mode: single
icon: mdi:map-marker-radius-outline

anyone able to guide me in the right direction. The intent sends however, the phone says “Unable to send activity intent, please check command format”
One things I don’t know how to do is made the address have URL encoded format (ie “New%20York%20Airport”) from the attribute of sensor.google_alarm_event

anyone have any ideas?

Tried doing this but I get a 404 error instead:

alias: Send Map Location
sequence:
  - service: notify.mobile_app_nathaniel_mobile
    data_template:
      message: Time to Leave
      title: >-
        {{ as_timestamp(now()) | timestamp_custom('%H:%M') }} Do You Wish to
        Navigate to {{ state_attr('sensor.google_alarm_event', 'address') }}?
      data:
        ttl: 0
        priority: high
        actions:
          - action: URI
            title: Navigate
            URI: >-
              https://www.google.com/maps/search/?api=1&q={{
              state_attr('sensor.google_alarm_event', 'address') }}
mode: single
icon: mdi:map-marker-radius-outline

I have implemented a similar thing that works, I had a difference in the url used. In mine it was:

service: notify.{{states('sensor.prefered_notification_method')}}
data:
  message: >-
    #insert your message here
  data:
    #below is optional, but doesn't hurt
    car_ui: true
    ttl: 0
    priority: high
    actions:
      - action: URI
        title: GPS Guidance
        uri: >-
          https://www.google.com/maps/dir/?api=1&travelmode=driving&dir_action=navigate&destination={{states('whatever_variable_you_want_to_user_as_a_url_encoded_format_here)}}

To get a url encoded version of a string it is actually quite simple in home assistant. I found it in some random documents, but its just as simple as taking a {{states('example')}} and adding

| urlencode

so it would look like the following in your case:

            URI: >-
               https://www.google.com/maps/dir/?api=1&travelmode=driving&dir_action=navigate&destination={{
              state_attr('sensor.google_alarm_event', 'address') |urlencode}}

I still get the error 404 Not Found… that is the only thing that appears on the page. I don’t know if it’s a phone app issue or something else?

alias: Send Map Location
sequence:
  - service: notify.mobile_app_nathaniel_s23u
    data_template:
      message: Time to Leave
      title: >-
        {{ as_timestamp(now()) | timestamp_custom('%H:%M') }} Do You Wish to
        Navigate to {{ state_attr('sensor.google_alarm_event', 'address') }}?
      data:
        ttl: 0
        priority: high
        actions:
          - action: URI
            title: Navigate
            URI: >-
              https://www.google.com/maps/dir/?api=1&travelmode=driving&dir_action=navigate&destination={{state_attr('sensor.google_alarm_event',
              'address') |urlencode}}
mode: single
icon: mdi:map-marker-radius-outline

This is how I launch DroidCam

service: notify.mobile_app_pixel_3a
data:
  message: command_activity
  data:
    channel: com.dev47apps.obsdroidcam
    intent_class_name: com.dev47apps.obsdroidcam.MainActivity
    tag: android.intent.action.MAIN

There is no intent_action or intent_extras.
channel would be your intent_action.
tag would be your intent_extras.

Additionally - your use of + to join strings doesn’t work in Jinja you need to use ~

So for example:

tag: >-
  INTENT.ACTION_VIEW:"q=" ~ (state_attr('sensor.google_alarm_event', 'address')|urlencode)

Checking both the Android Docs and the Google Maps docs - you would want something like this:

tag: android.intent.action.VIEW:{{ ("google.navigation:q=" ~ state_attr('sensor.google_alarm_event','address'))|urlencode  }}

I’m confused about the channel (intent_action) and intent_class_name (intent_extras) that I would need here?

I don’t know that you specifically need class name. Hold on let me try and see if I can invoke Google maps in navigation mode on my phone.

OK - this DOES work:

service: notify.mobile_app_pixel_8_pro
data:
  message: "command_activity"
  data:
    intent_package_name: "com.google.android.apps.maps"
    intent_action: "android.intent.action.VIEW"
    intent_uri: "{{ 'google.navigation:q=' ~ (state_attr('sensor.google_alarm_event','address'))|urlencode }}"

I have tested it.
I don’t know what happened with channels and tag etc, it must have been changed again…

(Just so I know I wasn’t going crazy, it did definitely used to be channel and tag… Open app on Android phone - #5 by ha_user22323 )

ok so I have this:

alias: Send Map Location
sequence:
  - service: notify.mobile_app_nathaniel_s23u
    data_template:
      message: Time to Leave
      title: >-
        {{ as_timestamp(now()) | timestamp_custom('%H:%M') }} Do You Wish to
        Navigate to {{ state_attr('sensor.google_alarm_event', 'address') }}?
      data:
          intent_package_name: "com.google.android.apps.maps"
          intent_action: "android.intent.action.VIEW"
          intent_uri: "{{ 'google.navigation:q=' ~ (state_attr('sensor.google_alarm_event','address'))|urlencode }}"

mode: single
icon: mdi:map-marker-radius-outline

All this seems to do for me is open up Home Assistant to it’s home screen?

You can’t launch an app and have a title - you have to send 2 notifications. If you want the user to confirm they want the address before sending the notification with the address you want to do something a little bit different - like this:

sequence:
  - service: notify.mobile_app_nathaniel_s23u
    data:
      message: Time to Leave
      title: >-
        {{ as_timestamp(now()) | timestamp_custom('%H:%M') }} Do You Wish to
        Navigate to {{ state_attr('sensor.google_alarm_event', 'address') }}?
      data:
        actions:
          - action: google_alarm_navigate_address
            title: "Yes"
          - action: noop
            title: "No"
        tag: google_alarm_address
        channel: google_alarm_address
        priority: high
        ttl: 0
        timeout: 300

Change the timeout to whatever, or omit it if you don’t need it.

Next you want a wait for trigger

  - wait_for_trigger:
      - platform: event
        event_type: notification_response_action
        event_data:
          response_action: google_alarm_navigate_address
    timeout:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
    continue_on_timeout: false

Then you send the actual notification to launch Google maps.

  - service: notify.mobile_app_nathaniel_s23u
    data:
      message: "command_activity"
      data:
        intent_package_name: "com.google.android.apps.maps"
        intent_action: "android.intent.action.VIEW"
        intent_uri: "{{ 'google.navigation:q=' ~ (state_attr('sensor.google_alarm_event','address'))|urlencode }}"
1 Like

OK so now I have 3 scripts:

The sending to google maps for location works beautifully fine. However it’s the other two that I can’t seem to understand how it works. I think I’ve completly misunderstood what you were meaning:

alias: Request Navigation to Mobile
sequence:
  - service: notify.mobile_app_nathaniel_s23u
    data:
      title: Time to Leave
      message: >-
        Event starts at {{ state_attr('sensor.google_alarm_event', 'time') }} Do
        You Wish to Navigate to {{ state_attr('sensor.google_alarm_event',
        'address') }}?
      data:
        actions:
          - action: google_alarm_navigate_address
            title: Send Location
        tag: google_alarm_address
        channel: google_alarm_address
        priority: high
        ttl: 0
        timeout: 300
mode: single
icon: mdi:map-marker-radius
alias: Google Alarm Navigate Address
sequence:
  - wait_for_trigger:
      - platform: event
        event_type: notification_response_action
        event_data:
          response_action: google_alarm_navigate_address
    timeout:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
    continue_on_timeout: false

I can’t say I understand the need for two triggers? or how this is working. The message on the phone comes up perfectly fine, but when I click Navigage on the phone it does nothing at all.