OwnTracks - Rule

Hello guys,
I recently start to use GPSTracker due the IFTTT Problems.
And I have a few question that can’t be sloved by searching or looking up the OwnTracks Binding page, And believe me I tried.

I just want to simply make a rule when every time I arrive to my home, It will turn on a switch.

Of course OwnTracks is installed on my phone and have a full sync with openhab with no problem, I just dont know what to do from here.

Edit: I post that I need help with GPSTracker, and I got confue, it’s OwnTracks.

You will need to add a channel to your thing of type distance. This is the region for your home. Once configured. Add your switch item to the Region Trigger section. Once added a second box will pop up where you can link the distance channel you added before.

This switch is on if you are in region. Home or Away. From there you can trigger a rule off that switch to do whatever logic you want.

Hope this helps.

Chris

Thank you Chris, I actually did all that. I just can’t understand the way I need to use the Rules…

This is the Things

Thing gpstracker:tracker:1   "XY tracker" [trackerId="XY"]

//tracker definition with extra distance channel
Thing gpstracker:tracker:EX   "EX tracker" [trackerId="EX"] {
    Channels:
            Type regionDistance : homeDistance "Distance from Home"
             [
                regionName="Home",
                regionCenterLocation="33,34",
                regionRadius=100,
                accuracyThreshold=30
            ]
}

This is the items:
Location locationEX "Location" {channel="gpstracker:tracker:GG:lastLocation"}

Switch atHomeEX "Home presence" {channel="gpstracker:tracker:EX:regionTrigger" [profile="gpstracker:trigger-geofence", regionName="Home"]}

What I need to do at the rules now? (And yes I link my Item to Region Trigger)

so you want a rule which triggers off the atHomeEX switch

Try something like this.

rule "Turn Switch On when Home"
when
    Item atHomeEX received command
then
   if (atHomeEX.state == ON)
   {
      mySwitch.sendCommand(ON)
   }
   else if (atHomeEX.state == OFF)
   {
      mySwitch.sendCommand(OFF)
   }
end

How can I check it? Like if it’s working.

You would need to move out of the zone and back into the zone to trigger it.
You can add to the log if you want to debug.

logInfo("SwitchHome", "Rule Triggered - ON")

Might be worth trying out some other rules based off some dummy switches ect and add them to the sitemap so you can get use to using rules.

Thank you Chris, I will check that, Just last question, the GPSTracker App, its need to be open on my device? I want it to be automaticly when I arrive home , with out open the app, do I need to something special?

I use owntracks on android which has a persistent notification to stop it from closing. It starts at boot.

Look at the last seen item to ensure openhab is seeing changes, but note unless you are moving it wont send updates very often.

Oh, god I am using Owntracks as well, my bad, so you saying it’s it’s persistent notification to stop it from closing, and on the main page, should I leave it on Play, pause/play, Stop, or Pause?

you want last reported location under ongoing notifications turned on. I have it on the Play icon, which is significant changes monitoring mode. owntracks docs are here https://owntracks.org/booklet/

I’ve those settings as well, and i’ts not working.
Any idea?, and do I need " OwnTracks (formerly MQTTitude) Binding (1.x) " binding?

Rules:

rule “Turn Switch On when Home”
when
Item atHomeEX received command
then
if (atHomeEX.state == ON)
{
sendBroadcastNotification(“CHECK”)
}
else if (atHomeEX.state == OFF)
{
sendBroadcastNotification(“TEST”)
}
end

Items:

Location locationEX “Location” {channel=“gpstracker:tracker:GG:lastLocation”}

Switch atHomeEX “Home presence” {channel=“gpstracker:tracker:EX:regionTrigger” [profile=“gpstracker:trigger-geofence”, regionName=“Home”]}

Things:

Thing gpstracker:tracker:EX “EX tracker” [trackerId=“EX”]
{
Channels:
Type regionDistance : homeDistance “Distance from Home”
[
regionName=“Home”,
regionCenterLocation=“31,32”,
regionRadius=100,
accuracyThreshold=30
]
}

You dont need the mqtt binding if you are using gpstracker binding.

Ok you are falling foul of the item state being updated after the command is received.

Try this…

rule “Turn Switch On when Home”
when
Item atHomeEX received command
then
if (receivedCommand == ON)
{
sendBroadcastNotification(“CHECK”)
}
else if (receivedCommand == OFF)
{
sendBroadcastNotification(“TEST”)
}
end

In this case you use the receivedCommand special variable. https://www.openhab.org/docs/configuration/rules-dsl.html#event-based-triggers

Not working either.

I know you’ve said that OwnTracks is working on your phone, but is it properly setup to still work when away from your home/the host network? If not then with the rules above you’ll never trigger the atHomeEX.state==OFF.

It would help you to add some logging to the rule to see what, if anything is changing.

"but is it properly setup to still work when away from your home/the host network? " I am not sure I setup it properly. How can I check, and what about that “atHomeEX.state==OFF” ?

If you turn off the wifi on your phone can Owntracks still connect to the broker you set up on your home network? If not then when owntracks notices you’ve left your home location it won’t be able to send a message to say so, which in turn means no rule will fire in OH.

Have you set up a reverse proxy like nginx? Or do you use a dynamic DNS service with port forwarding? There are a few different ways to allow owntracks to connect to openhab no matter where you are.

I did not do anything like that, no Nginx, no Dynamic DNS, what is your favorite to do?

Here’s one option: