GPSBinding Distance from location not working

I have setup the GPS binding just like in the tutorial using ontracks. It would appear that everything is working but the region settings. I have tried several variations but I cant seem to get either the distance from home or atHome working. No matter what I try I get a message that the item does not exist. The docs dont really explain the channels part of the things file.

Things

//tracker definition with extra distance channel
Thing gpstracker:tracker:KM   "Kirk tracker" [trackerId="KM"] {
    Channels:
            Type regionDistance : homeDistance "Distance from Home" [
                regionName="Home",
                regionCenterLocation="44.7736825,-46.6935502",
                regionRadius=100,
                accuracyThreshold=30
            ]
}

Items:

//items for basic channels
Location        locationKM      "Location"              {channel="gpstracker:tracker:KM:lastLocation"}
DateTime        lastSeenKM      "Last seen"             {channel="gpstracker:tracker:KM:lastReport"}
Number          batteryKM       "Battery level"         {channel="gpstracker:tracker:KM:batteryLevel"}
Number:Length           accuracyKM      "GPS Accuracy [%d m]"           {channel="gpstracker:tracker:KM:gpsAccuracy"}

//linking switch item to regionTrigger channel. assuming the Home distance channel is defined in the binding config (see above)
Switch atHomeKM "Home presence" {channel="gpstracker:tracker:KM:regionTrigger" [profile="gpstracker:trigger-geofence", regionName="Home"]}

//another switch for work region. assuming the OTWork is defined in OwnTracks application (no distance channel is needed like for Home)
Switch atWorkKM "Work presence" {channel="gpstracker:tracker:KM:regionTrigger" [profile="gpstracker:trigger-geofence", regionName="Work"]
}

SItemap:

sitemap gpstracker label="GPSTracker Binding" {
    Text        item=homeDistance
    Switch      item=atWorkKM
    Switch      item=atHomeKM
    Text        item=lastSeenKM
    Text        item=batteryKM
    Text        item=accuracyKM
    Mapview item=locationKM height=4
}

It will be easier to read your configs if you How to use code fences.

I can’t help with you specific problem but code fences will help those who can.

You have two items with the same name. The .items file will not load this way…

I’m not sure how that happened but thanks for catching it. Sadly it didnt solve the problem. Same situation everything works but the distance from location and the region settings.

homeDistance seems to be a thing channel in your configuration, not an item. So probably that’s where the ‘item does not exist’ error comes from.

I saw that, but since thats how they have it in the documentation that is how I did it.
The documentation didnt really go into how channels in a thing config file works so I didnt know where to go other than the forums.

Try to put the following in your items file and see if that works:

Number:Length homeDistance "Distance from home" { channel="gpstracker:tracker:KM:distanceSystem" }

I just figured it out you were close:

The definition of the channel in the thing file makes the option homeDistance available as a channel source for a thing.

Number homeDistanceKM "Distance From Home" {channel="gpstracker:tracker:KM:homeDistance"}

I submitted a pull request for that page so the documentation includes it.

Thanks for the help guys.

1 Like

What do you coordinate do you put in regionCenterLocation home or work?

mine is not switching

//tracker definition with extra distance channel

Thing gpstracker:tracker:KM “Kirk tracker” [trackerId=“KM”] {

Channels:

Type regionDistance : homeDistance “Distance from Home” [

regionName=“Home”,

regionCenterLocation=“44.7736825,-46.6935502”,

regionRadius=100,

accuracyThreshold=30

]

}

The location I have set is my home location.

I likely could add a work one if I wanted but I have not tried it yet. I suspect it would look something like this:

Type regionDistance : workDistance “Distance from Work” [

regionName=“Work”,

regionCenterLocation=“45.7736825,-45.6935502”,

regionRadius=100,

accuracyThreshold=30

]

I changed the Lat and Long for both for security reasons. But now that I’ve looked at it. It would seem that my “Home” would be on a boat or at the bottom of the ocean.

Work like a charm!

Here is my config in case someone getting the same problem.

presence.things

//tracker definition with extra distance channel
Thing gpstracker:tracker:LM   "Lohn tracker" [trackerId="LM"] {
    Channels:
            Type regionDistance : homeDistance "Distance from Home" [
                regionName="Home",
                regionCenterLocation="-24.234657,25.753543",
                regionRadius=50,
                accuracyThreshold=30
            ]

            Type regionDistance : workDistance "Distance from Work" [
                regionName="Work",
                regionCenterLocation="-24.435647,25.245853",
                regionRadius=50,
                accuracyThreshold=30
            ]
}

presence.items

//Presence
Location        locationLM      "Location"              {channel="gpstracker:tracker:LM:lastLocation"}
DateTime        lastSeenLM      "Last seen"             {channel="gpstracker:tracker:LM:lastReport"}
Number          batteryLM       "Battery level"         {channel="gpstracker:tracker:LM:batteryLevel"}
Number:Length   accuracyLM      "GPS Accuracy [%d m]"   {channel="gpstracker:tracker:LM:gpsAccuracy"}
Number          homeDistanceLM  "Distance From Home"    {channel="gpstracker:tracker:LM:homeDistance"}
Number          workDistanceLM  "Distance From Work"    {channel="gpstracker:tracker:LM:workDistance"}

//linking switch item to regionTrigger channel. assuming the Home distance channel is defined in the binding config (see above)
Switch atHomeLM "Home presence" {channel="gpstracker:tracker:LM:regionTrigger" [profile="gpstracker:trigger-geofence", regionName="Home"]}

//another switch for work region. assuming the OTWork is defined in OwnTracks application (no distance channel is needed like for Home)
Switch atWorkLM "Work presence" {channel="gpstracker:tracker:LM:regionTrigger" [profile="gpstracker:trigger-geofence", regionName="Work"]
}

presence.sitemap

sitemap home label="My Home"
{
  Frame label="Presence" {
       Text        item=homeDistanceLM
       Switch      item=atWorkLM icon=office
       Switch      item=atHomeLM icon=presence
       Text        item=lastSeenLM
       Text        item=batteryLM
       Text        item=accuracyLM
       Mapview     item=locationLM height=4
   }
}
1 Like

Glad you got it to work for you!