Mobile install - Auto update Home location in a van/boat using a GPS capable router and Traccar

The problem:
HA installed in a van (or boat, etc) which makes zone based automations very difficult or rather impassible.

There is a really good topic showing how to achieve this in great detail so why bother with another take on this, you ask. Not to forget the fact that I am new to the game and know very little about HA. Well, because it’s easier for a novice like me…

Prerequisites:

  • mobile HA installation or otherwise why bother with this at all?!? :grinning:
  • GPS capable router (like the Teltonika RUTX11) or any other GPS device capable to communicate with Traccar

The above-mentioned router is capable of reporting the lat & lon values over MQTT as well, the reason I went with Traccar is because it can help with service intervals (after set mileage reached) and I also use it for my car as well.

Both HA (as a VM) and Traccar (as an LXC container) run in a Proxmox install on my home server in the van, right next to the Teltonika router. On the router I set up an AVL server in the Services menu which sends data to my Traccar install. On the Traccar server I made a restricted user for HA with readonly privileges to view the van location. You can use the Traccar addon but I decided I want my HA instance as light as possible with as few addons as possible.

Now let’s talk about the HA side of things…

To integrate your Traccar instance into HA you need to copy this to your configuration.yaml:

device_tracker:
  - platform: traccar
    host: 192.168.xxx.xxx #your_traccar_IP
    port: 8082
    username: your_traccar_user
    password: your_traccar_password
    new_device_defaults:
      track_new_devices: true

You need to create a couple of sensors (latitude and longitude) but I created some more for later use like vehicle speed. This also should be included in your configuration.yaml or you can put the whole thing into a traccar.yaml file but don’t forget to reference that file in your config.

template:
  - sensor:
      - name: "van_latitude"
        state: "{{ state_attr('device_tracker.crafter', 'latitude') | float }}"
      - name: "van_longitude"
        state: "{{ state_attr('device_tracker.crafter', 'longitude') | float }}"
      - name: "van_altitude"
        state: "{{ state_attr('device_tracker.crafter', 'altitude') | float }}"
      - name: "van_speed"
        state: "{{ state_attr('device_tracker.crafter', 'speed') | float }}"

At this point you can test if the Traccar integration works in HA and your sensors are reporting the correct values.

Then comes the automation. I could not imagine an easy way to do this, I had nightmares for weeks. Not really, but anyway. I was scrolling through services and there it was: “homeassistant.set_location”!!! I could not believe my eyes :joy: If this is not beginner’s luck then what is?!

I implemented a 5 minutes delay so on a long drive HA does not get mad updating its location every 20 seconds or so.

alias: Homezone Update
description: ""
trigger:
  - platform: state
    entity_id:
      - device_tracker.crafter
    from: home
    to: not_home
    for:
      hours: 0
      minutes: 5
      seconds: 00
condition: []
action:
  - service: homeassistant.set_location
    data_template:
      latitude: |
        {{ state_attr('device_tracker.crafter', 'latitude') }}
      longitude: |
        {{ state_attr('device_tracker.crafter', 'longitude') }}
mode: single

And that’s it. No Raspberry Pi, no python script, gpsd connected rpiclient, just a simple copy paste exercise for you. For me it took a couple of days or more and some help to figure out the syntax but hey, we want to have some fun, right?

3 Likes

This is so simple and easy for all of us campers! Thank you for that! To test it just move your Home location away from your tracker and wait! You can do that under settings-> system → general (1. point) → edit location (last at bottom) just pick the house and move it away and wait for more than 5 minutes!

Big ask but I am not at all techy. I would really appreciate it if you could give me a guide on how to set up the Teltonika router. I have just spent the last two days and at the moment I still can’t get the router on line in the traccar server, I’ve enabled gps and put the correct imei in but the traccar server keeps showing it as offline no matter what I alter, really am thrashing about in the dark.
Thanks.

No worries.

  1. What router do you have, please?
  2. Where do you run your traccar server?

Cheers

Just a thought :slight_smile:

Did you config your traccar server for the teltonika port?!?

It needs to go to /config/traccar.xml

<entry key='teltonika.port'>5027</entry>

Thanks for your response ,super quick :+1: didn’t expect that.
This is my set up. I have a RUT955 connected by eth to a pi4 running haos supervised. Although I’m not a total newby my back ground was more hands on until I retired. I’ve spent a couple of years running and learning about h/a in my home and now have a basic knowledge but it’s a long hard slog these days. I was trying to run my m/h instance through a cloudflare tunnel which worked well enough untill I installed traccar on it . I thought at first that was the problem because cloudflared sits on the pi4. Anyway I digress, routers are not my forte I know didly really but I did figure out the gps and Avl server at a very basic level.
Port 5027 is in avl settings but I suspect I’ve got some thing major wrong with something in the router. The map and location show up in the gps settings but when I add the imei to traccar it just shows offline.

very greatfull for your quick response
thanks
Les