One2Track integration

I haven’t found any similar requests yet, but please point me in the right direction of this has been handled before.

One2Track makes GPS watches to help keep track of your kids. They also have phone capabilities, so the kids can call their parents and vice versa. For those who would like to know more: https://www.one2track.nl/

I’ve added device trackers for my wife and myself based on our phones, but the kids don’t have phones yet, but do wear those watches. Would be great if there was a (community) integration to help with automation and scripts going off based on presence.

Admittedly I have zero idea of the vendor’s policy towards 3rd party integrations, but since I can’t find any information I thought I’d check here with the community before I contact them directly.

One possibility is to look into Traccar and see if the data coming out of your devices has a compatible protocol. Traccar is supported by HA. It also will work with many protocols.

Otherwise contact the company and request they look into the ‘works with home assistant’ program were they could share their data with customers

1 Like

I received a reply from the One2Track team that they won’t be exposing their systems to external API’s due to the sensitive nature of the data stored there. (GPS information about kids)

I guess understandable from a data privacy perspective, but too bad in terms of Home Assistant integration potential!

From GDPR perspective that seems to be a bit of a weak answer tbh, so it’s probably a commercial/financial choice.

It’s your data, and as far as they process it, it should be done so in a respectable/secure manner. Allowing integration is fine as long as you give consent and expectations/responsibilities are clear, given that on their end it’s securely done.

Not sure if they’re a bit cloud native or not (currently they don’t seem to be hosting on a well known cloud platform but rather on-prem/colo), but that would make things a lot simpler and less scary. But perhaps some pubsub exposure where HA is able to subscribe to would be a simple-ish solution.

That said, it takes a fair amount of effort, so let’s hope they’ll see the potential in this :slight_smile:

Received a watch for our oldest this week, and noticed there is a web-based dashboard as well ( https://www.one2trackgps.com/ ). Seems like the data could be scraped fairly easily from there, I might give it a try in the coming week.

I got a similar response on my question, but I agree with @Rizzlarzz:

I’m very interested in those watches for my kids, but not being able to pull (some of) the data into Home Assistant is the reason I haven’t bought one yet.

Made any progress? Need any help? Device tracker and battery status would be the data I’m looking for.

Some progress, but can’t seem to get the login to work. But I’ve got something working based on copying an existing cookie, which seem to be valid for quite a long period of time (at least a few days, possibly much longer).

Probably missing something stupid for the login, but just getting a cookie and the csrf of the login page doesn’t seem to be enough, I run into a “422 Unprocessable Entity” or an error that the login is incorrect.

I’ll try to share the code later, but maybe someone want to look into the login proces.

Oh wow, I didn’t know there was a web dashboard! Would be indeed very nice of we can scrape that.

I received the one for my daughter today, so I will definitely also be looking into this too.

There are two headers that you have to send along: a Cookie header and an Accept header. The value for the first should be taken from another session obviously, and the value of the second should be ‘application/json’. That’s enough to get it going. I have both my children’s locations on my dashboard now. :slight_smile:

1 Like

Would you mind sharing your code?

I’m also interested at the code and the way you scraped the data.
Would be nice if it is shared.

Hello everyone,

We are glad to see that there is an interest for our products beyond what we have to offer. As a company we strive to become better and offer improved services to our customers throughout the years. We did indeed hear from our support department that there seemed to be some interest from our customers to integrate our services into home automation. Sadly we have to prioritize other features for now, but we would like you to know that we have heard you and are willing to put some features in to place to allow for home automation.

It seems you guys found a way to crawl through our web portal, which we are fine with for now. We also have an api (sadly not very well documented yet), which our apps use. We’ll create some documentation for our api in the future so you can use the api for integration rather than crawling through our web portal.

For now we’re very interested in what kind of functionality you would like to see from our end. I see some requests for pub/sub. Which functions would you like to be able to sub to? I’m assuming subs for location updates and alarms obviously, but it would be nice to have a list for sake of completeness. We are not quite familiar yet with home automation, so any help pointing towards the correct way would be very helpful!

4 Likes

Can you please explain how you’ve done this?

For me, I would like to see location, battery, alarms and amount of money left in the account. But location is the most important one.

It would be extra nice if I could send messages from home assistant too.

Not the one you’re replying to, but I did this:

Add the following to your configuration.yaml and replace the all caps parts:

rest:
  - authentication: basic
    username: "ONE2TRACK USERNAME"
    password: "ONE2TRACK PASSWORD"
    headers:
      Cookie: _iadmin=ONE2TRACK_COOKIE_VALUE
      Accept: application/json
    scan_interval: 900
    resource: https://www.one2trackgps.com/users/ONE2TRACK_USERNAME/devices
    sensor:
      - name: "ONE2TRACK_DEVICENAME_1"
        json_attributes_path: "$.[?(@.device.id==ONE2TRACK_DEVICEID)]"
        value_template: "OK"
        json_attributes:
          - "device"
      - name: "ONE2TRACK_DEVICENAME_2"
        json_attributes_path: "$.[?(@.device.id==ONE2TRACK_DEVICEID)]"
        value_template: "OK"
        json_attributes:
          - "device"

This should give you the devices listed as sensor.ONE2TRACK_DEVICENAME_1 with attribute ‘device’ and a ton of subattributes.

Oh, and the device ID you’ll find if you add this too:

logger:
  default: info
  logs:
    homeassistant.components.rest: debug

Then find the homeassistant.log file and look at the output. You should see a block of JSON output somewhere. It’s not the same as the ID shown on the website.

Edited to add:
If you then create a template sensor, you can format the values a little better for easier use in a device tracker. Like so:

- platform: template
    sensors:
      DEVICENAME_ONE2TRACK: 
        value_template: "{{ state_attr('sensor.one2track_ONE2TRACK_DEVICENAME_1','device')['status'] }}"
        attribute_templates:
          latitude: "{{ state_attr('sensor.ONE2TRACK_DEVICENAME_1','device')['last_location']['latitude'] }}"
          longitude: "{{ state_attr('sensor.ONE2TRACK_DEVICENAME_1','device')['last_location']['longitude'] }}"
          last_contact: "{{ state_attr('sensor.ONE2TRACK_DEVICENAME_1','device')['last_location']['last_communication'] }}"
          last_update: "{{ state_attr('sensor.ONE2TRACK_DEVICENAME_1','device')['last_location']['last_location_update'] }}"
          speed: "{{ state_attr('sensor.ONE2TRACK_DEVICENAME_1','device')['last_location']['speed'] }}"
          signal_strength: "{{ state_attr('sensor.ONE2TRACK_DEVICENAME_1','device')['last_location']['signal_strength'] }}"
          battery: "{{ state_attr('sensor.ONE2TRACK_DEVICENAME_1','device')['last_location']['battery_percentage'] }}"
          balance: "{{ (state_attr('sensor.ONE2TRACK_DEVICENAME_1','device')['simcard']['balance_cents']/ 100)| round(2) }}"

Changed the balance to display in rounded euro’s instead of cents.

Then you can easily make a device tracker like so:

- id: DEVICETRACKER_NAME
  alias: DEVICETRACKER NAME
  description: ADD DESCRIPTION
  mode: queued
  trigger:
  - platform: homeassistant
    event: start
  - platform: state
    entity_id: sensor.DEVICENAME_ONE2TRACK
  action:
  - service: device_tracker.see
    data:
      dev_id: DEVICENAME
      gps: >
        {% if not is_state('sensor.DEVICENAME_ONE2TRACK', 'OFFLINE') -%}
          [{{ state_attr('sensor.DEVICENAME_ONE2TRACK','latitude') }}, {{ state_attr('sensor.DEVICENAME_ONE2TRACK','longitude') }}]
        {%- else -%}
          []
        {%- endif %}

Might not work as it’s part of a larger device tracker I built for my kids that also switches based on calendar entries. But it should at least point you in the right direction.

4 Likes

This seems like a fine solution for now. this endpoint we use internally to show the devices on a map with automatic refreshing. We will monitor the load on our systems and kindly ask you guys to not set the scan_interval too low. if necessary we will add a rate limit to this endpoint.

Since you are using this endpoint anyway, anything you’d like to see added to the response? this is a quicker fix for us and any requests could be implemented in a few days

I’m pretty happy with it as is! What scan interval would you recommend? I’ve set it at 15 mins now, but I’m not sure what would be best for the servers.

15 minutes is more than fine. The watches send data every 10 minutes by default. They also have a 10 second setting for more accurate tracking though. We’d be happy if you can keep your scan interval somewhere above a minute.

With apps it is not necessarily a concern if they poll more often since people don’t look on their phones 24/7. I assume however that the home assistant scanner will scan continuously. Of course a few scanners won’t create a problem.
Our main concern is when this number increases, too many trackers may want to scan too often at some point, which will push us to rate limit the endpoint.

In other words: play fair and we won’t have to limit :slight_smile:

1 Like

Hi Netwitch,

Thanks for the code.
How do you create the Device tracker? Can you give me some more content how to create it?

It should work if you paste the last piece of yaml in your automations.yaml file. That creates a device tracker that is populated with the One2track longitude and latitude as long as it’s on.