How to use the API to get the current geozone

Christoph Haas 7 years ago

I would appreciate and hint that helps me get the current geozone of a user. There is a feature request for implementing Traccer support into ioBroker (the house automation software). I would gladly do that. But I cannot figure out at the moment how to get a user's geozone through the API. Any hints? Thank you.

Anton Tananaev 7 years ago

If user has configured time zone, it should be available in its attributes.

Christoph Haas 7 years ago

Thanks for the response. But I mean the geozone – not the time zone.
From a call to /api/devices I get this information:

[{"id":2,"attributes":{},"groupId":0,"name":"Chris","uniqueId":"123456","status":"online","lastUpdate":"2018-12-18T10:03:51.021+0000","positionId":355,"geofenceIds":[],"phone":"","model":"","contact":"","category":"person","disabled":false}]

Although I'm in a geozone at the moment I don't get the information here.

To paint the big picture… I intend to send the information about entering/leaving geofences/geozones to my home automation system to let the family know where I am at the moment. So either I have to poll my location every few seconds or I can make Traccar send that information on an event. Currently I only see "Web" (popups) and "Mail" implemented. Is there a way to add such hooks without having to learn Java?

Anton Tananaev 7 years ago

What you provided is device attributes. We are talking about user.

Christoph Haas 7 years ago

Okay. But according to the documentation you need admin permissions to get user information. And even that JSON data structure does not contain the geofence.

Anton Tananaev 7 years ago

Sorry, I misread it. I thought you want timezone. Looks like you are talking about geofences. User doesn't have geofence. Devices do have geofences and there is corresponding parameter in the model.

Christoph Haas 7 years ago

No problem. But I fetched the device information (see above) and all I got was:

"geofenceIds":[]

So for some reason I get an empty array although I am definitely within a fence. Am I doing anything wrong?

Anton Tananaev 7 years ago

It probably means that geofence is not linked to this particular device.

Christoph Haas 7 years ago

I am logged in as a non-admin, have just one device and several geofence zones. Is there an extra step required to map the device to the zones?

Anton Tananaev 7 years ago

Yes, as I said, you need to link geofences to devices. It's also mentioned in the official documentation.

Christoph Haas 7 years ago

I did not find it mentioned in the documentation. But I just figured out that I can click on a device and then using the "gear" icon select "Geofences" and assign them. It didn't appear to me that I have both to define and also assign a geofence zone. But you are right of course… I now get the proper number of the geozone. Thanks for your support.

Now I will try to learn enough Java to add a notificator that allows me to send an event to ioBroker. :)