I’ve read all the threads I can find and I think this is supposed to work.
I’ve installed OwnTracks on two phones and they both are reporting locations to OH successfully. Woohoo! But I couldn’t get the regionTrigger to fire.
I defined a couple of regions in the apps on the phones and pressed “Publish”. There does not appear to be a “share” option for regions any more. And the regions are correctly reporting when I’m inside or outside the defined region in the app itself.
I have a Rule to trigger from the Trigger Channel:
from core.rules import rule
from core.triggers import when
@rule("Region Change",
description="Triggeredn when someone changes a geofence region",
tags=["location"])
@when("Channel gpstracker:tracker:RK:regionTrigger triggered")
@when("Channel gpstracker:tracker:JC:regionTrigger triggered")
def region_change(event):
region_change.log.info("The region changed: {} - {}".format(event.channel, event.event))
name = "Unknown"
if "RK" in str(event.channel):
name="Rich"
if "JC" in str(event.channel):
name="Jenn"
if name == "Unknown":
region_change.log.info("Unknown trigger!")
return
region = event.event.split("/")[0]
move = event.event.split("/")[1]
if move == "leave":
region = "away"
region_change.log.info("Updating v{}_Region to {}".format(name, region))
events.postUpdate("v{}_Region".format(name), region)
I used curl to POST some JSON to simulate entering a region and nothing would appear to happen. It wasn’t until I issued a POST to simulate leaving a region that the channel started to trigger the Rule.
I’m not sure if this is a bug, I failed to do something, or what but I’m posting this here in case someone else runs into the same problem. I used the following commands to send the enter and leave events.
// Leave
curl -v -X POST --header "Content-Type: text/plain" --header "Accept:application/json" -d '{"_type":"transition","tid":"<ID>","acc":10.0,"desc":"<region>","event":"leave","lat":<LAT>,"lon":<LON>,"t
st":1527966973,"wtst":1524244195,"t":"c"}' "http://argus:8080/gpstracker/owntracks"
// Enter
curl -v -X POST --header "Content-Type: text/plain" --header "Accept:application/json" -d '{"_type":"transition","tid":"<ID>","acc":10.0,"desc":"<region>","event":"enter","lat":<LAT>,"lon":<LON>,"t
st":1527966973,"wtst":1524244195,"t":"c"}' "http://argus:8080/gpstracker/owntracks"
Make sure to replace the stuff in <>
with your information.