Trackr intergration

New error, not much better though.

(hass) hass@hass:~$ python3 pytrackrtest.py 
Traceback (most recent call last):
  File "pytrackrtest.py", line 6, in <module>
    state = str(trackr_api.dump_state())
AttributeError: 'trackrApiInterface' object has no attribute 'dump_state'
(hass) hass@hass:~$

Still not running the latest version. How did you install? If with pip try to manually download the correct version. pip install pytrackr==0.0.4

better. This time I installed it without the sudo

(hass) hass@hass:~$ pip install pytrackr==0.0.4
Collecting pytrackr==0.0.4
  Downloading pytrackr-0.0.4.tar.gz
Requirement already satisfied: requests>=2.0 in /srv/hass/lib/python3.4/site-packages (from pytrackr==0.0.4)
Building wheels for collected packages: pytrackr
  Running setup.py bdist_wheel for pytrackr ... done
  Stored in directory: /home/hass/.cache/pip/wheels/53/59/11/30ec3b0de748114ac81f8285052efc1b368366a52a71f8521c
Successfully built pytrackr
Installing collected packages: pytrackr
  Found existing installation: pytrackr 0.0.2
    Uninstalling pytrackr-0.0.2:
      Successfully uninstalled pytrackr-0.0.2
Successfully installed pytrackr-0.0.4
(hass) hass@hass:~$ python3 pytrackrtest.py 
[{'ownershipOrder': 0, 'batteryLevel': -1, 'trackerId': '0000b226-86c6ffe7', 'id': 4522278670303232, 'type': 'Bluetooth', 'icon': 'keys', 'timeUpdatedDiff': 2666320480, 'lastUpdated': 1479777758330, 'ownersEmail': '[email protected]', 'lastKnownLocation': {'longitude': -89.71545, 'latitude': 35.19716}, 'groupItem': False, 'lastTimeSeen': 'Thu Dec 22 20:32:29 UTC 2016', 'lost': False}]
Custom name: None
Location: {'longitude': -89.71545, 'latitude': 35.19716}
Last time seen: Thu Dec 22 20:32:29 UTC 2016
Tracker ID: 0000b226-86c6ffe7
Type: Bluetooth
Last upadted: Tue Nov 22 01:22:38 UTC 2016
Battery level: -1


Traceback (most recent call last):
  File "pytrackrtest.py", line 25, in <module>
    device.update_state_from_api()
AttributeError: 'trackrDevice' object has no attribute 'update_state_from_api'
(hass) hass@hass:~$

Sweet, you have all kinds if stuff in your response that I don’t have.

What type of trackr is it?
Not sure what the id field is for.
I also don’t have the lost field and email field and time between updates field or the ownership field. I’ll add those in.

Wonder why your battery reports as -1?

You can ignore that error I removed that function, must have forgot to remove it from the test.py.

cool, it’s on of the bravo’s. what was the setup to integrate it into HA? I’m hoping it’s more accurate to use for presence detection than my phone with nmap.

I made added the changes I mentioned, so if you want you can test again. upgrade to 0.0.5. To implement it into HA, you can try running it as a custom component until it gets added officially.

I have never tried using a custom component, but I think all you need to do is create a directory in your config directory called custom_components and place the trackr.py file from here (https://github.com/w1ll1am23/home-assistant/blob/7214b8a1071b84ec4bf4b7e3364551be14cc9af2/homeassistant/components/device_tracker/trackr.py) inside. Then add the following to your config.

device_tracker:
  - platform: trackr
    username: your email
    password: your password

in ha.log

Traceback (most recent call last):
File “/usr/lib/python3.4/asyncio/tasks.py”, line 237, in _step
result = next(coro)
File “/srv/hass/lib/python3.4/site-packages/homeassistant/components/device_tracker/init.py”, line 249, in async_see
dev_id = cv.slug(str(dev_id).lower())
File “/srv/hass/lib/python3.4/site-packages/homeassistant/helpers/config_validation.py”, line 226, in slug
raise vol.Invalid(‘invalid slug {} (try {})’.format(value, slg))
voluptuous.error.Invalid: invalid slug chips keys (try chips_keys)

You might want to check the device name to see if it has any blanks in it and replace them with an “_”

In the for loop in update_info, I modified the dev_id line as follows

dev_id = trackr.name().replace(" “,”_")

it seems to work.

Okay cool! Did you add a name to your trackr? Your response from above doesn’t have a name set so I would have expected you to get a device with a name of the trackr id.

I named it “chips keys” The space was causing a problem.

Cool, I’ll make the changes you made to the pull request I have open. Thanks for all the help.

sure, we’ll see what happens next week when I have multiple devices online.

I got curious and went ahead and setup a trackr for my wife. I through a for loop around the display for the devices and it works well. Looks like it’s just a list of dictionaries.

Custom name: Chips Keys
Location: {'longitude': -99.99999, 'latitude': 99.999999}
Last time seen: Fri Dec 23 13:32:18 UTC 2016
Tracker ID: 00009999-999999999
Type: Bluetooth
Last upadted: Thu Dec 22 22:10:09 UTC 2016
Battery level: None


Custom name: Susan keys
Location: {'longitude': -88.888888, 'latitude': 88.888888}
Last time seen: Fri Dec 23 13:32:42 UTC 2016
Tracker ID: 0000793b-f84e48d2
Type: Bluetooth
Last upadted: Fri Dec 23 12:55:53 UTC 2016
Battery level: None


(hass) hass@hass:~$ 

Now just how to figure out how to get hass to show them. Haven’t played with that yet.

Ok, I setup an account for my wife when I setup her trackr so she and I are on different email accounts. I then added her to a group called family. Once she confirmed that (and after a restart), I was able to see her tracker information in HA. It integrates well into HA and recognizes the zones I had setup around different locations in HA. For example, I had zones setup for the stores my wife supports back when I was using the iphone integration (which chewed up our batteries). HA is using the lon/lat reported by trackr to report that my wife is in one of her stores right now.
The only negative I see to this is that the trackr’s reported gps location isn’t all that accurate. I had setup the zone around my house to be 100ft, and that was fine for iphone reporting. But trackr isn’t that accurate in it’s gps reporting. I enlarged the zone around my house to be 500 ft and so far so good.

Sweet! That is awesome. I was assuming that it was going to be a list of dictionaries you just never know. Glad to know the group thing works too, that is interesting. Yeah I noticed the same thing on the accuracy going to need to make my zones a little bigger too.

Looks like we should be good to go for the 0.36.0 release as long as there are no complaints on my PR.

One thing I am not sure if you noticed or not, but at the moment I have it throttled in pytrackr to only poll every 5 minutes. I think that is about how often the Android app is doing it so since this isn’t supported by TrackR I thought I could at least not hammer on their API in hopes that they don’t ban us somehow.

5 minutes should be fine. You might want to make that something that could be configured through HA with a minimum value of 5 minutes. I might not care every 5 minutes about my dogs, but for proximity to the house for people, 5 minutes would be about right for me.

I need to play with the proximity sensor some more. So that I can base things not just on home/not home but on distance from home and direction of travel.

Failing for me… Did a pip install pytrackr as pi user and saved your script as test.py:

pi@raspberrypi:~ $ python test.py
Enter your trackr email: [email protected]
Traceback (most recent call last):
  File "test.py", line 14, in <module>
    email = input("Enter your trackr email: ")
  File "<string>", line 1
    [email protected]
     ^
SyntaxError: invalid syntax

Same thing with my own email - I’m useless at python, so It might be obvious but not for me :slight_smile:

Make sure you are using python3 your python might be configured to call python2?

It doesn’t seem to be updating in HA every 5 minutes. My wife is 20 minutes away from her last location and it still shows her as being in that zone. How does trackr update their location for her sensor thing. Does she have to have the app running on her phone? Or does someone near her just have to have it running on their phone?

I am not sure, I haven’t been able to test much with that. I believe it will update when anyone with the trackr app is near by. I don’t know how often the trackr app scan though, or how the phones GPS setting effect it.