A geofence is a virtual perimeter for a real-world geographic area – Wiki
It involves using a location aware device and a location aware service.
Geofencing is increasing being used in marketing.
For a smart home it can be used to perform an action like turn on heating, open garage door when the service detects the presence of a member of the household.
Geofencing Apps can use:
and other wireless devices to trigger the location App.
A very common use case is to use the GPS location of a cell phone to trigger an action when the owner enters into the perimeter.
It could for example automatically open the garage door, turn on lights,turn on the heating.
Node-Red Geofence Node
The Geofence node in node-red allows you to set a geofence around an area.
When you open the node you are presented with a world map and you need to locate the area you are interested in and then you can draw your geofence as a rectangle,circle or polygon.The screen shot below shows and example
The action setting below the map needs to be configured. The one I use is the inarea setting which gives a value of false or true when you are inside/outside the geofence.
The node output is shown below:
So all we need to do is test the property for true or false as in this code snippet
if (location.inarea) inarea_flag=true;
We can now use this flag to trigger an event e.g turn the heating on.
View on Worldmap
There is an option also to send the geofence location to a worldmap page so that you can see it.
For that to work you also need to install the worldmap node.
This is all best explained in a video which I have done below:
Getting GPS Data
For all this to work we need to have a source of GPS data. In the video I simulated this data but in reality it would usually come via an internet connection over http or MQTT.
Although there are many Apps on smart phones that use GPS data there are no Apps that make this data generally available in real time.
The only one am aware of is the owntracks App.
Related Tutorials and resources:
- Home Automation Timer with Node-Red
- Using Zigbee2MQTT- A Beginners Guide
- Controlling the Tasmota SonOff Switch with MQTT and Node-Red