Traccar integration via MQTT

Hi,

I want to integrate my Traccer server into my Home Assistant instance via MQTT. I want to track my cars as well as trigger different actions when any of the cars enters an area or leave it (at least this basic triggers).

I see the MQTT messages, so hopefully Traccar is already configured properly but I don’t know how to parse incoming MQTT messages in Home Assistant, make cars visible on the map and make scripts/automatons/etc work with.

Traccar can have more then just one car so it would be nice to avoid hardcoded car names in Home Assistant.

Any idea how to configure?

Here is an example MQTT message I get from Traccar:


{
    "event": {
        "id": 11640,
        "attributes": {},
        "deviceId": 1,
        "type": "deviceStopped",
        "eventTime": "2024-05-21T10:20:58.000+00:00",
        "positionId": 1581151,
        "geofenceId": 0,
        "maintenanceId": 0
    },
    "position": {
        "id": 1581151,
        "attributes": {
            "priority": 0,
            "sat": 15,
            "event": 0,
            "ignition": false,
            "motion": false,
            "io80": 0,
            "rssi": 5,
            "io200": 0,
            "io69": 1,
            "io29": 0,
            "io113": 87,
            "io263": 1,
            "io246": 0,
            "io252": 0,
            "pdop": 1.2000000000000002,
            "hdop": 0.8,
            "power": 12.717,
            "io24": 0,
            "io205": 5103,
            "io206": 93,
            "battery": 3.977,
            "operator": 21630,
            "distance": 0.0,
            "totalDistance": 23500160.497852825,
            "hours": 1802647310
        },
        "deviceId": 1,
        "protocol": "teltonika",
        "serverTime": "2024-05-21T10:21:01.739+00:00",
        "deviceTime": "2024-05-21T10:20:58.000+00:00",
        "fixTime": "2024-05-21T10:20:58.000+00:00",
        "outdated": false,
        "valid": true,
        "latitude": REDACTED,
        "longitude": REDACTED,
        "altitude": 223.0,
        "speed": 0.0,
        "course": 291.0,
        "address": null,
        "accuracy": 0.0,
        "network": null,
        "geofenceIds": null
    },
    "device": {
        "id": 1,
        "attributes": {},
        "groupId": 1,
        "calendarId": 0,
        "name": "MyOpelCar",
        "uniqueId": "REDACTED",
        "status": "online",
        "lastUpdate": "2024-05-21T10:21:01.740+00:00",
        "positionId": 1579232,
        "phone": "REDACTED",
        "model": "Opel",
        "contact": null,
        "category": "car",
        "disabled": false,
        "expirationTime": null
    }
}

Why do you want to use MQTT instead of the inbuild traccar integration?

The inbuild traccar integration requires to allow my HA instance reachable from the public internet what I don’t want to do.

Traccar client available in HA receives data from traccar server via webhook where HA is the REST server. That’s not acceptable for me because of security reasons.

I have a traccar server somewhere on the internet while HA is inside my LAN.

I want to use MQTT as a general communication bus for all my IOT equipment. I can set MQTT to use TLS and proper ACL rules to be secure enough use it on top of public internet.

Hello @halacs could you share with me what configuration you used to receive information from Traccar via broker?

I tried this configuration, but without success.

 <entry key='positions.forward.type'>mqtt</entry>
 <entry key='positions.forward.url'>mqtt://XXXXXXXXXX@XXXXXXX:1883</entry>
 <entry key='positions.forward.topic'>traccar/positions</entry>

In any case, you will need to have an mqtt server open to the internet, whether local or on a vps. Then you handle access via firewall rules to allow access to port 1883 only from your Traccar server IP.
Unfortunately, Cloudflare’s free tunneling service does not work with the mqtt protocol.