Error with embedded MQTT

Hi,

I am hoping that somebody here can help me with a problem I am having enabling the embedded MQTT broker within home assistant.

I have been successfully running home assistant for some time now, and it is great however have recently grown a need to implement MQTT. My Home Assistant running the native docker image and is unable to use port 8080 as this is used by another service.

My MQTT config is as follows:
mqtt:
embedded:
listeners:
default:
max-connections: 200
type: tcp
my-tcp-1:
bind: 0.0.0.0:1883

my-ws-1:

bind: 0.0.0.0:1884

type: ws

    timeout-disconnect-delay: 2

Note I have tried with the Web Service enable and disabled and see the same issue.

Issue is as follows - Home assistant reports that the MQTT broker is unable to start as it needs a configuration, however from the debug logs it appears to start successfully. Logs below.

2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker.plugins] Loading plugins for namespace hbmqtt.broker.plugins
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker.plugins] Loading plugin auth_anonymous = hbmqtt.plugins.authentication:AnonymousAuthPlugin
2017-08-14 22:23:41 DEBUG (MainThread) [passlib.utils.compat] loaded lazy attr ‘SafeConfigParser’: <class ‘configparser.ConfigParser’>
2017-08-14 22:23:41 DEBUG (MainThread) [passlib.utils.compat] loaded lazy attr ‘NativeStringIO’: <class ‘_io.StringIO’>
2017-08-14 22:23:41 DEBUG (MainThread) [passlib.utils.compat] loaded lazy attr ‘BytesIO’: <class ‘_io.BytesIO’>
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker.plugins] Initializing plugin auth_anonymous = hbmqtt.plugins.authentication:AnonymousAuthPlugin
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker.plugins] Plugin auth_anonymous ready
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker.plugins] Loading plugin auth_file = hbmqtt.plugins.authentication:FileAuthPlugin
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker.plugins] Initializing plugin auth_file = hbmqtt.plugins.authentication:FileAuthPlugin
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker.plugins.auth_file] Configuration parameter ‘password_file’ not found
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker.plugins] Plugin auth_file ready
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker.plugins] Loading plugin broker_sys = hbmqtt.plugins.sys.broker:BrokerSysPlugin
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker.plugins] Initializing plugin broker_sys = hbmqtt.plugins.sys.broker:BrokerSysPlugin
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker.plugins] Plugin broker_sys ready
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker.plugins] Loading plugin packet_logger_plugin = hbmqtt.plugins.logging:PacketLoggerPlugin
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker.plugins] Initializing plugin packet_logger_plugin = hbmqtt.plugins.logging:PacketLoggerPlugin
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker.plugins] Plugin packet_logger_plugin ready
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker] Broker starting
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker] Listener configuration ‘default’ is not bound
2017-08-14 22:23:41 INFO (MainThread) [hbmqtt.broker] Listener ‘my-tcp-1’ bind to 0.0.0.0:1883 (max_connections=-1)
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker] Broker started
2017-08-14 22:23:41 ERROR (MainThread) [homeassistant.components.mqtt] Unable to start MQTT broker. (Broker configuration required.)
2017-08-14 22:23:41 INFO (MainThread) [homeassistant.setup] Setup of domain mqtt took 2.7 seconds.
2017-08-14 22:23:41 ERROR (MainThread) [homeassistant.setup] Setup failed for mqtt: Component failed to initialize.
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker] Retaining message on topic $SYS/broker/version
2017-08-14 22:23:41 DEBUG (MainThread) [hbmqtt.broker.plugins.broker_sys] $SYS disabled
2017-08-14 22:23:41 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=persistent_notification, service=create, service_data=title=Invalid config, message=The following components and platforms could not be set up:

Any ideas would be appreciated.

Thanks,
Nichol

Does anybody have any ideas on what could be causing this?

Thanks,
Nichol

I have solved the problem.
it appears as well as defining the embedded MQTT server you need separately specify the ip addrress that HASS will use to connect to the embedded server.

I am having another problem now where the MQTT sever is not passing all messages.

I have decided that the embedded MQTT broker is possibly a bit buggy and have spun up a separate mqtt broker and all is good now.

hey, for what it’s worth here is my current conf

mqtt:
  embedded: 
    listeners:
      default:
        type: tcp
        max-connections: 5000
      internal_tcp_1:
        bind: 127.0.0.1:1882
      external_tcp_1:
        bind: 0.0.0.0:1883
        ssl: on
        certfile: !secret ssl_certificate
        keyfile:  !secret ssl_key
      ws-1:
        bind: 0.0.0.0:8080
        type: ws
    auth:
      plugins: ['auth_anonymous']
      allow-anonymous: false
      password-file: !secret hbmqttaccess
  broker: 127.0.0.1
  port: 1882
  client_id: home-assistant-1
  username: home-assitant-1
  password: !secret api_password
  discovery: true

ssl port is mapped by the router.
Ha! hass password has to be hashed in the password-file too !

Cheers

5 Likes

Hi, what do you mean by password has to be hashed in the password-file ? how do you hash a password inside a file ?

If you didn’t get the the time to figure it out, it’s in the end of the hbmqtt doc.
tldr:
use the interactive mkpasswd -m sha-512 command to encode the password and store the resulting hash in the password file:

username:$$6$9RcI5VHqF5bpfI$zL/0d8iC2...
1 Like

Thanks, I already moved to Mosquitto, I appreciate that !

I’m not able to start embedded mqtt.
Config:

mqtt:
  discovery: true
  discovery_prefix: homeassistant
  embedded:
    listeners:
      default:
        max-connections: 5000
        bind: 192.168.1.1:1883
        type: tcp
      ws-1:
          bind: 192.168.1.1:8083
          type: ws
    auth:
      plugins: ['auth.anonymous']
      allow-anonymous: true
  broker: 192.168.1.1
  port: 1883

Log:

2018-10-26 21:08:49 INFO (MainThread) [homeassistant.setup] Setup of domain logger took 0.0 seconds.
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.loader] Loaded recorder from homeassistant.components.recorder
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.setup] Setting up recorder
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.loader] Loaded history from homeassistant.components.history
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.loader] Loaded http from homeassistant.components.http
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.loader] Loaded frontend from homeassistant.components.frontend
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.loader] Loaded api from homeassistant.components.api
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.loader] Loaded system_log from homeassistant.components.system_log
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.loader] Loaded auth from homeassistant.components.auth
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.loader] Loaded onboarding from homeassistant.components.onboarding
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.loader] Loaded lovelace from homeassistant.components.lovelace
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.loader] Loaded mqtt from homeassistant.components.mqtt
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.setup] Setting up mqtt
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.loader] Loaded mqtt.server from homeassistant.components.mqtt.server
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.setup] Setting up http
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.setup] Setup of domain http took 0.0 seconds.
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.setup] Setting up lovelace
2018-10-26 21:08:49 INFO (MainThread) [homeassistant.setup] Setup of domain lovelace took 0.0 seconds.
2018-10-26 21:08:49 DEBUG (MainThread) [hbmqtt.broker.plugins] Loading plugins for namespace hbmqtt.broker.plugins
2018-10-26 21:08:49 DEBUG (MainThread) [hbmqtt.broker.plugins] Loading plugin auth_anonymous = hbmqtt.plugins.authentication:AnonymousAuthPlugin
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker.plugins] Initializing plugin auth_anonymous = hbmqtt.plugins.authentication:AnonymousAuthPlugin
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker.plugins] Plugin auth_anonymous ready
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker.plugins] Loading plugin auth_file = hbmqtt.plugins.authentication:FileAuthPlugin
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker.plugins] Initializing plugin auth_file = hbmqtt.plugins.authentication:FileAuthPlugin
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker.plugins.auth_file] Configuration parameter ‘password_file’ not found
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker.plugins] Plugin auth_file ready
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker.plugins] Loading plugin broker_sys = hbmqtt.plugins.sys.broker:BrokerSysPlugin
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker.plugins] Initializing plugin broker_sys = hbmqtt.plugins.sys.broker:BrokerSysPlugin
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker.plugins] Plugin broker_sys ready
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker.plugins] Loading plugin packet_logger_plugin = hbmqtt.plugins.logging:PacketLoggerPlugin
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker.plugins] Initializing plugin packet_logger_plugin = hbmqtt.plugins.logging:PacketLoggerPlugin
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker.plugins] Plugin packet_logger_plugin ready
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker.plugins] Loading plugin topic_taboo = hbmqtt.plugins.topic_checking:TopicTabooPlugin
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker.plugins] Initializing plugin topic_taboo = hbmqtt.plugins.topic_checking:TopicTabooPlugin
2018-10-26 21:08:50 WARNING (MainThread) [hbmqtt.broker.plugins.topic_taboo] ‘topic-check’ section not found in context configuration
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker.plugins] Plugin topic_taboo ready
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker] Broker starting
2018-10-26 21:08:50 INFO (MainThread) [homeassistant.setup] Setting up onboarding
2018-10-26 21:08:50 INFO (MainThread) [homeassistant.setup] Setting up api
2018-10-26 21:08:50 INFO (MainThread) [homeassistant.setup] Setting up websocket_api
2018-10-26 21:08:50 INFO (MainThread) [homeassistant.setup] Setup of domain websocket_api took 0.0 seconds.
2018-10-26 21:08:50 INFO (MainThread) [homeassistant.setup] Setting up system_log
2018-10-26 21:08:50 INFO (MainThread) [homeassistant.setup] Setup of domain system_log took 0.0 seconds.
2018-10-26 21:08:50 INFO (MainThread) [homeassistant.setup] Setting up auth
2018-10-26 21:08:50 INFO (MainThread) [homeassistant.setup] Setup of domain auth took 0.0 seconds.
2018-10-26 21:08:50 INFO (MainThread) [homeassistant.setup] Setup of domain api took 0.0 seconds.
2018-10-26 21:08:50 INFO (MainThread) [hbmqtt.broker] Listener ‘default’ bind to 192.168.1.1:1883 (max_connections=-1)
2018-10-26 21:08:50 INFO (MainThread) [hbmqtt.broker] Listener ‘ws-1’ bind to 192.168.1.1:8083 (max_connections=-1)
2018-10-26 21:08:50 DEBUG (MainThread) [hbmqtt.broker] Broker started
2018-10-26 21:08:50 ERROR (MainThread) [homeassistant.components.mqtt] Unable to start embedded MQTT broker
2018-10-26 21:08:50 INFO (MainThread) [homeassistant.setup] Setup of domain mqtt took 0.7 seconds.
2018-10-26 21:08:50 ERROR (MainThread) [homeassistant.setup] Setup failed for mqtt: Component failed to initialize.

When I open http://192.168.1.1:8083/ in browser, it shows:

Invalid Connection header: keep-alive

This appears to be related to this error.

is this already resolved?