Mqttitude on OH3, Will it be ported?

Yes, of course. The documentation at owntracks concerning the installation of mosquitto is a little bit outdated, so I combined my installation out of this three websites:

Finally I got owntracks up and running with mosquitto on my linux box, client connections secured by TLS.

Now comes the openHAB part: Install the mqtt binding, create a bridge thing:

UID: mqtt:broker:MQTTBroker
label: MQTT Broker
thingTypeUID: mqtt:broker
configuration:
  lwtQos: 0
  publickeypin: true
  clientID: openhab
  keepAlive: 60
  secure: false
  certificatepin: true
  password: ThisIsASecret
  qos: 0
  reconnectTime: 60000
  port: 1883
  host: localhost
  lwtRetain: true
  username: openhab
  enableDiscovery: true

and a generic MQTT thing. In my case I configured four channels, each for every person which is using owntracks

UID: mqtt:topic:MQTTBroker:owntracks
label: Owntracks Channel
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:MQTTBroker
channels:
  - id: person1String
    channelTypeUID: mqtt:string
    label: person1 String
    description: ""
    configuration:
      stateTopic: owntracks/person1/handy
  - id: person2String
    channelTypeUID: mqtt:string
    label: person2 String
    description: null
    configuration:
      stateTopic: owntracks/person2/handy
  - id: person3String
    channelTypeUID: mqtt:string
    label: person3 String
    description: null
    configuration:
      stateTopic: owntracks/person3/handy
  - id: person4String
    channelTypeUID: mqtt:string
    label: person4 String
    description: null
    configuration:
      stateTopic: owntracks/person4/handy

Create string items and connect them to the channels. I created four of them with the names “OwntracksChannel_person1String” to “OwntracksChannel_person4String”. They will receive a JSON string from owntracks via mosquitto, each time an onwtracks client posts an update.

Create four location items for each person (maybe name them hperson1Position to hperson4Position) and leave them unconnected to any channel. They will be updated by the following rule. The rule should be triggered each time a OwntracksChannel_personXString item is updated.

'use strict';

//var log = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);
//log.info("Script is starting");

var owntrack = JSON.parse(event.itemState);

if (owntrack._type == "location") {

  switch (event.itemName) {

    case "OwntracksChannel_person1String":
      events.postUpdate("hperson1Position", owntrack.lat + ", " + owntrack.lon + ", " + owntrack.alt);
      break;
    case "OwntracksChannel_person2String":
      events.postUpdate("hperson2Position", owntrack.lat + ", " + owntrack.lon + ", " + owntrack.alt);
      break;
    case "OwntracksChannel_person3String":
      events.postUpdate("hperson3Position", owntrack.lat + ", " + owntrack.lon + ", " + owntrack.alt);
      break;
    case "OwntracksChannel_person4String":
      events.postUpdate("hperson4Position", owntrack.lat + ", " + owntrack.lon + ", " + owntrack.alt);
      break;
    default:
      //nothing
  }
}

Hope this helps. In this case owntracks is totally separated to openHAB. OpenHAB is only a client to mosquitto and collecting the location information as mqtt strings.

1 Like