Home Assistant Community Add-on: Traccar

It should work on port 8072 which differs from traccar’s default one.

Due to a conflict with a port of motionEye, was changed:

https://github.com/hassio-addons/addon-traccar/issues/1

:tada: Release v0.5.1

Full Changelog

This is a general maintenance release.

Changed

  • :arrow_up: Upgrades add-on base image to v4.0.2

Questions? Join our Discord server! https://discord.me/hassioaddons
Enjoying my add-ons? Consider supporting my work: https://patreon.com/frenck

How do you get to see the “address”? (Streetname?) Mine doesn’t show that in HA.

Sign up at https://eu1.locationiq.com/ to get a key.
Then add this to your traccar.xml


    <entry key='geocoder.enable'>true</entry>
    <entry key='geocoder.type'>nominatim</entry>
    <entry key='geocoder.url'>https://eu1.locationiq.com/v1/reverse.php</entry>
    <entry key='geocoder.key'>xxxxxxxxxxxxxx</entry>
2 Likes

Hi,

I’m struggling to gain access to the server when I start it. I just get a bad gateway 502 error. I’m not using ingress, and set my port to 8072.
My config is otherwise default.

Here is my log file

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing... 
-----------------------------------------------------------
 Hass.io Add-on: Traccar
 Modern GPS Tracking Platform
-----------------------------------------------------------
 Add-on version: 0.5.1
 You are running the latest version of this add-on.
 System: HassOS 1.13  (armv7 / raspberrypi3)
 Home Assistant version: 0.96.5
 Supervisor version: 170
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] nginx.sh: executing... 
[cont-init.d] nginx.sh: exited 0.
[cont-init.d] traccar.sh: executing... 
[cont-init.d] traccar.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[10:48:08] INFO: Starting Traccar server...
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/traccar/lib/slf4j-jdk14-1.7.26.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/traccar/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.JDK14LoggerFactory]
2019-07-31 11:48:16  INFO: HikariPool-1 - Starting...
2019-07-31 11:48:20  INFO: HikariPool-1 - Start completed.
2019-07-31 11:48:30  INFO: Clearing database change log checksums
2019-07-31 11:48:31  INFO: SELECT COUNT(*) FROM PUBLIC.DATABASECHANGELOGLOCK
2019-07-31 11:48:31  INFO: SELECT COUNT(*) FROM PUBLIC.DATABASECHANGELOGLOCK
2019-07-31 11:48:31  INFO: SELECT LOCKED FROM PUBLIC.DATABASECHANGELOGLOCK WHERE ID=1
2019-07-31 11:48:31  INFO: Waiting for changelog lock....
2019-07-31 11:48:41  INFO: SELECT LOCKED FROM PUBLIC.DATABASECHANGELOGLOCK WHERE ID=1
2019-07-31 11:48:41  INFO: Waiting for changelog lock....

It just then repeats these 2 lines

Any clues?

If you want to use Nabu Casa webhooks with the Traccar add-on have a look at this post -> Traccar via Nabu Casa webhooks.

hello, working very well, a question … you have to add something to the mariadb addon to change the traccar database, I’m not sure about the configuration

I appreciate the work of frenck, but setting up this add on was a mess for me. Mainly for lack of documentation.

I found different problems:

  1. Make the ui work
  2. Send data to traccar from a device (eg. mobile application)
  3. Let hassio discover the device

I’ll try to explain here how I solved these three problems.

Make the ui work
This does not require any port forwarding from the router.
Here I faced two problem:

  1. UI returned 502 bad gateway
  2. The addon was blocked in an inconsistent while querying DATABASECHANGELOGLOCK table

To solve 1, you simply have to wait. The addon is freaking slow to start. Until you won’t see that nginx is actually started, the addon is not ready.
So wait at least 5 minutes or more after restarting the application.

2 occurs if you stop the addon while it is starting up. In order to restore the state you have to send a command to the database.
I had MariaDB installed, so to solve this problem I entered in the docker container where MariaDB was running and executed the following query:
MariaDB [traccar]> update DATABASECHANGELOGLOCK set locked = 0;
In order to enter the docker container I logged using ssh using:

ssh [email protected] -p 22222

Then executed the login command.
Then executed docker ps, copied the id of the docker container where MariaDB is running and executed the command:
docker exec -it DOCKER_ID_MARIA_DB mysql -D TRACCAR_DB_NAME, where TRACCAR_DB_NAME is the name you have assigned to the traccar db.
Now you can execute the previous command.

Refer to this guide to login in ssh in advanced mode: https://developers.home-assistant.io/docs/en/hassio_debugging.html
Refer to this guide to use MariaDB as DB for traccar: https://github.com/hassio-addons/addon-traccar
Refer to this guide to set up Maria DB: https://www.home-assistant.io/addons/mariadb/

Once you removed the lock, the addon should proceed to the next step. Remember, the addon is very slow to start, so be patient.

2. Send data to traccar from a device (eg. mobile application)
This does require port forwarding from the router.
If you use a mobile application, you need to forward a port of your router (eg. 5055) to the 5055 of your hassio.
Prior to download or test the mobile application, my advice is to do a curl (or use a software like postman) to test that the API to send coordinates work.
I used the following curl:

curl --request POST \
  --url 'http://MY_DOMAIN.duckdns.org:5055/?lat=40&lon=20&id=123456'

This will return 200 if everything was setup correctly. Do not waste time using the application until this curl does not return 200.

Once the curl wors, you can proceed and download the mobile application. I used the iOS one. Since the endpoint worked previously, you simply need to copy
http://MY_DOMAIN.duckdns.org:5055/?lat=40&lon=20&id=123456 in the server URL textfield of the app.
If you enable Service Status and check the status, you should not see any Send Failed.

Now login to the Web UI and manually add the device to the interface using the device identifier that was present on the app. Give the device a friendly name and KISS because this will be the name of the device that will appear in hassio.

If after the data send, the device will show on the traccar UI map, everything worked so far.

  1. Let hassio discover the device
    This does not require port forwarding from the router.
    To do that, hassio needs to do a curl to the traccar service that is running on the traccar container.
    In the traccar addon page, this is my configuration:
{
  "ssl": true,
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem",
  "log_level": "debug"
}

and I also enabled the port 8072 under the Network section.

Remember to restart the addon, if you do any change to your configuration (and be patient waiting the full addon restart).

Prior to edit the configuration.yml, test again with a curl if hassio is able to do a request to the traccar addon.
As we did in point to, ssh to hassio using:

ssh [email protected] -p 22222

Then, search the hassio container using the docker ps command (its friendly name should be homeassistant) and enter that container using the command:
docker exec -it homeassistant bash (or sh, if bash is not available).

Once you are in, use the command:
wget -O- --no-check-certificate https://hassio:8072

8072 is the port you previously add on the Network section of the addon.

This should return an HTML containing the text:

...
<div id="attribution">Powered by <a href="https://www.traccar.org/">Traccar GPS Tracking System</a></div>
...

Remember that:

  • --no-check-certificate corresponds to the property verify-ssl: false, on configuration.yaml
  • https corresponds to the property ssl: true
    If this does not work try the followings until one of this works:
    wget -O- --no-check-certificate https://localhost:8072
    wget -O- --no-check-certificate https://hassio:8072
    wget -O- --no-check-certificate https://HASSIO_INTERAL_IP:8072

Depending on your configuration, you may need to do not use the flag --no-check-certificate or use http in place of https.

When you made this work, compose your configuration like this:

device_tracker:
  - platform: traccar
    host: hassio
    port: 8072
    ssl: true
    verify_ssl: false
    username: YOUR_USERNAME
    password: YOUR_PASSWORD

That corresponds to the following curl:
wget -O- --no-check-certificate https://hassio:8072
because:

  • host comes from https://hassio:8072
  • port comes from https://hassio:8072
  • ssl: true comes form https://hassio:8072
  • verify_ssl: false comes from –no-check-certificate

Add this in the configuration.yaml, restart hassio and everything should work.

If this does not work, the last check that you can do is to enter the traccar container (docker exec -it addon_a0d7b954_traccar sh) and use this command:
netstat -lutanp | grep nginx
This is my output:

tcp        0      0 0.0.0.0:8072            0.0.0.0:*               LISTEN      388/nginx: master p
tcp        0      0 172.30.32.1:63998       0.0.0.0:*               LISTEN      388/nginx: master p
tcp        0      0 127.0.1.1:8072          127.0.0.1:40558         ESTABLISHED 1298/nginx: worker
udp        0      0 172.30.32.1:49636       172.30.32.2:53          ESTABLISHED 1298/nginx: worker

As you can see in the first row, this container is exposing on the public interface (0.0.0.0 LISTEN) the port 8072. If this is different from the one you wrote, probably there is some misconfiguration.

P.S.: I am sure this guide will not fit your exact case, but I am sure can help you in debugging your problem.

2 Likes

:tada: Release v0.5.2

Full Changelog

This is a general maintenance release.

Changed

  • :arrow_up: Upgrades add-on base image to v4.0.3

Questions? Join our Discord server! https://discord.me/hassioaddons
Enjoying my add-ons? Consider supporting my work: https://patreon.com/frenck

Can someone pls advice.
I have finally made the connection from iOS app to Traccar in Hassio but, I dont see any device tracker entity in HA :woozy_face:

How have you made the “connection” between the Traccar IOS app and the Traccar-server running on Home Assistant?

Port forward 5055 and just in case also 8072. What did the trick I think for me is just put the http not https in ios app server address.

In device_tracker config both host works:

host: a0d7b954-traccar or the local ip of HA

I have also added port 8072 in traccar web port in the plugin config section.

But like I said I dont see any entity in device tracker…

1 Like

Does your IOS Traccar app provide a Device Identifier (a 6-digit number)?

You need to login into your local Traccar web page (via OPEN WEB UI) and add your Device (using the + button).
Give the Device a unique name and in the Identifier-field put the Device Identifier number from the Traccar app.

I have used traccar before, therefore yes I have already done this. I can see my device in traccar web ui and the location is updating. Why I don’t see any device_tracker entity in HA its a mystery for me.

Sooo, thanks to @daaaaa , sorry BIG THANKS, I have finally made it. I have read his nice long post and what did the trick for me was just to remove from configuration file in HA http(s) from host line. Thanks again @daaaaa

2019-07-31 11:48:41 INFO: SELECT LOCKED FROM PUBLIC.DATABASECHANGELOGLOCK WHERE ID=1
2019-07-31 11:48:41 INFO: Waiting for changelog lock…

Did you solve this by the way? I’m having the same issue right now! It only happends when the power is cut to the raspberry pi! The way I solve it is by uninstalling and installing the MariaDB addon again so it creates a new database but that removes everything stored! Very annoying because I really wanna use this addon! If anyone have some advice with this situation please contact me <3

I think you need to use Mariadb database not the SQLite which is build in. I am using the hassio addon MariaDB and it works nicely.

  1. Follow the instruction how to install MariaDB add-on and put this in config - change the passwords as you like.
{
  "databases": [
    "homeassistant",
    "traccar"
  ],
  "logins": [
    {
      "username": "hass",
      "host": "%",
      "password": "your_password"
    },
    {
      "username": "traccar",
      "host": "%",
      "password": "your_password"
    }
  ],
  "rights": [
    {
      "username": "hass",
      "host": "%",
      "database": "homeassistant",
      "grant": "ALL PRIVILEGES ON"
    },
    {
      "username": "traccar",
      "host": "%",
      "database": "traccar",
      "grant": "ALL PRIVILEGES ON"
    }
  ]
}
  1. Then you need to add this in configuration.yaml:
recorder:
  db_url: mysql://hass:your_password@core-mariadb/homeassistant?charset=utf8
  1. Uncomment the 4 lines as per this link https://github.com/hassio-addons/addon-traccar and change the password in traccar.xml file.
1 Like

:tada: Release v0.5.3

Full Changelog

This is a general maintenance release.

Changed

  • :arrow_up: Upgrades nginx to 1.16.1-r0
  • :arrow_up: Upgrades openjdk8-jre to 8.212.04-r1
  • :ambulance:Fix ability to have SSL certs in folders (#24)
  • :arrow_up: Upgrades add-on base image to v4.1.1
  • :hammer: Use Hass.io DNS as NGinx resolver

Questions? Join our Discord server! https://discord.me/hassioaddons
Enjoying my add-ons? Consider supporting my work: https://patreon.com/frenck

:tada: Release v0.5.4

Full Changelog

This is a general maintenance release.

Changed

  • :arrow_up: Upgrades Traccar to v4.6

Questions? Join our Discord server! https://discord.me/hassioaddons
Enjoying my add-ons? Consider supporting my work: https://patreon.com/frenck

Ok, so I need that to launch Traccar, I’d read it as a stability issue. Ok will give it a go!