Owntracks - How to Update Device Tracker via HTTP (Without Owntracks)

I do not know about remote config of owntracks android client via HA. All im using is the http owntracks sensor via manually creating the input with a http rest api service call

I think I need that too…
Somewhere in HA I need to setup somekind of configuration, so all Android clients can read that json…

My goal is to define the monitoring mode from HA, so that I can disable gps on android from HA when it’s not needed… To preserve battery…

How did you setup that sensor?

You could probably employ a push message and then use tasker or automate to enable / disable GPS.

The Sensor can be setup as described in my first post. Simply send all the values via HTTP Rest API. You could copy the layout of an already existing sensor.

Hi, thnx, but thats the beauty of it, i dont need tasker normally, with http mode its actually possible to send remote config to the android client

so yes, i need something like you in the first post, but i dont understand the link?

how do you make a sensor, with the json below in it, and how do you push it trough a client?

{
"_type":"cmd",
"action":"setConfiguration",
"configuration":
{
"_type": "configuration",
"monitoring": 2
}
}

Just send it to the API. It will be created with the name you choose.
https://developers.home-assistant.io/docs/en/external_api_rest.html

yeah, if i send the state to the API, but how is it linked to the android client? where do you specify the android client were you want to send the remote config too ? is it that “tid”: “02”

is that somekind of unique id?

I am not sending anything to any android client. My Android will send the state to the API. Thats it. I use it to save my parking position with the car without having owntracks even installed. I just “emulate” the owntracks app.

ok, thnx

ok, gonna do a curl to get the state of the api , i should retrieve the monitoring mode normally and hopefulle somekind of id
hopefull i can do with a POST the update of that moniring mode

thnx for putting me in right direction with that rest api

can you help me one more time :slight_smile:
just struggling with this

with this command i can actually see states so GET command is working

curl -k -X GET -H "Authorization: Bearer xxxxxx" https://192.168.0.17:8123/api/states/device_tracker.fabio_owntracks

but where to send the remote config too with rest api ?

this gives me :

curl -k -X POST -H "Authorization: Bearer xxxxxxx" -d '{"_type":"cmd", "action":"setConfiguration", "configuration":{"_type": "configuration","monitoring": 2}}' https://192.168.0.17:8123/api/states/device_tracker.fabio_owntracks

error message : “no state specified”

so i still dont know how to send a message

more info here:

https://owntracks.org/booklet/tech/json/#_typeconfiguration

Looks like you are not updating a state to the home assistant sensor. Try my example in the above post and see what happens.

What should happen:
The state of your device_tracker.fabio_owntracks should update to the values you manually specified in your curl message.

I’m still not sure that what you actually want to achieve though, can be done with this way.

yeah, but your command is only changing states in HA , i need it pushed back to the android client :frowning:dont think its possible

I never thought of updating the device tracker directly…I ended up doing much the same thing, but with a webhook, and parsing the owntracks JSON and sending a device-tracker-compatible MQTT payload.

Can you share how you did it?

Sure.

device_tracker:
  - platform: mqtt_json
    devices:
      steve_location: location/tracker/steve

automation:
  - alias: location_owntracks
    trigger:
      - platform: webhook
        webhook_id: <webhook_id>

    action:
      - condition: template
        value_template: >
          {{ trigger.json.acc | int <= 400 }}

      - service: mqtt.publish
        data_template:
          topic: >
            {%-
              set people =
              {
                "st": "steve",
                "wi": "wife",
                "k1": "kid_1",
                "k2": "kid_2"
              }
            -%}
            {%- set person = people[trigger.json.tid | lower] |lower -%}
            location/tracker/{{ person }}
          retain: true
          payload: >-
            {{
              {
                'latitude': trigger.json.lat,
                'longitude': trigger.json.lon,
                'battery_level': trigger.json.batt | round(0) | int,
                'gps_accuracy': trigger.json.acc | round(0) | int,
                'provider': 'owntracks'
              } | to_json
            }}

What did you mean by you “need it pushed back to the android client”?

Yeah, I want to push settings/config to the Android client , settings like, monitoring mode, to enable location on/off

What android client do you mean? I’m just using the nabu casa web UI. If I want to shut off location tracking, I just turn off that automation.

the androids where you install Onwtracks on
i want to be able to push a configuration setting TO Onwtracks, thats installed on a Android

I didn’t know that was even possible.

Seems you can only do that when using Owntracks in MQTT mode. I’m using http, so it’s currently not.possible for me.

yeah , seems to developed yet :slight_smile: