OpenHabian owntracks and mosquitto

Ok so i really cant seem to get owntracks set up as a presence detection to work, i know there are other topics regarding this but ive read them all with no luck.
so my set up so far is openhabian on a RPi3, i have owntracks on my phone with a single region set as home.
I have mosquitto set up on the RPi3 and so far the logs suggest that it connects to owntracks and i can receive publishes from owntracks.
I have the mqtt binding set up for local host
and I have a switch item subscribing to event publishes from mosquitto and a site map showing said item .
I believe that openhab isnt connecting to mosquitto as it doesnt show it connecting in the log and thats why my sitemap switches don’t work.
does anyone have any ideas of what im doing wrong ?


# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.

# Optional. User id to authenticate with the broker.

# Optional. Password to authenticate with the broker.

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.

# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>
mosquitto.lwt=<last will definition>


# A full description of the configuration file is at 
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

allow_anonymous true
autosave_interval 1800

connection_messages true
log_dest syslog
log_dest stdout
log_dest topic
log_type error
log_type warning
log_type notice
log_type information

log_type debug
log_timestamp true

log_dest file /var/log/mosquitto/mosquitto.log

#message_size_limit 10240

#acl_file jp.acl

persistence true
persistence_location /var/lib/mosquitto/
persistence_file mosquitto.db
persistent_client_expiration 1m

password_file /etc/mosquitto/passwd

pid_file /var/run/

retained_persistence true

#listener 1883
listener 1883

listener 8883
tls_version tlsv1
cafile /etc/mosquitto/conf.d/ca.crt
certfile /etc/mosquitto/conf.d/openHABianPi.crt
keyfile /etc/mosquitto/conf.d/openHABianPi.key
require_certificate false

default items file

DateTime Today <clock> 

Switch Presence_Mobile_Tim "Tim's Mobile" <network> { channel="network:device:192_168_1_179:online" }

Switch Mobile_Tim_mqtt  "Tim's Gps" <presence> { mqtt="<[mosquitto:owntracks/Tim/Android/event:home]" }

mosquitto log

1497609544: Config loaded from /etc/mosquitto/mosquitto.conf.
1497609544: Opening ipv4 listen socket on port 1883.
1497609544: Opening ipv4 listen socket on port 8883.
1497609544: Opening ipv6 listen socket on port 8883.
1497609553: New connection from on port 8883.
1497609553: Client tim/android disconnected.
1497609553: New client connected from as tim/android (c0, k3600, u'Tim').
1497609553: Sending CONNACK to tim/android (0, 0)

You have clientID commented out but nothing assigned to it. That means your clientID is empty string or essentially no clientID. I don’t think mosquitto will allow a client to connect with an empty id.

Hi Rich,
I didn’t even notice that I commented it out . I shall give it a try and see if it works.
As far as my item syntax do you think this should work to operate a switch on the sitemap when I enter or leave a home region?
Thanks for the advice

No such luck i commented the client ID and for good measure the last will and testament as well. After restarting it still only shows the owntracks client connecting and not openhab.

When you configured mosquitto, did you create a user and password for openhab?

Do you have a firewall running on the openHAB server?

1 Like

Hi Rich, yes in my passwd file, I Created a user openhab and a password to match the Mqtt.cfg. I even deleted it and created it again Just in case it was wrong.
I use the ufw firewall on the raspberry pi but I’ve allowed 1883 and 8883.

Just to completely rule out the firewall, disable ufw and restart openhab

Also, you do have the MQTT binding installed?

Do you also have the MQTT Action installed? There was a bug a while back where the Action would break the binding. I don’t know if it is fixed yet.

1 Like

Since you have done several changes to your mqtt.cfg, it wouldn’t hurt to delete /var/lib/openhab2/config/org/openhab/mqtt.config to avoid this issue:

1 Like

I won’t be able to do this for a few days but when I can I’ll try with the firewall.
I do have th Mqtt binding installed but I not sure about the action I’ll have a look and get back to you.

Hey Dim I cant do this for a a few days but I’ll give it a go when I can and see what happens.

ok Rich so i turned off ufw and restarted but this had no effect. I definitley have the Mqtt binding installed and i did have the action binding install but i uninstalled and tried a restart again. No change unfortunately. However in the openhab2 log i did find this:

2017-06-20 12:00:34.176 [INFO ] [] - MQTT Service initialization completed.
2017-06-20 12:00:34.178 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'
2017-06-20 12:00:34.377 [ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type 'mqtt' of item 'Mobile_Tim_mqtt' could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: Configuration 'mosquitto:owntracks/Tim/Android/event:home' is not a valid inbound configuration: Configuration requires 4 or 5 parameters separated by ':'
	at org.openhab.core.binding.internal.BindingConfigReaderDelegate.processBindingConfiguration(
	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.internalDispatchBindings(
	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.dispatchBindingsPerType(
	at org.eclipse.smarthome.model.item.internal.GenericItemProvider.addBindingConfigReader(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_131]
	at sun.reflect.NativeMethodAccessorImpl.invoke([:1.8.0_131]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke([:1.8.0_131]
	at java.lang.reflect.Method.invoke([:1.8.0_131]
	at org.apache.felix.scr.impl.inject.BaseMethod.invokeMethod([32:org.apache.felix.scr:2.0.6]
	at org.apache.felix.scr.impl.inject.BaseMethod.access$500([32:org.apache.felix.scr:2.0.6]
	at org.apache.felix.scr.impl.inject.BaseMethod$Resolved.invoke([32:org.apache.felix.scr:2.0.6]
	at org.apache.felix.scr.impl.inject.BaseMethod.invoke([32:org.apache.felix.scr:2.0.6]
	at org.apache.felix.scr.impl.inject.BindMethod.invoke([32:org.apache.felix.scr:2.0.6]
	at org.apache.felix.scr.impl.manager.DependencyManager.doInvokeBindMethod([32:org.apache.felix.scr:2.0.6]
	at org.apache.felix.scr.impl.manager.DependencyManager.invokeBindMethod([32:org.apache.felix.scr:2.0.6]
	at org.apache.felix.scr.impl.manager.SingleComponentManager.invokeBindMethod([32:org.apache.felix.scr:

any ideas why it’s showing my binding as invalid?

I removed this file with no change to the problem although maybe the log i posted to Rich might help.
one thing ive noticed is that mosquitto no longer starts when i boot the raspberry up it tries but then creates an error. I can get it to start manually though with no problems.

The binding is fine.

The error states that the config on Mobile_Tim_mqtt is invalid. Look at that item and look at the mqtt readme and you should see you are missing some parameters.

Right so my item config is

Switch Mobile_Tim_mqtt "Tim's Gps" <presence> { mqtt="<[mosquitto:owntracks/Tim/Android/event:home]" }

And according to the Mqtt readme the 2 options I’m missing are type and transformation. In other words my item should be this

Switch Mobile_Tim_mqtt "Tim's Gps" <presence> { mqtt="<[mosquitto:owntracks/Tim/Android/event:home:state:default ]" }

Surely this shouldn’t stop openhab connecting as a client even if it has nothing to send as a message.

I’ll try the new configuration and see what changes.

Switch Mobile_Tim_mqtt "Tim's Gps" <presence> { mqtt="<[mosquitto:owntracks/Tim/Android/event:state:default ]" }
Switch Mobile_Tim_mqtt "Tim's Gps" <presence> { mqtt="<[mosquitto:owntracks/Tim/Android/event/home:state:default ]" }

the syntax is: broker:topic:type:transformer (you had event:home and then state:default)

Also: (in mosquitto.conf) try to remove the bind address limitation from the first listener to see if this will help

listener 1883
1 Like

Ok I seem to be making some progress, so i changed the syntax for the item to

Switch Mobile_Tim_mqtt "Tim's Gps" <presence> { mqtt="<[mosquitto:owntracks/Tim/Android/event:home:state:default ]" }

this removed the error i was having however this didnt solve openhab not connecting as a client.

I decided to unistall the binding and any tmp files associated with mqtt.cfg
after i reinstalled it and it shows openhab connecting.

mosquitto version 1.4.12 (build date Thu, 25 May 2017 22:38:16 +0100) starting
1497986616: Config loaded from /etc/mosquitto/mosquitto.conf.
1497986616: Opening ipv4 listen socket on port 1883.
1497986616: Opening ipv4 listen socket on port 8883.
1497986616: Opening ipv6 listen socket on port 8883.
1497986836: New connection from on port 8883.
1497986836: Client tim/android disconnected.
1497986836: New client connected from as tim/android (c0, k3600, u'Tim').
1497986836: Sending CONNACK to tim/android (0, 0)
1497986836: Received SUBSCRIBE from tim/android
1497986836: 	owntracks/+/+ (QoS 2)
1497986836: 	owntracks/+/+/info (QoS 2)
1497986836: 	owntracks/Tim/Android/cmd (QoS 2)
1497986836: 	owntracks/+/+/event (QoS 2)
1497986836: 	owntracks/+/+/waypoint (QoS 2)
1497986836: Sending SUBACK to tim/android
1497986836: Sending PUBLISH to tim/android (d0, q1, r1, m1634, 'owntracks/Tim/Android', ... (114 bytes))
1497986836: Received PUBACK from tim/android (Mid: 1634)
1497986960: New connection from on port 1883.
1497986960: New client connected from as openhab.1497986960113 (c1, k60, u'openhab').
1497986960: Sending CONNACK to openhab.1497986960113 (0, 0)
1497986990: Received DISCONNECT from openhab.1497986960113
1497986990: Client openhab.1497986960113 disconnected.
1497987018: New connection from on port 1883.
1497987018: New client connected from as openhab.1497987018633 (c1, k60, u'openhab').
1497987018: Sending CONNACK to openhab.1497987018633 (0, 0)

The only issue i have now is that the switch doesnt change to (ON) on the sitemap what am i missing ?

thanks again Rich and Dim for all your help so far.

It looks wrong to me

what is the topic that you want to subscribe to?

this part: event:home:state:default is not following the proper syntax

Is home a part of the topic? If yes, it should be: event/home (not event:home)

Keep in mind that mqtt= is not the same as mqttitude=

Maybe you want:

Switch Mobile_Tim_mqtt "Tim's Gps" <presence> { mqttitude="<[mosquitto:owntracks/Tim/Android/event:home ]" }

Whoops sorry Dim I’ve typed the syntax the way you showed me in a previous
message in my items file like this

Switch Mobile_Tim_mqtt "Tim's Gps" <presence> { mqtt="<[mosquitto:owntracks/
Tim/Android/event/home:state:default ]" }

That’s just a typing error in the message I sent you.
So the owntracks booklet suggests that I subscribe to the topic
Tim/Android/Event and home is the region I have added in the owntracks app
as part of the event when I enter or leave that geo fence.

All I want to do is have the sitemap switch show ON when I enter the home
geofence and OFF when I leave. Is there a better way to do this ?

If I don’t show status and default in the syntax it suggests in the log that I am missing bits.

…but… with another binding (not mqtt)

Use the OwnTracks (formerly MQTTitude) Binding to achieve what you are looking for

Switch Mobile_Tim_mqtt "Tim's Gps" <presence> { mqttitude="<[mosquitto:owntracks/Tim/Android/event:home ]" }

For event:home to work, I think that you need to define a geofence (or region… not sure)

Alternatively, for just a switch (without geofencing), use manual config:

Switch Mobile_Tim_mqtt "Tim's Gps" <presence> { mqttitude="<[mosquitto:owntracks/Tim/Android ]" }

I think this is where my confusion is coming from. When I downloaded the owntracks binding before it gave me the option to define a location but I unstood this was a manual mode and I was achieving the same thing in the app by defining a location/region and what the owntracks binding docs called region mode.

Does this mean I need the owntracks binding installed and a configured with a geolocation like the region I have on the owntracks app ?

Or just installed and then change the item as you have shown to mqttitude=