Phonetrack vs RESTful implemetation how to?

There were cool application that I used for a while Custom_component: PhoneTrack GPS device tracker but seem it is not working anymore…

I wondering how it is possible to replace it with RESTful calls. Basically I created following config in configuration.yaml:

rest_command:
  phonetrack_get:
    url: https://DOMAIN/index.php/apps/phonetrack/api/getlastpositions/TOKEN
    # Or better this one more secure way
    #url: !secret phonetrack_url_token
    method: get
If you choice more secure way

you need to update / create secrets.yaml with URL:

phonetrack_url_token: https://DOMAIN/index.php/apps/phonetrack/api/getlastpositions/TOKEN

Now I can create automation to periodically calling this API and get data based on RESTful Command - Home Assistant example:

alias: "[RESTful] Get Last GPS Position"
description: >-
  https://www.home-assistant.io/integrations/rest_command/#using-rest-command-response-in-automations
trigger:
  - platform: time_pattern
    minutes: "5"
condition: []
action:
  - service: rest_command.phonetrack_get
    metadata: {}
    data: {}
    response_variable: phonetrack_response
  - if:
      - condition: template
        value_template: "{{ phonetrack_response['status'] == 200 }}"
    then:
      - alias: Parse data
        variables:
          state.entity_id: device_tracker.phonetrack_device_name
          source_type: gps
          friendly_name: Device Name
          locations_lat: >-
            {{
            phonetrack_response['content']['TOKEN']['Device Name']['lat']
            }}
          locations_lon: >-
            {{
            phonetrack_response['content']['TOKEN']['Device Name']['lon']
            }}
          locations_accuracy: >-
            {{
            phonetrack_response['content']['TOKEN']['Device Name']['accuracy']
            }}
          locations_batterylevel: >-
            {{
            phonetrack_response['content']['TOKEN']['Device Name']['batterylevel']
            }}
    else:
      - service: persistent_notification.create
        data:
          title: Could not get GPS data via Phonetrack. Please check the logs.
          message: "Http Response code is: {{ phonetrack_response['status'] }}"
mode: single

And get following data:

locations_lat: XX.yyyyyyy
locations_lon: XX.yyyyyyy
locations_accuracy: 2.61
locations_batterylevel: null

Seems light, but I have few Problems:

  1. How to assign those GPS Values to the Person / Device to track location? I know that in a /config/person I can do that, but here I do not have anything from my automation. Somehow it is working now and I have following output:

    But how it is assigned to it is still magic for me, because Object name on screenshot is device_tracker.bmw and in automation it is state.entity_id: device_tracker.phonetrack_bmw… Is it done via Friendly name?

  2. I there is a way to get rid of TOKEN in automation config?
    Problem is that API answer is as following:

{
    "TOKEN": {
        "Device Name 1": {
            "accuracy": 2.61,
            "altitude": 111.6,
            "batterylevel": null,
            "bearing": 226.78,
            "lat": xxxxx,
            "lon": xxxxx,
            "satellites": null,
            "speed": 3.015,
            "timestamp": 1707751858,
            "useragent": "Ulogger"
        },
        "Device Name 2": {
            "accuracy": 12.73,
            "altitude": null,
            "batterylevel": null,
            "bearing": null,
            "lat": xxxxx,
            "lon": xxxxx,
            "satellites": null,
            "speed": null,
            "timestamp": 1707748428,
            "useragent": "browser"
        },
		...
    }
}

And I need to go over it to get Device Name and Location…

  1. Can it be more general for “Device Name”? E.g. some variable?