Traccar.org (GPS/GPRS Tracker) custom platform

I’m still using owntracks on my/wife iphones for presence tracking.
i’m also using ot-recorder to log all tracks for future (statistics) projects.
Exporting the traccar data to ot-recorder makes sense in this scenario.
ot-recorder can receive traccar data sent via the traccar app directly i believe but havent looked in to it.

I you have a device that is working with traccar server this component will fetch the location data from the traccar server.
Check the traccar forums for supported gsm/gprs trackers.

I was curious as my experience with owntracks was not very reliable, and traccar works well with iphone.
I was going to ask if you had any suggestions for trackers (realtime) vehicle or personal

It’s broken again!

Not sure if the bug is yours or core. How do I submit a bug report. I believe it has to do with tcp connection/package.

I attached my log, but have no idea where it is.

https://github.com/home-assistant/home-assistant/issues/9207

Do you think that you will merge this into the master home assitant git?

Another install, and still no luck.

- platform: traccar
  username: !secret traccar_username
  password: !secret traccar_password
  host: http://192.168.2.41:8082

Traccar server runs fine, Traccar UI works as expected, but continuous error. (fresh start and this is the error)

2017-08-29 02:12:13 WARNING (Recorder) [homeassistant.components.recorder] Ended unfinished session (id=11 from 2017-08-26 00:44:27.161237)
2017-08-29 02:12:16 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform traccar
Traceback (most recent call last):
File “/usr/src/app/homeassistant/components/device_tracker/init.py”, line 160, in async_setup_platform
disc_info)
File “/usr/local/lib/python3.6/asyncio/futures.py”, line 332, in iter
yield self # This tells Task to wait for completion.
File “/usr/local/lib/python3.6/asyncio/tasks.py”, line 250, in _wakeup
future.result()
File “/usr/local/lib/python3.6/asyncio/futures.py”, line 245, in result
raise self._exception
File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/device_tracker/traccar.py”, line 28, in setup_scanner
TraccarDeviceScanner(hass, config, see)
File “/config/custom_components/device_tracker/traccar.py”, line 41, in init
self._update_info()
File “/config/custom_components/device_tracker/traccar.py”, line 51, in _update_info
self._positions_data = json.loads(self._positions.text)
File “/usr/local/lib/python3.6/json/init.py”, line 354, in loads
return _default_decoder.decode(s)
File “/usr/local/lib/python3.6/json/decoder.py”, line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/local/lib/python3.6/json/decoder.py”, line 357, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
2017-08-29 02:12:57 WARNING (MainThread) [homeassistant.helpers.entity] Update for media_player.lounge is already in progress
2017-08-29 02:13:02 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.

Not all clients are active, it is 2:30 am

[
{
“id”: 1,
“attributes”: {},
“name”: “Randy”,
“uniqueId”: “669555”,
“status”: “online”,
“lastUpdate”: “2017-08-29T06:22:09.768+0000”,
“positionId”: 1707,
“groupId”: 0,
“geofenceIds”: ,
“phone”: “Samsung”,
“model”: “Note 5”,
“contact”: “”,
“category”: “person”
},
{
“id”: 3,
“attributes”: {},
“name”: “Koral”,
“uniqueId”: “561764”,
“status”: “unknown”,
“lastUpdate”: “2017-08-29T05:07:54.282+0000”,
“positionId”: 1694,
“groupId”: 0,
“geofenceIds”: ,
“phone”: “Samsung”,
“model”: “G4”,
“contact”: “”,
“category”: “animal”
},
{
“id”: 4,
“attributes”: {},
“name”: “Kelsey”,
“uniqueId”: “460488”,
“status”: “offline”,
“lastUpdate”: “2017-08-28T17:07:50.359+0000”,
“positionId”: 1297,
“groupId”: 0,
“geofenceIds”: ,
“phone”: “Apple”,
“model”: “?”,
“contact”: “”,
“category”: “van”
},
{
“id”: 5,
“attributes”: {},
“name”: “Kaylee”,
“uniqueId”: “220894”,
“status”: “unknown”,
“lastUpdate”: “2017-08-29T03:35:10.385+0000”,
“positionId”: 1676,
“groupId”: 0,
“geofenceIds”: ,
“phone”: “”,
“model”: “”,
“contact”: “”,
“category”: “animal”
},
{
“id”: 6,
“attributes”: {},
“name”: “Laurie”,
“uniqueId”: “764619”,
“status”: “online”,
“lastUpdate”: “2017-08-29T06:21:24.338+0000”,
“positionId”: 1706,
“groupId”: 0,
“geofenceIds”: ,
“phone”: “”,
“model”: “”,
“contact”: “”,
“category”: null
}
]

Are you sure you are using the latest version?

Could you paste your positions json repsonse?
I’m guessing somethings going wrong there…
The first line “#-- coding: utf-8 --” in the compent is important for the component to work with ü and á like characters in adresses and stuff.

yes, exactly like your example here.

device_tracker.1 not_home source_type: null
friendly_name: Randy
icon: mdi:castle
device_tracker.3 not_home source_type: null
friendly_name: Koral
device_tracker.4 not_home source_type: null
friendly_name: Kelsey
icon: mdi:donkey
device_tracker.5 not_home source_type: null
friendly_name: Kaylee
device_tracker.6 not_home source_type: null
friendly_name: Laurie

[{“id”:1,“attributes”:{},“name”:“Randy”,“uniqueId”:“669555”,“status”:“online”,“lastUpdate”:“2017-08-29T06:29:36.378+0000”,“positionId”:1711,“groupId”:0,“geofenceIds”:[],“phone”:“Samsung”,“model”:“Note 5”,“contact”:"",“category”:“person”},{“id”:3,“attributes”:{},“name”:“Koral”,“uniqueId”:“561764”,“status”:“offline”,“lastUpdate”:“2017-08-29T05:07:54.282+0000”,“positionId”:1694,“groupId”:0,“geofenceIds”:[],“phone”:“Samsung”,“model”:“G4”,“contact”:"",“category”:“animal”},{“id”:4,“attributes”:{},“name”:“Kelsey”,“uniqueId”:“460488”,“status”:“offline”,“lastUpdate”:“2017-08-28T17:07:50.359+0000”,“positionId”:1297,“groupId”:0,“geofenceIds”:[],“phone”:“Apple”,“model”:"?",“contact”:"",“category”:“van”},{“id”:5,“attributes”:{},“name”:“Kaylee”,“uniqueId”:“220894”,“status”:“offline”,“lastUpdate”:“2017-08-29T03:35:10.385+0000”,“positionId”:1676,“groupId”:0,“geofenceIds”:[],“phone”:"",“model”:"",“contact”:"",“category”:“animal”},{“id”:6,“attributes”:{},“name”:“Laurie”,“uniqueId”:“764619”,“status”:“online”,“lastUpdate”:“2017-08-29T06:28:38.671+0000”,“positionId”:1710,“groupId”:0,“geofenceIds”:[],“phone”:"",“model”:"",“contact”:"",“category”:null}]

There is no Lat or Lon in that json is there? Thi is the correct way to get that information is it not: http://192.168.2.41:8082/api/devices

http://192.168.2.41:8082/api/positions

No that doesn’t work, file not found

are you using Internet Explorer? use Chrome or safari to open the URL.
It should ask you for the usename + password for the traccar platform.

traccar is running and I’m able to use other api commands with results, just a couple shows no file found IE is the only one I did not use.

Well three days later and more hours than I can count, and the issue seems to be don’t install traccar on F: drive in windows; use the C: drive. It’s working now and I can load the positions file. (time will tell as I had same issue using the demo server)

Now that I see the information that you can draw from how about adding battery level.

Thanks for your help.

Again that did not last long.

The issue maybe in HTTP Headers, I don’t see any and according to Anton they are required for the API. If I knew how to add it I would as this is getting old quick, well not too quick I have been working on this for about a week blaming everything.

And again I can not see the local api/positions, Anton said that it really is a hit and miss doing it that way as the header can’t be stated in address bar and the web app just picks one, but it definitely needs to be defined in scripts.

Anton gave me this link http://docs.python-requests.org/en/master/user/quickstart/#custom-headers

Can you please take a look at it and tell me how to implement in your script?

Definitely the issue: I’m able to curl the api and get updated data, but need to use the header command.

I used git bash for curl: Windows:: https://git-scm.com/download/win

$ curl -u username:password -H “Accept: application/json” ‘http://192.168.2.41:8082/api/positions

I was able to see updated information, so it’s there but the script cannot read it, nor can I just using the address bar.

Well the timer starts again, I got it to work by adding: CONTENT_TYPE_JSON

to this line in your script, unknown if anything else needs to be done

from homeassistant.const import CONF_NAME, CONF_USERNAME, CONF_PASSWORD, CONTENT_TYPE_JSON

Thank you for looking and contacting the traccar author himself for debug :slight_smile:

could try this version? i
added a custom header to the devices and positions request as stated in the traccar api

I’ll give it a try later, you have an error with a forgotten space between the first header.

Anton is a little short and sparse with his answers but the guy knows his app and seems to send everybody in the right direction if they listen.

>         self._devices = requests.get(self._host + '/api/devices', auth=(self._username, self._password),headers = ({'Accept': 'application/json'}))
>         self._device_data = json.loads(self._devices.text)
>         self._positions = requests.get(self._host + '/api/positions', auth=(self._username, self._password), headers = ({'Accept': 'application/json'}))
>         self._positions_data = json.loads(self._positions.text)