Custom_component: PhoneTrack GPS device tracker

In my endeavour to slowly stepping away from using remote/external big data gather companies (especially) Google I was looking for a replacement of the “Google Location Sharing” device tracker as it only worked once for a small time and since then even with all the updates from HASS it still did not came back to live.

I already migrated my contacts and calendar using Nextcloud on my own server. However during that process I came aware of PhoneTrack-OC;

I was using the Life360 device tracker and that worked great, however the size of the Android APP was rather big and heavy for my wife’s old phone. But most importantly, I rather keep all that GPS based (+historical) data on my own servers (Privacy and Piracy wise)

PhoneTrack works amazingly good and you can use whatever GPS logger suits you best on your phone, however I really, REALLY like the PhonTrack-OC Android APP for this as well. It is very basic, light and just does what it needs to do without even noticing it on the battery life.

Searching on the Internet brought me to a topic from @Phyks here;

So I took his code, converted it to the new layout and adjusted it a bit by looking at the Google Location Sharing tracker.

Anyhow, more information on PhoneTrack here;

And the device tracker to poll this backend here;

Let me know your thought…

5 Likes

Looks pretty good to me. The only slight suggestions I’d make are:

  • If you’re running _update_info via track_time_interval, you don’t need the Throttle decorator.
  • I would convert data[device]['batterylevel'] to an int first, like this: `battery = int(float(data[device][‘batterylevel’]))
1 Like

Thanks,

Indeed, will move the throttle stuff to something similar as the Google Tracker uses.
Will change battery to an Int like you stated.

No problem. Don’t know Python yet, but considering I got this far, that should also not be a problem. :smiley:

Any other feedback is always welcome.

1 Like

Hi

I get the below when trying to add this as a custom respository in HACS

Could not add j1nx/homeassistant-phonetrack at this time, check the log for more details.

I have tried both


j1nx/homeassistant-phonetrack

So not sure why it’s not working. Any advice on how to solve.

Cheers

The structure of the respository is not correct for HACS.

The component has to be in the folder “custom_components”.

Ah, ok, that can be done easily. Hang on …

EDIT: Done!

Thanks - component working but not the sensor

token: <SHARED_VIEW_TOKEN> - Is this the SESSION Token Number?

devices:
- <DEVICE_NAME> - Assume these are the device names given in Phonetrack

and finally which new entities should be create in HA

Sorry about all the questions :slight_smile:

hi. i’ve added the folder inside the custom_components, added the code in device_tracker. Restart homeassistant and this error come up:

Log Details (ERROR)
Thu Jul 11 2019 17:04:23 GMT+0200 (Ora legale dell’Europa centrale)
Error setting up platform legacy
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/device_tracker/setup.py", line 76, in async_setup_legacy
    tracker.see, discovery_info)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/phonetrack/device_tracker.py", line 33, in setup_scanner
    PhoneTrackDeviceTracker(hass, config, see)
  File "/config/custom_components/phonetrack/device_tracker.py", line 50, in __init__
    self._update_info()
  File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 224, in wrapper
    result = method(*args, **kwargs)
  File "/config/custom_components/phonetrack/device_tracker.py", line 61, in _update_info
    data = data[self.token]
TypeError: list indices must be integers or slices, not str

See attached picture (although Dutch);

Click the sharing icon (red square)

You need the API-URL as selected with the black square. It contains all the info you need, including the TOKEN (No it is not the same token as you use for logging)

Device name is the name as selected in the bottom red square.

Hope this helps.

@hangy Could you post the (anonymized) configuration.yaml section you are using. I suspect something is wrong there.

now it’s ok. i was using the Token Session… :wink:

1 Like

Ok, cool!

IT is all quick code without any proper error handling for mis-configurations. Have that on the list though to start learning some Python.

Let me know how it holds up for you.

Brilliant Peter all working - this is a great additional to HA
Really appreciate the help and efforts

1 Like

No problem. Will update the README with above information to help others in advanced.

See https://gitlab.com/eneiluj/phonetrack-oc/issues/271 if you want the other way around, i.e. have phonetrack record a device from HA

SOLVED
Tried it again after some days, now it works adding
j1nx/homeassistant-phonetrack
to HACS.

Tried to add

j1nx/homeassistant-phonetrack

to HACS (tried both Categories Integration and Plugin) , but also got the messages

Could not add ‘j1nx/homeassistant-phonetrack’ with type ‘integration’ at this time.
If you used the correct type, check the log for more details.

But no details in the log.
Do i have to be logged into github during adding the repo to HACS ? Or what did i probably wrong

System: pi3 - HassOS 2.12/Supervisor 192 and (HACS 0.16.3)

Super, works a treat.
only issue is it is only showing me one of two devices i added.
my configuration is below, can someone here confirm this is the correct way of defining it:

- device_tracker:
  - platform: phonetrack
    url: http:/<DOMAIN>/index.php/apps/phonetrack/api/getlastpositions/
    token: <TOKEN_1>
    devices
    - <DEVICE_1>
    
  - platform: phonetrack
    url: http://<DOMAIN>/index.php/apps/phonetrack/api/getlastpositions/
    token: <TOKEN_2>
    
    devices:
    - <DEVICE_2>

I created a group within phonetrack and added both my wife’s and own phone to that group. Then used the link and token of that group. That way you can have just both devices within the same devices section of one integration.

I tried that, not sure if the space in the device name is causing the issue.
will have to check next week on her phone when my wife is back

found the issue :grimacing:
the configuration (even with 2 separate trackers) is fine
the device name had a trailing space !

1 Like

@j1nx Thank you so much!
It works perfectly!
I’m wondering why there aren’t any official Nextcloud integrations/components.
I would imagine there’s a large overlap in Homeassistant/Nextcloud users.