MQTT devices all not working

Hi, I recently reinstalled the latest HA Hassbian. Long story short, I tried to upgrade from 0.51 to 0.69, python version issues so I decided to reinstall Hassbian and move my config files over.

Now all my MQTT devices are not working. I did set up the Mosquitto broker with all the same user name and passwords. I am able to ping from Owntracks on my phone and check via subscribing to the topic on putty and was able to see my phone report stats to it but it’s not showing up on HA. Can someone point me in the right direction?

Mon May 21 2018 01:36:54 GMT-0400 (Eastern Daylight Time)

Error setting up platform owntracks
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/__init__.py", line 180, in async_setup_platform
    hass, p_config, tracker.async_see, disc_info)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/owntracks.py", line 96, in async_setup_scanner
    hass, context.mqtt_topic, async_handle_mqtt_message, 1)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 273, in async_subscribe
    topic, msg_callback, qos, encoding)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 591, in async_subscribe
    await self._async_perform_subscription(topic, qos)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 626, in _async_perform_subscription
    _raise_on_error(result)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 712, in _raise_on_error
    'Error talking to MQTT: {}'.format(mqtt.error_string(result_code)))
homeassistant.exceptions.HomeAssistantError: Error talking to MQTT: The client is not currently connected.

My sonoff devices are all not showing up either.

Mon May 21 2018 01:36:50 GMT-0400 (Eastern Daylight Time)

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 314, in _async_add_entity
    await entity.async_added_to_hass()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/switch/mqtt.py", line 114, in async_added_to_hass
    self._qos)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 273, in async_subscribe
    topic, msg_callback, qos, encoding)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 591, in async_subscribe
    await self._async_perform_subscription(topic, qos)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 626, in _async_perform_subscription
    _raise_on_error(result)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 712, in _raise_on_error
    'Error talking to MQTT: {}'.format(mqtt.error_string(result_code)))
homeassistant.exceptions.HomeAssistantError: Error talking to MQTT: The client is not currently connected

Double check your config. Copying config files from 0.51 to 0.69 might break a couple of things.

Something is not quite matching in the mqtt: section. Double check your username, password and ip address. Also show the output of

sudo tail /var/log/mosquitto/mosquitto.log

As that might indicate what is going wrong.

Also setting up logging on HA might indicate the problem

1 Like

I feel like every time I do an upgrade things break in HA, I’m close to giving up with HA… :triumph:

I did the mosquitto.log and all I got was:

pi@hassbian:~ $ sudo tail /var/log/mosquitto/mosquitto.log
1526803135: mosquitto version 1.5 starting
1526803135: Config loaded from /etc/mosquitto/mosquitto.conf.
1526803135: Opening ipv4 listen socket on port 1883.
1526803135: Opening ipv6 listen socket on port 1883.
1526803137: mosquitto version 1.5 terminating
pi@hassbian:~ $ tail -f /home/homeassistant/.homeassistant/home-assistant.log
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/                             mqtt/__init__.py", line 273, in async_subscribe
    topic, msg_callback, qos, encoding)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/                             mqtt/__init__.py", line 591, in async_subscribe
    await self._async_perform_subscription(topic, qos)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/                             mqtt/__init__.py", line 626, in _async_perform_subscription
    _raise_on_error(result)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/                             mqtt/__init__.py", line 712, in _raise_on_error
    'Error talking to MQTT: {}'.format(mqtt.error_string(result_code)))
homeassistant.exceptions.HomeAssistantError: Error talking to MQTT: The client i                             s not currently connected.
2018-05-21 08:55:28 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribi                             ng to owntracks/#

I suspect you are correct with the username and password. Last night before I posted, that was what I suspected and I went through my config to find that I was indeed missing a user straight from HA. I added it and things seemed to be back on track for like 5 mins, then after a reboot, everything was gone. :face_with_symbols_over_mouth::face_with_symbols_over_mouth::tired_face:

That isn’t a good sign. Just to confirm it has stopped, try

systemctl status mosquitto.service

No I think it’s still running? Sorry I’m a bit of a noob but I appreciate the help.

pi@hassbian:~ $ systemctl status mosquitto.service
● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
   Loaded: loaded (/etc/init.d/mosquitto; generated; vendor preset: enabled)
   Active: active (running) since Mon 2018-05-21 01:22:38 EDT; 8h ago
     Docs: man:systemd-sysv-generator(8)
  Process: 305 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mosquitto.service
           └─383 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

May 21 01:22:37 hassbian systemd[1]: Starting LSB: mosquitto MQTT v3.1 message broker...
May 21 01:22:38 hassbian mosquitto[305]: Starting network daemon:: mosquitto.
May 21 01:22:38 hassbian systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker.
pi@hassbian:~ $

That certainly looks like it is running. The log file is odd though.

But now you have a broker up, you can use mosquitto_pub as in the MQTT testing page to connect to it, and check you have the correct ip address, username and password.

Ok, so I found two “users” were missing. They are sonoff switches that required a username for each. I readded them all and was able to sub to the topic and pub to it. I can manually get the switches to trigger which is great news. That means the very least the MQTT is working.

However, the switches are not showing up on the HA GUI which is driving me crazy. I am also missing my phone battery indicator which this info gets reported from OwnTracks via MQTT. I can see the msgs being published to my MQTT on my pi but it’s not even showing up on HA…:unamused:

Are the missing items showing up and changing state on the states page under developer tools?

wow you don’t sleep do you. :stuck_out_tongue: I’m just up watching my newborn…

No they are not there in the states, I was just checking after I posted.
It should be like switch.strip_cord or switch.strip_cord_white. They were there before I did a fresh upgrade. I even tried copy and pasting the yaml straight into the configuration.yaml file under switch: and not working.

My MQTT strip cord yaml

platform: mqtt
name: "Strip Cord"
command_topic: "cmnd/sonoff/power"
state_topic: "stat/sonoff/POWER"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true

Just answering some questions over breakfast. I don’t do anything complex until after the first mug of coffee :grinning:

Is your HA connecting to the broker now, or are you still getting the error messages from your original post?

1 Like

Looks like the same errors are there. I got 4 MQTT errors, which makes sense since I have 4 instances of MQTT. I tested OwnTracks today while I was out and it did not update HA. The messages are going through but it’s not updating to HA, that is probably why my devices are missing.

Tue May 22 2018 18:56:32 GMT-0400 (Eastern Daylight Time)

Error setting up platform owntracks
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/__init__.py", line 180, in async_setup_platform
    hass, p_config, tracker.async_see, disc_info)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/owntracks.py", line 96, in async_setup_scanner
    hass, context.mqtt_topic, async_handle_mqtt_message, 1)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 273, in async_subscribe
    topic, msg_callback, qos, encoding)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 591, in async_subscribe
    await self._async_perform_subscription(topic, qos)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 626, in _async_perform_subscription
    _raise_on_error(result)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 712, in _raise_on_error
    'Error talking to MQTT: {}'.format(mqtt.error_string(result_code)))
homeassistant.exceptions.HomeAssistantError: Error talking to MQTT: The client is not currently connected.

Tue May 22 2018 18:56:26 GMT-0400 (Eastern Daylight Time)

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 314, in _async_add_entity
    await entity.async_added_to_hass()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/switch/mqtt.py", line 114, in async_added_to_hass
    self._qos)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 273, in async_subscribe
    topic, msg_callback, qos, encoding)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 591, in async_subscribe
    await self._async_perform_subscription(topic, qos)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 626, in _async_perform_subscription
    _raise_on_error(result)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 712, in _raise_on_error
    'Error talking to MQTT: {}'.format(mqtt.error_string(result_code)))
homeassistant.exceptions.HomeAssistantError: Error talking to MQTT: The client is not currently connected.

I got it, you were right about the username and passwords.

So what I noticed was the user for HA was missing even though I was 100% sure I added it which I did. However, I used the wrong command to add additional users after which overwrote the original pwfile hence deleting my MQTT user for HA :flushed:

I noticed when I dug into the pwfile that HA MQTT user was missing.

I kept using sudo mosquitto_passwd -c /etc/mosquitto/pwfile username which is ok for the first user, additional users should us -b instead sudo mosquitto_passwd -b /etc/mosquitto/pwfile newusername password gahhhh so stupid :flushed:

Thank you so much @gpbenton for working this out with me. Always a great community of people. I think talking it through with you kept me sane through all this :rofl:

1 Like

It seems I have the same problem, but I do not have anything set as username and password on my mosquitto/hassio configuration.

Please note I use HASSIO so I don’t know how to follow the instructions as above (mosquitto testing and so on)

This my settingsd

mqtt:
  broker: core-mosquitto
  birth_message:
    topic: 'hassio/status'
    payload: 'online'
  will_message:
    topic: 'hassio/status'
    payload: 'offline'

I wish I could help you but I don’t know anything about HASSIO.

You can’t access mosquito or the password file for MQTT? I found that I was just missing users so MQTT did not work for me.

Hopefully someone with more experience can chime in and help you out.

I think my problem was related to a DNS iissue in hassio_supervisor

Running on fresh version of Hassio. No MQTT devices are appearing despite being able to communicate with MQTT Broker (Add-On) installed on my pi. All Sonoff’s use username/pwd to talk to MQTT broker (which appears working).

Here is config of MQTT Add-on:
{
“logins”: [
{
“username”: “”,
“password”: “”
}
],
“anonymous”: false,
“customize”: {
“active”: false,
“folder”: “mosquitto”
},
“certfile”: “fullchain.pem”,
“keyfile”: “privkey.pem”
}

And a log entry to show I’m connecting.
1542487392: New client connected from 192.168.178.242 as B2MR_lamp (c1, k15, u’b2mqtt’).
1542487552: New connection from 192.168.178.42 on port 1883.

Any thoughts?

~Bryan

Hi I´m facing difficulties after the update from mqqt mosquitto, I´ve changed the username so it´s not “homeassistant” anymore, I erased all my mqtt config.yaml and integrated trough fontend, my devices are apearing in the logs of the addon it seems to be conected but I can make my devices to work. Logs not showing anything about this. Here´s my sensors:

 - platform: mqtt  
    state_topic: "bruh/sensornode1"  
    name: "SN1 Humidity"  
    unit_of_measurement: "%"  
    value_template: '{{ value_json.humidity | round(1) }}'  
  
  - platform: mqtt  
    state_topic: "bruh/sensornode1"  
    name: "SN1 LDR"
    ##This sensor is not calibrated to actual LUX. Rather, this a map of the input voltage ranging from 0 - 1023.
    unit_of_measurement: "LUX"  
    value_template: '{{ value_json.ldr }}'  
  
  - platform: mqtt  
    state_topic: "bruh/sensornode1"  
    name: "SN1 PIR"  
    value_template: '{{ value_json.motion }}'  
  
  - platform: mqtt  
    state_topic: "bruh/sensornode1"  
    name: "SN1 Temperature"  
    unit_of_measurement: "°F"  
    value_template: '{{ value_json.temperature | round(1) }}'
1 Like