OwnTracks to toggle a switch


Could someone point me in the right direction.

I would like to get owntracks to simply toggle a switch ‘on’ when I get home and to display this for now on my sitemap, later this would go into a rule.

I have so far,

  • Got the iOS app running in Private mode & a region (called home) defined for geofence
  • Got mosquitto installed, tested, running locally
  • Got the iOS app connected to the mosquitto install (same localhost as openhab)
  • Placed both mqtt & mqttitude bindings in the addon directory
  • Changed openhab.cfg to include
  • Added an item,
    Switch PresenceGW "GW @Home" {mqttitude="mosquitto:owntracks/user/gwiphone:home" }
  • Added to sitemap
    Switch item=PresenceGW label="Is GW home?" icon="switch"

I have changed the geofence from 1m to 100m to trigger a change in state and thus trigger the switch but nothing happens.

Would be great if you could give me a prod in the right direction.

Kind Regards

Hi George

I don’t know whether or not I get you right but there are two possible problems: First you should make sure that in your iphone app the setting for the region is set to “share”. Second is, if you use regions your item should look like
Switch PresenceGW "GW @Home" {mqttitude="mosquitto:owntracks/user/gwiphone/event:home" }

If that doesn’t work you should check whether your phone sends the events (using mosqitto_sub on your broker) and also if OH is registered as subscriber in your OH logfile.



Yep the region is set to share & I fixed up the switch code.

How could I check if the phone is sending events? In the app ‘Messaging’ section it says the MQTT is connected.
How could I check if OH is registered as a subscriber?

(apologies if these are silly questions)



If you don’t mind using a command line you could use the mosquitto_sub program from mosquitto and register on topic ‘#’ to see the traffic on your MQTT broker.

This will allow you to confirm that your phone is sending messages correctly to the broker.

Georegion “home” is a reserved word (used for server-side tracking).
Your original setup was using that mechanism, although you probably didn’t specify ‘home’ geo coordinates in openhab.cfg and thus it didn’t work.
As you now changed to phone-side tracking (…/event:XXX) following @DieterL 's proposal, you need to rename the region to something other than ‘home’ to avoid clashes with server-side processing in both, your phone and OH items.

Connect to mosquitto to see if it’s receiving anything from your phone:
mosquitto_sub -t 'owntracks/#' -v -p 1883 -h localhost
Enable debugging in logback.xml to see in OH logfile if OH registers to mosquitto:
<logger name="org.openhab.binding.mqttitude" level="DEBUG" />


Daniel & Marcus,

Thanks, it does seem that mosquitto is receiving data from the iphone,

I have changed the region name on the iphone to gwhome (from home) and updated it in the item file.
Switch PresenceGW "GW @Home" {mqttitude="mosquitto:owntracks/user/gwiphone/event:gwhome"}

On the debug it looked like this,

Do you guys have any pointers?

Thanks again I appreciate it!

Kind Regards,

Bad for reading, copy’n paste next time, please.
It seems you don’t receive transition events (‘enter’/‘leave’) which is what you need to obtain for the OH switch to toggle.
They’re only sent from owntracks when you enter or leave the area. Reduce your waypoint radius, and go for a walk, weather is nice :smile:

You could also add another switch for ‘home’ in parallel to gwhome, it works without transitions. Configure home & radius in openhab.cfg for that to work.


Thanks for that, it was a bit late for a walk last night, went this morning and all works well.