if anyone is interested I have developed this simple package to send data from any device_tracker from Home Assistant to Traccar, a popular open-source GPS tracking system, already integrated in HA but from Traccar to HA.
For example, I used it to track on Traccar phones that are already being tracked with Home Assistantās iOS/Android app, without having to install any other software that sends data to Traccar (and without exposing Traccar outside my network) and my electric scooter (Silence) integrated in HA but not on Traccar.
I think Traccar is much better than Home Assistant for storing and showing travel history data, while Home Assistant is much better for automations and everything else.
Thanks for sharing Lorenzo!
Works like a charm.
I would like to add a button with tekstbox in home assistant to send an annotation to traccar for when i see something while travelling i want to remember where approx. it is on the map.
I write it in documentation, for updates I use default protocol that runs on port 5055
I never try on public demo Traccar server but I guarantee that on local server works :slight_smile
Iām using your automation and it works great (thank you for sharing) but I have an issue with battery level with one of my devices. Iām tracking 2 samsung smartphones and a senseCAP T1000-A tracking device. Battery level are correct for my 2 smartphones but stays at 0% for my tracker. In the Sensecap integration, I can clearly see that battery level is reported correctly:
Hello, yes, can be a solution.
This is because, on HA App devices the state attribute for battery is ābattery_levelā, but, in your case is only ābatteryā.
So, maybe I can add another check, and, for backward compatibility, check for both ābatteryā and ābattery_levelā.
Can you try this version
My curiosity, how works senseCAP T1000-A ? do you use with your LoRa network? with Meshtastic or something?
Are you in EU or US?
Just to chime in on this - most device trackers donāt report the battery as an attribute any more (ha companion app as one example) so itās a separate sensor that isnāt tied to the device tracker id. I actually ended up dropping battery level support as i have that info in ha and I only need the location!
@lorenzo-deluca Thanks for your hardwork! Wish I found this before I rolled my own - wouldāve saved an hour! I actually just list my device trackers (wish there was some efficient way to run for all domain:device_tracker) with the automation below.
Also I noticed in your automation you have a condition for the from state being unavailable - would this not prevent updating in the event a device tracker changed fro unavailable to a location?
alias: Traccar Updater
description: ""
triggers:
- entity_id:
- device_tracker.pixel_8
- device_tracker.juno_tracker
- device_tracker.niro_ev_19_location
- device_tracker.sm_g780g
trigger: state
conditions:
- condition: template
value_template: '{{ trigger.to_state.state not in [''unknown'', ''unavailable''] }}'
actions:
- data:
input: >
{% set device = trigger.entity_id %} {% set timestamp = now() |
as_timestamp | int %} {% set lat = state_attr(device, 'latitude') %} {%
set lon = state_attr(device, 'longitude') %} {% set accuracy =
state_attr(device, 'gps_accuracy') | float %}
id={{device}}&valid=1×tamp={{timestamp}}&lat={{lat}}&lon={{lon}}&accuracy={{accuracy}}
action: rest_command.update_traccar
Honestly, I havenāt even thought about it because I think itās the wrong place to keep the history⦠it doesnāt normally keep more than a few daysā worth of travel history on home assistant.
i had made a python script that opened the SQLite database but it was very slow and caused problems for HAā¦
Thanks. Yes, after doing some more looking around I realised that I didnāt have any particular history in HA to import. I managed to miss that my old google data was all deleted at the end of last year so was casting around for alternatives. Oh well. This is still great for future use.
Hi, Iām sorry I think I never replied to your questions.
The SenseCAP T1000-A is working okā¦ish :
I can get GPS positionning if itās exposed to clear sky.
It doesnāt work when in a bag for example.
Iāve never really managed to get GNSS+WIFI to work, itās either one or the other (which may also be a user error, Iām not a pro).
Thereās a limitation on how frequently you can send data (itās a LoRa network limitation I believe, not a T1000-A one), itās not really designed to get quick GPS positionning, but if speed is not needed, then it works pretty well.
As soon as it gets connection to a LoRa gateway it sends its data. It can take some time if gateway is slow or if it has a lot of position-history to upload.
I use it on a LoRa Gateway I just bought for the test. I tried other LoRa provider but I was not able to get it working. Iām based in EU. France to be precise.
I have a node-red instance in my HA that is getting data from the software stack provided by the gateway, performs data-processing and then updates a Traccar instance.
I got a SenseCAP T1000-A as well and can confirm your opinion.
Small form-factor but mediocre reception of both GPS and LoRaWAN.
I did test it with Helium and The Things Network LoRaWAN global networks and did not get persistant location tracking. TTN has not as many gateways as Helium (which is also declining) so the coverage in the wild of Germany is not optimal.
This tracker can be set to cache GPS fixes to upload when getting a LoRa connection which might help in some cases but not when helping LoRa coverage mapping (TTN mapper).
Which local gateway and software are you using? I recently got some 2nd hand Senscap M1 for cheap, testing with local Chirpstack and global TTN.
Getting geolocation into Homeassistant was not that easy (Node Red, MQTT, yaml, using HA actions to update GPS tracking device) for me. In HA the longitude and latitude seem to be updated not in sync, resulting in a shifted location.
I got it to work with a bit of a struggle. For others that might want to do this, here are my notesā¦
I didnāt use the āpackagesā thing as I already had some Rest commands in my configuration.yaml file. I just added this new one thus
rest_command:
...
other rest commands
...
update_traccar:
url: "http://<My domain name>:5055"
method: GET
payload: "?id={{id}}&lat={{lat}}&lon={{lon}}&altitude={{alt}}&batt={{batt}}&speed={{speed}}"
Note - http not https!
I didnāt use the Blueprint but just added the following automationā¦
alias: Traccar Update
description: >-
This, together with the Rest command in configuration.yaml, updates Traccar
with the position of the entities in order to store the history
triggers:
- trigger: state
entity_id:
- device_tracker.uis8581a
conditions:
- condition: template
value_template: "{{ trigger.from_state.state not in ['unknown', 'unavailable'] }}"
- condition: template
value_template: "{{ trigger.to_state.state not in ['unknown', 'unavailable'] }}"
actions:
- action: rest_command.update_traccar
continue_on_error: true
data:
id: "{{ trigger.entity_id }}"
lat: "{{ state_attr(trigger.entity_id, \"latitude\") | float(0) }}"
lon: "{{ state_attr(trigger.entity_id, \"longitude\") | float(0) }}"
alt: "{{ state_attr(trigger.entity_id, \"altitude\") | float(0) }}"
batt: "100"
speed: "{{ state_attr(trigger.entity_id, \"speed\") | float(0) }}"
mode: parallel
max: 10
Battery wasnāt being reported by my device so I just set it to 100.
I used the entity id device_tracker.uis8581a as the corresponding id when setting up the device in Traccar.
Note - If you try to run the Actions manually in the automation to test it, it will fail as there is no trigger.entity_id. So i tested it by going into Developer Tools/States selecting the entity and changing its state to away (then back to home). Traccar got the updates and reported it as online. Examination of the automation trace showed it all worked fine.
Thanks again - I learnt some stuff working through this.