Geofence functions
Use the geofences you already have in Navixy inside IoT Logic flows, to act when a device enters or leaves an area, or to record which area it is in.
Geofence functions let a flow react to where a device is, using the geofences you already have in Navixy. You reference a geofence instead of describing an area with coordinates, so the boundaries stay the same ones you already use for alerts and reports.
Which function you need
Act on one particular geofence, when a device is inside it, enters it, or leaves it
inGeofence(), enterGeofence(), leaveGeofence(). See Reacting to one geofence
Find out which geofence a device is in, without naming one in advance
geofenceName(). See Recording the current geofence
You must create geofences in Navixy before you can reference them in IoT Logic expressions. To create or manage geofences, see Geofences.
geofenceName() is a paid option, sold separately. It is switched off for every account by default, and your service provider enables it per account on request. The other three functions are unaffected and need no extra option.
Contact your service provider to have it switched on. See Before you start.
Reacting to one geofence
Use these three functions when you already know which geofence matters. Each one answers yes or no for most data packets that the device sends, so a flow can send that data down one branch or another. On some packets a function can't answer, and it returns an empty value instead. See When a geofence function gives no answer.
inGeofence(id)
The device is inside the geofence right now
enterGeofence(id)
The device has just crossed into the geofence
leaveGeofence(id)
The device has just crossed out of the geofence
You add them to the condition of an IF/THEN Logic node. The id is the numeric ID of the geofence in your Navixy account, and a picker fills it in for you, so you rarely type it by hand. See How to add a geofence condition.
When a geofence function gives no answer
inGeofence(), enterGeofence(), and leaveGeofence() return an empty value instead of yes or no when they can't answer. A function can't answer in these cases:
The data packet carries no coordinates. A position of poor quality is still tested, so a weak GPS fix gives a real yes or no.
The geofence was deleted from your Navixy account, or became inaccessible, after the flow was saved. A geofence that is already missing when you save the flow is rejected at save time instead.
An empty value stops the condition that it is part of. When the function is the whole condition, the data goes to the ELSE path. That routing is usually what you want. When the function is combined with anything else, the empty value can stop the whole condition, including the terms that did have values. To keep the rest of the condition working, compare the function with == true:
For the full rule, see Missing values in expressions.
Syntax
This is the format the geofence picker inserts automatically. The geofence name appears as a comment for readability but has no effect on evaluation.
inGeofence() accepts two more parameters, so it can test an earlier position instead of the current one:
The second parameter says which data packet to take the position from, counting back from the current one. The third says whether to count packets that carry no position. Both are optional, and they follow the same convention as the value() function.
enterGeofence() and leaveGeofence() take the geofence ID and nothing else. Both compare the current position with the previous one, so there is no index to choose. A flow that passes a second parameter to either function can't be saved, and the error names the function.
Keep the index in the range 0 to 11. inGeofence() accepts a higher index, saves without an error, and then returns an empty value for every packet.
Don't wrap a geofence function inside value(). The first parameter of value() is an attribute name, not an expression, so a call such as value("inGeofence(35229)", 1, 'valid') looks for an attribute with that literal name and always returns an empty value.
For value() function details, see IF/THEN Logic expressions and syntax.
How to add a geofence condition
The expression field in the IF/THEN Logic node configuration panel includes a dedicated geofence selector
, separate from the standard attribute autocomplete. It lists all geofences defined in your Navixy account, grouped by name and ID.
To add a geofence function to your expression:
Find and select a geofence
Type part of the geofence name to filter the list. Each geofence appears three times, once for each available function. Select the entry that combines the geofence you need with the function that matches your condition:
inGeofence- use when you need to check whether a device is currently located inside the selected zone.enterGeofence- use when you need to detect that a device moved from outside the selected zone into it.leaveGeofence- use when you need to detect that a device moved from inside the selected zone to outside it.
The picker inserts the complete function call at the cursor position in the expression field.
Combine with other conditions if needed
Use logical operators to combine the geofence function with other conditions. See Condition examples.
The picker inserts only the three ID-based functions. To use geofenceName(), type it into the field yourself.
Condition examples
Recording the current geofence
geofenceName() tells you which geofence a device is in, instead of testing one geofence that you chose in advance. It returns the name as text, and you store that text in an attribute of its own.
One formula covers every geofence you have. You don't build a chain of per-geofence checks, and you don't edit the flow each time you add a geofence. Here is what the attribute holds for a delivery vehicle reporting through the day:
Data packet
current_zone
08:14
Main depot
09:02
(empty)
09:47
Client site 3
You create it as a calculated attribute in an Initiate Attribute node. From there it behaves like any other calculated attribute: it appears in Data Stream Analyzer, it can be shown on the platform as a custom sensor, and it can be forwarded to an external system.
Before you start
The option must be switched on for your account. geofenceName() is sold separately and is switched off by default for everyone. Contact your service provider and ask them to enable the geofence name function for your account. It helps to quote the internal feature name, iot_logic_geofence_search.
Until it is switched on, a flow that uses the function cannot be saved. The node is marked with this error:
Remove the function from the node to save the flow, or wait until your service provider switches the option on.
You also need geofences to search.
At least one geofence exists in your account. See Geofences.
Add the attribute
Create a calculated attribute the usual way, as described in Managing attributes, and enter one of the formulas below in the Formula field.
Type the function name yourself. The attribute autocomplete doesn't offer geofenceName, and the geofence picker is available only in the IF/THEN Logic node.
Formulas
The first two forms cover most cases. The third one reads an earlier position instead of the current one.
geofenceName()
The name of any geofence the device is currently in
geofenceName('depots')
The name of a geofence tagged depots that the device is currently in
geofenceName('', 1, 'valid')
The name of any geofence the device was in one data packet earlier
All three parameters are optional:
The tag, first, limits the search to the geofences you tagged with that name. Upper or lower case makes no difference, and an empty tag means all geofences. Tagging matters when you have many geofences and only some of them are meaningful for this attribute, for example depots but not customer sites.
The packet number, second, says how far back to look:
0is the packet being processed,1the one before it, and so on. Leave it out for the current position.The position filter, third, is
'valid'to skip packets that carried no position, or'all'to count them. Leave it out and packets with no position are counted.
For the exact limits of each parameter, see Geofence name function in the IoT Logic API documentation.
What you get back
The attribute holds the geofence name as text, or an empty value when there is no name to give. It is empty when:
The device is outside every geofence that was searched.
The data packet holds no position.
No geofence in your account has the tag you passed.
An empty value looks the same in all three cases. In a formula, this empty value is written as null, which is how the routing example below tests for it.
To get readable text instead of a blank, add a fallback with the ?: operator:
When a position falls inside two overlapping geofences, the function returns one of the two names. Navixy does not rank overlapping geofences, and the same name is returned for as long as the device stays in the overlap.
Formula examples
Frequently asked questions
Where do I find the geofence ID?
The geofence picker displays each geofence's name and numeric ID in the list. You can also find the ID in the Navixy geofences interface. When you select a geofence from the picker, the ID is inserted into the expression automatically.
Can I store a geofence check in an attribute?
Yes. All four functions work in an attribute formula as well as in a routing condition. geofenceName() is the natural choice, because it gives you readable text. The other three give you a yes or no value, or an empty value when the position is unknown. A yes or no value is usually more useful for routing than for storing.
The geofence picker appears only in the IF/THEN Logic node, so in an attribute formula you type the function and the geofence ID yourself.
Why can't I save a flow that uses geofenceName?
geofenceName() is a paid option and is switched off by default. Contact your service provider to have it enabled for your account. See Before you start.
What happens if the referenced geofence is deleted?
If a geofence referenced in an expression is deleted from your Navixy account, the function can no longer answer and returns an empty value. In an IF/THEN Logic node that uses the function on its own, data flows through the ELSE connection. The node stores its own attribute as an empty value, not as false. In a condition that combines the function with other terms, the empty value can stop the whole condition. In an Initiate Attribute node the attribute has no value for that packet. See Missing values in expressions.
The flow keeps running, but you can no longer save it until you fix the expression. Saving it again fails with Node "<node title>" (#<node id>) contains nonexistent or inaccessible geozones. Update or remove the expression to restore both the routing and the ability to save.
Does inGeofence evaluate the current GPS position of the device?
Yes. inGeofence() checks the position reported in the current data packet against the geofence boundaries. Each packet is evaluated independently, so the result reflects the position of the device at the time that packet was received. A packet that carries no position gets an empty value instead of true or false.
What is the difference between inGeofence and enterGeofence?
inGeofence() returns true for every packet that reports a position inside the geofence. enterGeofence() returns true only for the packet that records the moment the device crossed into the geofence. Use inGeofence when you need to apply logic to all data from inside the area. Use enterGeofence when you need to react specifically to the event of crossing the boundary.
Why is my geofenceName attribute always empty?
Check these causes in order:
The option is not switched on for your account. A flow saved earlier keeps running, and the function returns an empty value for every packet. See Before you start.
The tag you passed is not assigned to any geofence. Tag names must match a tag that exists in your account.
The device really is outside every geofence you searched.
You have a very large number of geofences and the formula passes no tag. Pass a tag to search a smaller set. The exact threshold is in Geofence name function.
Last updated
Was this helpful?
