#Find my phone script not working for Android.

1 messages · Page 1 of 1 (latest)

timber heart
#

I had created a script under /homeassistant/scripts.yml named Find my phone to basically send a critical level or high priority alert notification for both Android and iPhone devices. Here is the script,

find_my_phone:
  alias: Find My Phone
  sequence:
  - service: notify.{{ device_name }}
    data:
      message: Your phone is being located.
      title: Find My Phone
      data: >
        {% set device_name_lower = device_name | lower %}
        {% if "android" in device_name_lower %}
          {
            "ttl": 0,
            "priority": "high",
            "channel": "alarm_stream"
          }
        {% elif "iphone" in device_name_lower or "ipad" in device_name_lower %}
          {
            "push": {
              "sound": {
                "name": "default",
                "critical": 1,
                "volume": 1.0
              }
            }
          }
        {% endif %}
  description: Find My Phone
  icon: mdi:cellphone-sound
  fields:
    device_name:
      selector:
        text:
      name: Device name
      description: Name of the mobile device
      required: true
#

I got this from online somewhere, I don't remember where, its been a while.

#

This script used to work for all devices, Android and iPhone, but recently I cannot get this to work for any Android device, iPhone devices seems to work fine though.

#

I use it on my Dashboard via a button, like this,

  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: script.find_my_phone
      data:
        device_name: mobile_app_my_android
      target: {}
    name: Find My Phone
    icon: mdi:cellphone-sound
    show_state: true
#

similarly for iPhone,

      - type: button
        show_name: true
        show_icon: true
        tap_action:
          action: call-service
          service: script.find_my_phone
          service_data:
            device_name: mobile_app_foo_iphone
        name: Foo's iPhone
        icon: mdi:cellphone-sound
        show_state: true
#

and iPhone one works.

#

though iPhone one doesn't ring the alarm, it just plays a short notification sound so you have to ring it multiple times sometimes to find the phone, where as Android one plays the alarm tone so it keeps playing for a while.

#

when I click the button to activate the script, I get this toast message..

#

AFAIK the notifications needs the persistent thing to be on, and I have double checked I have it turned on, on my Android phone.

idle kettle
#

channel: alarm_stream only works on Android 7 or below

timber heart
idle kettle
#

It doesn't look that that's the reason for the error message you posted though

near knot
#

Maybe the trace log of the script will give more insights. Have you checked the obvious? Entity name for android changed?

#

Are all notifications disturbed or just this particular one?

timber heart
timber heart
near knot
timber heart
#

TBH I forgot what are all the steps I followed to configure this, its been a long time (over a year).

timber heart
near knot
#

HA

timber heart
#

I don't think I get any other notification from HA apart from this. I don't recall getting any other notification.

#

Like I have turned all the sensors on my phone and if I turn location off I get a warning notification saying location is off so I won't be able to get certain sensor's info.

near knot
#

Please try via the developer tools actions to send a notification to these devices. This is just to ensure that the basic functionality is not disturbed for them.

timber heart
#

this page I am guessing?

near knot
#

Exactly. In there choose the "send a notification via mobile app..." and choose the one for your particular phone. Enter a message and click perform action.

timber heart
#

Yes I get a notification on my phone.. so the device name have changed I guess? my phone no longer has _android at the end.. and because of this my script logic won't work.

#

how to change the device name? in my mobile app?

near knot
#

Go to devices and services, open the mobile app integration. All devices are listed there and can be renamed through their respective "..." menu. It should ask you to also change all entity IDs, choose yes

timber heart
#

yea it was in the mobile app, changed the device name, it works now.

#

in android, in the ham menu, App configuration -> SERVER_NAME (first item in the list) -> Device Name, changed this and works.

#

Had to force stop the app for the change to take effect.

#

Guess my issue is fixed and this can be closed now. Thanks to @near knot and @idle kettle for helping.

#

how to mark solved?