Home assistant as tracking app #77
-
Lots of the self hosted community already run Home assistant which has the ability to track location. Is there a way to tap into this rather than run an additional app? |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 19 replies
-
I think at some point I'll research the possibility for HomeAssistant to send data to Dawarich. I'm not aware if there are any plugins allowing sending geodata to 3rd party URL, but if there are any, send me a link and example of payload, and I'll experiment with it. Meanwhile I asked Chatgpt are there ways to send this data to 3rd party urls, and it suggested using something like NodeRED or other webhooks-based solutions :) |
Beta Was this translation helpful? Give feedback.
-
hey, I was able to push Home assistant device location to Darawich with the RESTful Command integration. It could probably be improved, but it's a first working step. Here is how I configured it: # configuration.yaml
rest_command:
push_position_to_dawarich:
url: http://dawarich_dns:3000/api/v1/overland/batches?api_key={{ api_key }}
method: POST
content_type: 'application/json'
payload: >
{
"locations": [
{
"type": "Feature",
"geometry":{
"type": "Point",
"coordinates":[
{{ longitude }},
{{ latitude }}
]
},
"properties":{
"api_key": "xxxxxxxxxxxxx",
"timestamp": "{{ now().isoformat() }}",
"altitude": {{ altitude }},
"speed": {{ speed }},
"horizontal_accuracy": 0,
"vertical_accuracy": {{ vertical_accuracy }},
"motion": [],
"pauses": false,
"activity": "{{ activity }}",
"desired_accuracy": 0,
"deferred": 0,
"significant_change": "unknown",
"locations_in_payload": 1,
"device_id": "{{device_id}}",
"wifi": "unknown",
"battery_state": "unknown",
"battery_level": {{ battery_level }}
}
}
]
} Note: you have to restart homeassistant (and not reload the yaml files) the first time you add a rest_command, later you can use the and this the automation to call the rest command when the latitude or longitude of a device tracker changes. alias: Push pixel7 position to dawarich
description: ""
trigger:
- platform: state
entity_id:
- device_tracker.pixel_7
attribute: longitude
- platform: state
entity_id:
- device_tracker.pixel_7
attribute: latitude
condition: []
action:
- service: rest_command.push_position_to_dawarich
data:
latitude: "{{ state_attr('device_tracker.pixel_7','latitude') }}"
longitude: "{{ state_attr('device_tracker.pixel_7','longitude') }}"
speed: "{{ state_attr('device_tracker.pixel_7','speed') }}"
altitude: "{{ state_attr('device_tracker.pixel_7','altitude') }}"
vertical_accuracy: "{{ state_attr('device_tracker.pixel_7','vertical_accuracy') }}"
activity: "{{ states('sensor.pixel_7_detected_activity') }}"
device_id: pixel7
battery_level: "{{ states('sensor.pixel_7_battery_level') }}"
mode: single I used the overland format because it was the only one documented in the swagger api-docs. I would be nice to expose as well the owntrack api endpoint, and even nicer to add a generic api endpoint with a simple/flat json format with only the minimal required fields for darwarich. Edit: adding the api_key as template variable, to be able to resused the rest command with multiple device/users (each user in dawarich has its own api key) |
Beta Was this translation helpful? Give feedback.
-
Hello, do you have more information about the position of Home Assistant. I mean how freakantly is it updated? Another question. I have 2 users, how should this be configured? and than of course use the Dawarich API for each user. Is there a way to see which app pushed the locations update to Dawarich? |
Beta Was this translation helpful? Give feedback.
-
It would be nice to have the option even with less accuracy 👍
…On Sun, Jul 7, 2024, 12:58 drlobo ***@***.***> wrote:
I would say homeassistant app location updates are less frequent than a
dedicated app like owntracks, here is the documentation
<https://companion.home-assistant.io/docs/core/location/> from
homeassisant explaining when a location update is triggered.
I 've edited my code sample to allow the rest command to be resused with
multiple users, the api key in the url is now a variable that you can pass
in the automation data.
To compare home assistant and owncloud, I would simply create a new user
(one user for HA, one for Owntrack) and each app will push location with
it's own api key. If you do so, I would as well be interested in the
results, but I guess that owntrack will be more accurate
—
Reply to this email directly, view it on GitHub
<#77 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACVUTHQKNQLIMCMETFOF56DZLD7KPAVCNFSM6AAAAABJXVXMZCVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TSNZYGQYTS>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Thank you @drlobo for the head start! I would not have gotten there without your guide. My /opt/homeassistant/config/rest_command.yaml file:
My Automation yaml:
Notice, I'm using person.myuser so that whatever device the user has is what's being tracked - except one important thing... the trigger is based on a device. I know that I could use a variable to further streamline this, but this is a WIP, too. Maybe I'll update this again later, but I wanted to get this out for others. Does anyone know how to trigger on a PERSON changing location? |
Beta Was this translation helpful? Give feedback.
-
I didn't had time before but I just setup this link between HA and Dawarach and it's working fine. I have only one thing. It's because sometimes the location is changed very often even when I hardly move. |
Beta Was this translation helpful? Give feedback.
-
Working great for me as well. But one drawback I realized is that if you have no connection to your server (let's say your are hiking in a area without cell coverage or you are traveling without a mobil data plan for the country you are in) the locations data will be lost. This is sad as this might be some of the most interesting data. Any ideas for a workaround? I am aware this might be the intended behavior of home assistant but maybe someone here has an idea for a workaround. |
Beta Was this translation helpful? Give feedback.
-
Thank you to all here for helping integrate Home Assistant with Dawarich! I am testing this as a self-hosted replacement for Google Timeline. (it was nice of google to push me to another self-hosted alternative with their depreciation of Timeline 😀) Building off of these comments (#77 (comment) #77 (comment)), I iterated on these to be able use a single automation (utilizing configuration.yaml rest_command:
dawarich_push_position_rest_command:
url: https://sub.domain.tld/api/v1/overland/batches?api_key={{ api_key }}
method: POST
content_type: 'application/json'
payload: >
{
"locations": [
{
"type": "Feature",
"geometry":{
"type": "Point",
"coordinates":[
{{ longitude }},
{{ latitude }}
]
},
"properties":{
"api_key": "{{ api_key }}",
"timestamp": "{{ now().isoformat() }}",
"altitude": {{ altitude }},
"horizontal_accuracy": {{ horizontal_accuracy }},
"vertical_accuracy": {{ vertical_accuracy }},
"motion": [],
"pauses": false,
"locations_in_payload": 1,
"device_id": "{{device_id}}"
}
}
]
} I created the automation in the HA GUI editor, but here is the yaml from the generated automations alias: dawarich location push
description: rest command diy integration
triggers:
- entity_id:
- device_tracker.user1_composite_device_tracker
attribute: longitude
trigger: state
id: user1_location
- entity_id:
- device_tracker.user1_composite_device_tracker
attribute: latitude
trigger: state
id: user1_location
- entity_id:
- device_tracker.user2_composite_device_tracker
attribute: longitude
trigger: state
id: user2_location
- entity_id:
- device_tracker.user2_composite_device_tracker
attribute: latitude
trigger: state
id: user2_location
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id:
- user1_location
sequence:
- data:
api_key: xxx
latitude: "{{ state_attr(trigger.entity_id,'latitude') }}"
longitude: "{{ state_attr(trigger.entity_id,'longitude') }}"
altitude: >-
{{
state_attr(state_attr(trigger.entity_id,'last_entity_id'),'altitude')
}}
vertical_accuracy: >-
{{
state_attr(state_attr(trigger.entity_id,'last_entity_id'),'vertical_accuracy')
}}
horizontal_accuracy: >-
{{
state_attr(state_attr(trigger.entity_id,'last_entity_id'),'gps_accuracy')
}}
device_id: ha_user1_composite
action: rest_command.dawarich_push_position_rest_command
- conditions:
- condition: trigger
id:
- user2_location
sequence:
- data:
api_key: yyy
latitude: "{{ state_attr(trigger.entity_id,'latitude') }}"
longitude: "{{ state_attr(trigger.entity_id,'longitude') }}"
altitude: >-
{{
state_attr(state_attr(trigger.entity_id,'last_entity_id'),'altitude')
}}
vertical_accuracy: >-
{{
state_attr(state_attr(trigger.entity_id,'last_entity_id'),'vertical_accuracy')
}}
horizontal_accuracy: >-
{{
state_attr(state_attr(trigger.entity_id,'last_entity_id'),'gps_accuracy')
}}
device_id: ha_user2_composite
action: rest_command.dawarich_push_position_rest_command
mode: single
caveats:
|
Beta Was this translation helpful? Give feedback.
-
Thanks to all of the above suggestions I threw together a (very simple) custom Home Assistant integration. It can take a device tracker in HA, such as if you have installed the app, and then send the requests to your Dawarich server. It also displays your stats as sensors. It is still in the very early stages, and I don't have too much time to develop it, but if you want to try it it is available here. |
Beta Was this translation helpful? Give feedback.
-
Note for version 0.21.0: Updated the files below to use the new Authorization header method of sending the api key. I've also done testing with both iOS and Android devices and refined the data collection script to work with both. I wanted to set this up for myself and implemented it a bit differently, primarily because I have a multi-person household who will potentially use dawarich all getting data from Home Assistant so I wanted a more generically repeatable setup process. This was all done with the previous comments in mind so thank you everyone who made suggestions. First off, for the REST command I ended up going with the owntracks endpoint as the docs listed it as being for individual data points vs batch points. It also looked a bit easier to set up. I included every bit of information that seemed potentially relevant though I'm not sure how much of this beyond the GPS location is actually used.
Instead of a single automation I went with a script. This script is set up with fields to make it easier to interact with. Notably, I have it configured to execute in queued mode with a limit of 100. I haven't had the opportunity to tune that but I set that mode and limit on the assumption that multiple automations could end up calling the script and we want them executed one at a time and in order. For the entities to pick for your devices I went with what is given by the companion apps. If any of these don't work double check you have the sensor in question enabled in your companion app.
The automation is now very simple. Here's an example of an anonymized one using my phone.
|
Beta Was this translation helpful? Give feedback.
hey, I was able to push Home assistant device location to Darawich with the RESTful Command integration. It could probably be improved, but it's a first working step.
Here is how I configured it: