[HowTo] Location and Presence (Owntracks)

Location and Presence for Homey (formally Owntracks client)


With this app you can enhance your Homey with presence detection based on geofences. This app is based on the Owntracks specification and available apps for Android and iPhone.

With the Owntracks app on your phone, you can define regions / geofences. These geofences are coordinates and a radius. These can be your home, workplace or any other place. Based on your username and geofence you can define triggers for Homey (as an example John leaves work and a trigger fires on Homey to increase the temperature at home so its nice and warm when he arrives home).

The Owntracks app on your phone needs to communicate with Homey. There are two ways to setup this communication:

  • using the Athom cloud to communicate through HTTPS
  • using MQTT to communicate to a MQTT broker

The advantages of using MQTT over HTTPS are:

  • You are not using Athom cloud
  • MQTT is a energy friendly protocol
  • MQTT has persistence
  • Other applications besides homey can subscribe to the locations messages also.
  • You can push way points from homey to connected phones (to sync the fences)

Using HTTPS is the easiest way to start with. There is no need to setup a seperate broker. So
this guide will focus on setting up HTTPS.

When using HTTPS, you have to add users that are allowed to send events to the homey app. To do this, go to the apps settings page and go to the second button (Change users). Add the user name that you want to give access by entering the name in the empty field below the already known users. Press the ā€œ+ā€ button to add the user.



After you have added the user, the user will show up in the user list and it will have a token generated that is used in the phone app to allow receiving of the events:


You can remove a user by pressing the ā€œ-ā€ button. The ā€œ#ā€ button can be used to generate a new token when you think the id has been comprimised.

In the app on your phone, you should select HTTP as connection:





Then select HOST:



The URL you have to enter here is as follows:

https://<cloudid>.connect.athom.com/api/app/nl.scanno.owntracks/events/?token=<tokenid from user>

where <cloudid> is the Athom Cloud ID of your homey that you can find in Settings/System.
The tokenid is the id that is generated when you added the user.

In case you get a 401 error, then you need to adjust a small setting. The 401 is generated because the Owntracks app on your phone (at least on Android) expects HTTP authentication. Since it is not used on Homey that setting needs to be disabled. Go to Preferences/Configuration Management. There select the menu and select editor. And fill out the key and value field as shown in the picture below:


Using the Athom Cloud is the easiest way of getting started with owntracks. If you are more skilled you can also directly connect to your Homey by port forwarding. Keep in mind that homey itself does not support TLS/SSL. If you want to have a secured session, you need to use a proxy.

In addtion you can use a MQTT broker:

Setting up a MQTT brokers can be done in several ways. You can either use a broker on the internet (there are MQTT hosting services) or run a MQTT broker yourself.
There is a MQTT Broker app for Homey available in the App store.

For setting up a private MQTT broker in the cloud with CloudMQTT see the tutorial below:

https://forum.athom.com/discussion/2810/use-cloudmqtt-as-a-broker-for-owntracks-or-mqtt-app

Known issues:

  • You need to enter minimal accuracy to 150 in the tweak section. When this value is not set, triggers will not fire.
  • When first started, the app will send two notification about files not able to be read. This is ā€œnormalā€ because those files have not been created yet. This is nothing to worry about. As soon as there are users en geofences added, this problem is solved.

Using selfsigned certificates with the Homey MQTT broker

The Owntracks client on your phone needs to trust the selfsigned certificates. To do so you will need to add the generated certificate to the client on your phone.

You need to do the following steps:

  1. Go to the settings page of the MQTT Broker for Homey.
  2. Go to the Session Settings tab

  1. Select the contents of the Certificate field and copy that.
  2. Paste the contents in a text editor and save it with the extension PEM
  3. Put the file on your phone
  4. Go to the settings of the owntracks app on your phone
  5. Go to the security sections
  6. Press CA Certificate, press select and select the PEM file you copied to your phone
  7. Confirm
  8. Secure communication should be working.
2 Likes

My Owntracks is not working lately. The fence stays empty:

While the fence is there. And if I open my mobile app, the Owntracks client detects me being in the Fence (marked red).

The log files shows:

20190104-11:21:35 Broker State: CONNECTED
20190104-11:21:36 OnMessage called
20190104-11:21:36 received '{"t":"t","tst":1546594305,"acc":65,"_type":"location","alt":-3,"lon":5.0360418962593254,"vac":10,"lat":52.460436814600506,"batt":48,"conn":"w","tid":"qx"}' on 'owntracks/camille/camille'
20190104-11:21:36 We have received a location message
20190104-11:21:36 Set battery percentage for camille to 48%
20190104-11:21:36 OnMessage called
20190104-11:21:36 received '{"tst":1546592798,"acc":65,"_type":"location","alt":-2,"lon":4.8871961774959001,"vac":10,"p":103.69418334960938,"lat":52.404296875,"batt":98,"conn":"w","tid":"EM"}' on 'owntracks/esther/esther'
20190104-11:21:36 We have received a location message
20190104-11:21:36 Set battery percentage for esther to 98%

If those logs are from the situation where you should be inside a fence, then check the phone app. The app on your phone thinks you are not inside a fence.

When I open the app, it marks the fence where Iā€™m in red. So the app is right.

Itā€™s Homey that forgets that Iā€™m in this fence somehow

Have not seen that before. The only possibility is that the owntracks on your phone is not sending the transistion messages correctly. Please check the logging to see if you see transition messages with the name of the fence included.

Iā€™ve followed the guide, made a user in the Homey app, looked up my cloudid and entered

https://<cloudid>.connect.athom.com/api/app/nl.scanno.owntracks/events/?token=<tokenid from user>

with my codes in the Owntracks app for Android under Host. Looked easy enough, but I donā€™t see anything in the Homey app. Lon & Lat both say undefined. Do I need to do anything with Identication in Owntracks?

If I enter the complete URL in a browser I get this:

{ā€œcodeā€:404,ā€œerrorā€:ā€œnot_foundā€,ā€œerror_descriptionā€:ā€œNot found: GET /api/app/nl.scanno.owntracks/events/ā€}

Homey v1.5.x or Homey v2.0?

2.0 ā€¦ Funny thing is that on 1.5 presence didnā€™t work on my wifeā€™s phone, but fine in mine. Now on 2.0, sheā€™s spot on and my never registers anything (new phone though). Everything is set correctly, but nothing comes through so Iā€™m looking for alternatives.

Also, when I try to create a geofence, should it pick up my GPS coordinates? GPS is working, checked with GPS info and nav software, but ā€˜Presence & Locationā€™ says 0 0 & 0 for Lon, Lat and Radius. The Homey app has access to my location in Android, but it looks like itā€™s not registering anything.

Are you sure there is no typo? If the connection is made, then the lon/lat will be shown next to the user.
If you define regions in the app on your phone, then they get created also on homey.
Oh and the error is correct because the browser does a GET while the app wants a POST.

What error do you see in status?. If its a 401, then you need to disable a setting in configuration management (select the menu and then editor) Then the key/value : auth / false

@Raytestrak let me know if that solves the problem. Added a picture and description also to the first post.

Thanks, thatā€™s was it. Now to see if it works. Iā€™ve added two flows, one to mark my presence as away based on this and (surprise surprise) to mark my presence as home. That way I donā€™t have to change all my flows.

1 Like

You might want to start in ā€œmove monitoringā€ mode. Your phone will use the GPS and you get a more accurate location. When confirmed working, you can use ā€œsignificant changeā€. But that might need some tweaking.

And set minimal accuracy to something like 150 meters (homey app)ā€¦

Hi,. I was playing around with your app

I get a 417 error in owntracks app.

any tips?

1 Like

Homey v1.5 or 2.0?
If v2. 0 then probably your homey lost its cloud connection.

If v1. 5.x then in the url you need to replace connect with homey.

I stoll have 1.5
Did what you said, it changed the error to a 500 errorā€¦ Http:s.

And 2.0 will break it? :o

What error do you see textual besides the 500.
Homey v2 is actually better with regards to this app. On homey v2 it is possible to send a response back. Now it is possible to get almost the same functionality with https as with MQTT.

Right now you will see (if on homey v2) other household memebers in the app on your phone.

O. The own track only endpoint 500 error

I canā€™t update to 2.0 yet. Using Bluetooth beacons :s

Owntracks works like a charm, I see my geofences and whether Iā€™m in or outside, my geofences get sent to Homey, but my geofence is not set to my user in Location & Presence app, so I canā€™t use in flows. Iā€™m using private http based on the config in this thread by the way. Any ideas?

Try setting the minimal Gps accuracy to 150. Ik n the Homey app

Working perfectly for some days already, my settings in the Homey-app:
afbeelding
And in Owntracks using Significant changes:

Connection
Private HTTP
Host : https://<cloudid>.connect.athom.com/api/app/nl.scanno.owntracks/events/?token=<tokenid from user>
Identification empty

Advanced
Locator Displacement : 50
Locator Interval : 30

1 Like