Why can't pi w [monitor] talk to my mqtt hassio addon?

home assistant version 0.84.6

Things i’ve tried

  1. use hassio username/password (that i login to) with mqtt broker
  2. point config.yaml file to homeassistant with correct username/password
  3. also tried configuring my own docker image for eclipse mosquitto, got it setup and running (pointed hassio to this and it was able to connect, but nothing came across from monitor script/pi w)

getting errors in logs, rasberry pi w with monitor script can’t connect to mqtt addon,
script im trying to utilize on pi w: [monitor] Reliable, Multi-User, Distributed Bluetooth Occupancy/Presence Detection
the pi w is pointed to my hassio, 192.168.1.214 ip address with the correct username and password in hassio that i login to

hassio logs from mqtt broker
Repeated errors: [INFO] found David on local database
1546735664: New client connected from 192.168.1.228 as mosqpub|13667-raspberry (c1, k60, u’David’).
1546735664: Client mosqpub|13667-raspberry disconnected.
1546735764: Saving in-memory database to /data/mosquitto.db.

Do i need to open up any ports on hassio? why does it keep disconnecting? Any logs i can look at to further investigate?

No. You can’t open ports because they’re all already open.

Look at the code you put on the pi. Is it supposed to keep the connection open or just broadcast every so often? What makes you think it’s broken?

https://github.com/andrewjfreyer/monitor this is the code,

  1. [INSTALL MOSQUITTO]
# get repo key
wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key

#add repo
sudo apt-key add mosquitto-repo.gpg.key

#download appropriate lists file 
cd /etc/apt/sources.list.d/
sudo wget http://repo.mosquitto.org/debian/mosquitto-stretch.list

#update caches and install 
apt-cache search mosquitto
sudo apt-get update
sudo aptitude install libmosquitto-dev mosquitto mosquitto-clients

I did this, then he says to edit the mqtt_preferences to point it to your server, username/password ect, which i did, however it keeps showing the error message, found username and then disconnects

Let’s clarify:. The steps you posted is not the code. They are installation steps. Let’s look at what the code of the script actually does, rather than a wall of install instructions.

A JSON-formatted MQTT message is reported to a specified broker whenever a specified bluetooth device responds to a name query.

So did you configure any Bluetooth devices to report?

You said you tried with an MQTT broker that wasn’t even installed on hassio, and it didn’t work, so why is this a home assistant issue? You should really be asking these questions on the GitHub page where you downloaded it from. They have an issues page for a reason, to support their script. You seem to be focusing on your broker as the issue, when if the problem happens on multiple brokers, maybe it isn’t an issue with the broker at all…

  1. “Bluetooth devices to report” - yes of course! I added my iphone’s mac address to the list

  2. I have tried the built in mqtt hassio addin in the repository and the pi-w can’t connect to that, hence why im asking for help and trying alternate solutions to see if it’s home assistant or the pi w script. The reason im posting in here is because when i use the hassio addon it immediately drops the connection, so im seeing if anyone has ran into the similar issue

But what happens when you run your own broker OUTSIDE of hassio?

how will that help me resolve the add-on for mqtt in hassio?

Huh?

Have you tried hooking up a client to your broker like mqtt.fx to verify it works? There’s really nothing to an MQTT broker. It either works or it doesn’t. If you can connect a client to it, then the broker isn’t the problem.

So i tried cloudmqtt for shits, and it receives the mqtt topics, however home assistant is still not updating or retrieving information from cloudmqtt

Boggles my mind, why my server wont work, follows guide pricesely, and no connection

Anyways, this is what i have set up for sensors in home assistant

2019-01-06 05:01:39: New client connected from 108.XXX.XXX.XXX as 576aed29-4090-4746-8041-800175083ccf (c1, k60, u’dbcrhhws’).
2019-01-06 05:01:39: No will message specified.
2019-01-06 05:01:39: Sending CONNACK to 576aed29-4090-4746-8041-800175083ccf (0, 0)
2019-01-06 05:01:54: Received SUBSCRIBE from 576aed29-4090-4746-8041-800175083ccf
2019-01-06 05:01:54: monitor/media_room/E4:E4:AB:80:14:92 (QoS 0)
2019-01-06 05:01:54: Sending SUBACK to 576aed29-4090-4746-8041-800175083ccf
2019-01-06 05:02:09: Received PINGREQ from mosqsub|31442-raspberry
2019-01-06 05:02:09: Sending PINGRESP to mosqsub|31442-raspberry
2019-01-06 05:02:54: Received PINGREQ from 576aed29-4090-4746-8041-800175083ccf
2019-01-06 05:02:54: Sending PINGRESP to 576aed29-4090-4746-8041-800175083ccf
2019-01-06 05:03:09: Received PINGREQ from mosqsub|31442-raspberry
2019-01-06 05:03:09: Sending PINGRESP to mosqsub|31442-raspberry
2019-01-06 05:03:55: Received PINGREQ from 576aed29-4090-4746-8041-800175083ccf

  - platform: mqtt
    name: "Davids Iphone"
    state_topic: "monitor/media_room/E4:E4:AB:80:14:92"
    value_template: "{{ value_json.confidence }}"
    unit_of_measurement: '%'

  - platform: min_max
    name: 'Home Occupancy Confidence of E4:E4:AB:80:14:92'
    type: max
    round_digits: 0
    entity_ids:
      - sensor.media_room

Zero values for my sensor node

Please all stop posting drivel.

Do NOT rely on the internal home assistant mqtt broker, it is crap.

So (assuming your post is correct and you are using hassio as your home assistant install) use the hassio mosquitto addon. When you install the addon it requires you to add a username and password. These are not the same as the username and password you use to log in to home assistant.

Once you have that running, give the mosquitto username and password to the monitor program, via @andrewjfreyer’s instructions.

1 Like

And you completely ignored my suggestion.

[INFO] found myuser on local database
1546789533: New client connected from 192.168.1.214 as e4a53988-976a-4564-83b9-cff9989b3a89 (c1, k60, u’myuser’).
1546789540: Client mosqsub|18882-raspberry has exceeded timeout, disconnecting.
1546789540: Socket error on client mosqsub|18882-raspberry, disconnecting.
1546789589: New connection from 192.168.1.228 on port 1883.
[INFO] found myuser on local database
1546789589: New client connected from 192.168.1.228 as mosqpub|22768-raspberry (c1, k60, u’myuser’).
1546789594: Client mosqpub|22768-raspberry disconnected.
1546789594: New connection from 192.168.1.228 on port 1883.
[INFO] found myuser on local database
1546789594: New client connected from 192.168.1.228 as mosqpub|23306-raspberry (c1, k60, u’myuser’).
1546789594: New connection from 192.168.1.228 on port 1883.
[INFO] found myuser on local database
1546789594: New client connected from 192.168.1.228 as mosqsub|23431-raspberry (c1, k60, u’myuser’).
1546789594: Client mosqpub|23306-raspberry disconnected.

{
  "logins": [
    {
      "username": "myuser",
      "password": "passwordthatdoesnotmatchuseraccounts"
    }
  ],
  "anonymous": false,
  "customize": {
    "active": false,
    "folder": "mosquitto"
  },
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem"
}

updated mqtt_preferences to point to my homeassistant and still getting errors

i noticed i am getting this error in home assistant since trying to setup mqtt

Sun Jan 06 2019 07:46:17 GMT-0800 (Pacific Standard Time)

Unhandled exception
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/aiohttp/web_protocol.py”, line 410, in start
await resp.prepare(request)
File “/usr/local/lib/python3.6/site-packages/aiohttp/web_response.py”, line 300, in prepare
return await self._start(request)
File “/usr/local/lib/python3.6/site-packages/aiohttp/web_response.py”, line 608, in _start
return await super()._start(request)
File “/usr/local/lib/python3.6/site-packages/aiohttp/web_response.py”, line 367, in _start
await writer.write_headers(status_line, headers)
File “/usr/local/lib/python3.6/site-packages/aiohttp/http_writer.py”, line 110, in write_headers
self._write(buf)
File “/usr/local/lib/python3.6/site-packages/aiohttp/http_writer.py”, line 67, in _write
raise ConnectionResetError(‘Cannot write to closing transport’)
ConnectionResetError: Cannot write to closing transport

My local server with mqtt installed on it works as expected

And what happens if you publish to this topic?

monitor/media_room/E4:E4:AB:80:14:92

What happens when you try to connect to your hassio mqtt add-on with mqtt.fx?

Nothing… not sure what to do from here, i can create a custom command with monitor/media_room/mac, but monitor isn’t connecting

this is my mqtt-preference file

# MOSQUITTO PREFERENCES
#
# ---------------------------

# IP ADDRESS OF MQTT BROKER
mqtt_address=192.168.1.226

# MQTT BROKER USERNAME (OR BLANK FOR NONE)
mqtt_user=user

# MQTT BROKER PASSWORD (OR BLANK FOR NONE)
mqtt_password=password

# MQTT PUBLISH TOPIC ROOT
mqtt_topicpath=monitor

# PUBLISHER IDENTITY
mqtt_publisher_identity='media_room'

# MQTT PORT
mqtt_port='1883'

# MQTT CERTIFICATE FILE (LEAVE BLANK IF NONE)

So, it works if you manually publish the topic, from a client app? But it doesn’t work from the monitor script? Seems like an issue with the monitor script, right? I mean logically if you can perform the same task manually from another client, and it works as expected, but it doesn’t work from the script, it would seem like a problem there…

thats all correct, guess i’ll open an issue on github, not sure why his isn’t working, thanks again for your help hopefully he doesn’t close the issue like the last one i created

Have you thought, maybe, taking it to the thread on these forums where he posted the script? Asking in that thread?

[monitor] Reliable, Multi-User, Distributed Bluetooth Occupancy/Presence Detection he doesn’t reply very often, looks like i’ll need to do a more detailed response

So it may not be monitor, could be the pi…, i setup the following on my server:
david@server1:~$ mosquitto_sub -d -h localhost -u user -P password -t dev/test

and on the rasberry pi w:
mosquitto_pub -d -h 192.168.1.226 -u user -P password -t /dev/test -m “hello”

the server did not get the message “hello”
what can i troubleshoot on the rasberry pi where monitor is installed on? I’ve installed all the correct packages per monitor instructions…