Configuring OwnTracks/MQTT

I am trying to set up OwnTracks to do presence detection. I’m running on Hass.io, and installed the “MQTT Server & Web client” plugin. It appears to be working correctly. When I open the web client, I am able to publish packets and see packets pushed from the iOS OwnTracks app on my phone.

HA appears to see the MQTT setup, I get the little MQTT icon among the developer tools. However, trying to publish from there doesn’t seem to do anything.

Additionally, in my entities list, I don’t see anything that looks like the device tracker.

Since MQTT is working between the OwnTracks App and the Web client, this makes me think the problem is in the HA setup. Here are the relevant configuration blocks:

MQTT/Web settings:

{
  "log_level": "debug",
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem",
  "web": {
    "enabled": true,
    "username": "!secret mqtt_broker_username1",
    "password": "!secret mqtt_broker_password1",
    "ssl": true
  },
  "broker": {
    "enabled": true,
    "enable_ws": true,
    "enable_mqtt": true,
    "enable_ws_ssl": true,
    "enable_mqtt_ssl": true,
    "allow_anonymous": false
  },
  "mqttusers": [
    {
      "username": "!secret mqtt_broker_username1",
      "password": "!secret mqtt_broker_password1",
      "readonly": false,
      "topics": [
        "#"
      ]
    }
  ]
}

configuration.yaml :

mqtt:
 broker: a0d7b954-mqtt
 port: !secret mqtt_port

device_tracker:
  - platform: owntracks
    max_gps_accuracy: 200
    waypoints: true
    mqtt_topic: "owntracks/#" 

Any advice would be appreciated.

Pushed (published) from where to where? from hass.io to owntracks (I do not use either service so a shot in the dark).

You are not specifying the username or password. Also worth specifying the client ID as that creates a persistent connection.

When I say " packets pushed from the iOS OwnTracks app on my phone." I mean that when I use the web client to monitor MQTT, I can see the packets being published by the OwnTracks app. It’s set to publish its location to the MQTT broker, and the web client sees those messages. So it seems that the broker itself is working correctly.

The user name thing makes sense. I’ve made some edits:

The plug-in configuration now reads (relevant, changed part)

  "mqttusers": [
    {
      "username": "!secret mqtt_broker_username_ha",
      "password": "!secret mqtt_broker_password_ha",
      "readonly": false,
      "topics": [
        "#"
      ]
    },
    {
      "username": "!secret mqtt_broker_username0",
      "password": "!secret mqtt_broker_password0",
      "readonly": false,
      "topics": [
        "#"
      ]
    },
    {
      "username": "!secret mqtt_broker_username1",
      "password": "!secret mqtt_broker_password1",
      "readonly": false,
      "topics": [
        "#"
      ]
    }

The intent is for the ha username to be the login HA uses, and user0 and user1 to be the two adults in the house who have phones that can be tracked (though my wife’s is not yet set up).

configuration.yaml now has:

mqtt:
 broker: a0d7b954-mqtt
 port: !secret mqtt_port
 username: !secret mqtt_broker_username_ha
 password: !secret mqtt_broker_password_ha
 client_id: "Hass"

This, however, didn’t make things better. MQTT broker, mqtt web client, and OwnTracks still all talk to one another, but on boot HA throws the following error and warning:

Warning:

Unable to remove unknown listener <function async_track_point_in_utc_time.<locals>.point_in_time_listener at 0x6f8bb390>`

This looks like the bug reported here: https://github.com/home-assistant/home-assistant/issues/17204 but I don’t have any scripting like in that bug - no delays or such, and it showed up when I made these edits.

Error:

Error doing job: Task exception was never retrieved

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/storage.py", line 160, in _async_callback_delayed_write
    await self._async_handle_write_data()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/storage.py", line 172, in _async_handle_write_data
    if 'data_func' in data:
TypeError: argument of type 'NoneType' is not iterable

No clue what this is about.

Are you using HassOS and have you checked the “home-assistant.log” ? I have an error as well but i am not trying to use owntracks but trying to use mqtt sensors and the MQTT broker addon is working fine as well. HA does not seem to connect whatever i have tried so far.

Have you tried using the local ip adress or domain as broker entry ?

I am using the Hass.io pre-generated image, so whatever version of the OS that installs.

Not sure where home-assistant.log lives in the directory tree.

I’ve tried using the local ip address, and I’ve tried using the global domain name (no local domain name, as I don’t have local DNS, plus the SSL certificates are set up for the global domain name through Let’s Encrypt and DuckDNS).

I think the errors posted above were unrelated. Restarting cleared them. But I’m still not seeing HA messages (sent via the mqtt dev tool) on the MQTT broker, and not seeing any evidence of the OwnTracks presence in HA

Ok, figured it out. After much poking, it looks like I need to use the internal IP address for the Pi. Not “127.0.0.1”, not “localhost”, not external IP, not external host name.

It means connecting to the MQTT broker over non-SSL, but that’s ok. I simply don’t forward that port. So from outside, only SSL connections work. From inside, it allows unencrypted.

Here’s the relevant config, in case anyone else runs into this issue:

mqtt:
  broker: XX.XX.XX.XX
  port: 1883
  username: !secret mqtt_broker_username_ha
  password: !secret mqtt_broker_password_ha
  client_id: "Hass"

device_tracker:
  - platform: owntracks
    max_gps_accuracy: 200
    waypoints: true
    mqtt_topic: "owntracks/#"

Plugin configuration:

{
  "log_level": "debug",
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem",
  "web": {
    "enabled": true,
    "username": "!secret mqtt_broker_username1",
    "password": "!secret mqtt_broker_password1",
    "ssl": true
  },
  "broker": {
    "enabled": true,
    "enable_ws": true,
    "enable_mqtt": true,
    "enable_ws_ssl": true,
    "enable_mqtt_ssl": true,
    "allow_anonymous": false
  },
  "mqttusers": [
    {
      "username": "!secret mqtt_broker_username_ha",
      "password": "!secret mqtt_broker_password_ha",
      "readonly": false,
      "topics": [
        "#"
      ]
    },
    {
      "username": "!secret mqtt_broker_username0",
      "password": "!secret mqtt_broker_password0",
      "readonly": false,
      "topics": [
        "#"
      ]
    },
    {
      "username": "!secret mqtt_broker_username1",
      "password": "!secret mqtt_broker_password1",
      "readonly": false,
      "topics": [
        "#"
      ]
    }
  ]
}