This documentation will explain and show how to create a flow which signal that you are next to your home. For example, the house’s portal will open when it detects you’re within 500 meters of your house. In this documentation, it simply send an email which contains the distance between the two GPS coordinates wished.

Before going further, you must have the application Owntracks on your mobile phone (Android or iOS) and configurate it. Here is how to do:

How to install and configure OwnTracks

What is OwnTracks ?

OwnTracks is an application that allows you to keep track of your own location. It’s available for IOS and Android devices.

Where can I download OwnTracks ?

OwnTracks is a mobile application that can be downloaded on the Google Play Store or on the Apple App Store.

Prerequisites

To use OwnTracks, you obviously need a mobile(IOS/Android) phone and an internet connection. You also need to use a OwnTracks account.

Configuration

To go to the preferences, you just have to touch your “options” button.

Connection

Before trying to connect, make sure you have checked the option “Advanced connection preferences” in Preferences->Advanced->Advanced connection preferences:

This option allows you to turn off the SSL/TLS security, when you go to Preferences->Connection.

These credentials are needed to connect to you MQTT broker:

The host is the MQTT server you want to connect to, and the port is the one you’ll use to connect to this server. Username is needed too in order to connect.

Publish topic

You can configure your publish topic (default one is owntracks/username/device ID, but you can change it if you want). To do this, go to Preferences->Advanced->Publish topic, then, enter the topic you want to use to publish your OwnTracks notifications.

Subscribe topic

Once its done, you can define the topic you want to receive messages on. (Preferences->Advanced->Subscribe topic). Default one is owntracks/+/+.

Reporting

Please ensure that you have checked the “Automatic location reporting” option in Preferences->Advanced->Automatic location reporting:

It allows you to automatically send notifications.

The Node-RED flow

Owntracks

Firstly, insert the owntracks node to recover your location:

To configure it properly, you must set the two tabs (Basic and Advanced). The first tab should inform the topic where writing owntracks app:

Caution, by default, this node publishes on a public mqtt server so it have to specify a single topic.

The second tab allows you to specify the courier mqtt owntracks which publishes messages:

Distance

Next take a distance node:

Thereafter, choose the type of data you send then fill in the blanks indicating the longitude and latitude of your home. (Watch the node info)

Switch

Finally, insert a switch node:

Then set it as the image shows to change the message according to the distance.

Template

To change the message according to the distance you need to use two nodes template:

Then in the first node enter the following text : You arrive soon. Then in the other write : You are {{payload}} km from home.

E-mail

Finally, drag and drop an email node to send the message:

And parametrize it to send the message written by the function node:

Linking

To finish link these node to obtain the following graph:

There is here the code to import in Node-RED to recover the graph:

[{"id":"51aff27.fae500c","type":"owntracks","name":"Location","broker":"test.mosquitto.org","port":1883,"clientid":"","topic":"","x":103,"y":149,"z":"1a8caac3.e57355","wires":[["2c41f752.d3be08"]]},{"id":"2c41f752.d3be08","type":"distance","name":"","latitude":"49° 10' 56\"","longitude":"0° 22' 14\"","gpsType":"DMS","x":288,"y":149,"z":"1a8caac3.e57355","wires":[["5943e694.a6bc18"]]},{"id":"5943e694.a6bc18","type":"switch","name":"","property":"payload","rules":[{"t":"lte","v":0.5,"v2":0},{"t":"else"}],"checkall":"true","outputs":2,"x":455,"y":149,"z":"1a8caac3.e57355","wires":[["a08fe512.5f7018"],["98129673.67ed68"]]},{"id":"a08fe512.5f7018","type":"template","name":"near","template":"You arrived soon","x":610,"y":113,"z":"1a8caac3.e57355","wires":[["b6d62bc3.4929d8"]]},{"id":"98129673.67ed68","type":"template","name":"far","template":"You are {{payload}} km from home","x":611,"y":184,"z":"1a8caac3.e57355","wires":[["b6d62bc3.4929d8"]]},{"id":"b6d62bc3.4929d8","type":"email","name":"","to":"","user":"","pass":"","service":"","x":778,"y":149,"z":"1a8caac3.e57355","wires":[]}]

Back to top