MQTT ConnectionRefusedError: Errno 111 Connection refused

I have some trouble with my Mosquitto MQTT service… it works when I start HA directly from terminal (python virtual environment), but it stops working when automatically started by systemd. Restarting HA-service doesn’t fix the problem. What should I do?

root@pine64:/home/homeassistant/.homeassistant# sudo systemctl restart home-assistant@homeassistant && sudo journalctl -f -u home-assistant@homeassistant | grep -i 'error'
Dec 06 18:39:27 pine64 hass[6384]: 2017-12-06 18:39:27 ERROR (MainThread) [homeassistant.setup] Error during setup of component mqtt
Dec 06 18:39:27 pine64 hass[6384]: ConnectionRefusedError: [Errno 111] Connection refused
Dec 06 18:39:29 pine64 hass[6384]: 2017-12-06 18:39:29 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of sensor.mqtt. Setup failed for dependencies: mqtt
Dec 06 18:39:29 pine64 hass[6384]: 2017-12-06 18:39:29 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.mqtt: Could not setup all dependencies.
Dec 06 18:39:29 pine64 hass[6384]: 2017-12-06 18:39:29 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of sensor.mqtt. Setup failed for dependencies: mqtt
Dec 06 18:39:29 pine64 hass[6384]: 2017-12-06 18:39:29 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.mqtt: Could not setup all dependencies.
Dec 06 18:39:29 pine64 hass[6384]: 2017-12-06 18:39:29 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of sensor.mqtt. Setup failed for dependencies: mqtt
Dec 06 18:39:29 pine64 hass[6384]: 2017-12-06 18:39:29 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.mqtt: Could not setup all dependencies.
Dec 06 18:39:29 pine64 hass[6384]: 2017-12-06 18:39:29 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of sensor.mqtt. Setup failed for dependencies: mqtt
Dec 06 18:39:29 pine64 hass[6384]: 2017-12-06 18:39:29 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.mqtt: Could not setup all dependencies.
Dec 06 18:39:29 pine64 hass[6384]: 2017-12-06 18:39:29 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of switch.mqtt. Setup failed for dependencies: mqtt
Dec 06 18:39:29 pine64 hass[6384]: 2017-12-06 18:39:29 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform switch.mqtt: Could not setup all dependencies.

I think this is normally a username/password problem. Are you sure you are starting HA with the same config file when you start HA from the terminal?

It is using the same config file as per full log file from service restart

root@pine64:/home/homeassistant/.homeassistant# sudo systemctl restart home-assistant@homeassistant && sudo journalctl -f -u home-assistant@homeassistant
-- Logs begin at Wed 2017-12-06 18:01:39 EET. --
Dec 06 18:54:04 pine64 hass[6799]: 2017-12-06 18:54:04 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=automation.cooldown, old_state=<state automation.cooldown=off; friendly_name=Cooldown, last_triggered=None @ 2017-12-06T18:54:02.420456+02:00>, new_state=<state automation.cooldown=on; friendly_name=Cooldown, last_triggered=None @ 2017-12-06T18:54:04.027104+02:00>>
Dec 06 18:54:04 pine64 hass[6799]: 2017-12-06 18:54:04 INFO (MainThread) [homeassistant.core] Timer:starting
Dec 06 18:54:04 pine64 hass[6799]: 2017-12-06 18:54:04 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=group.all_automations, old_state=<state group.all_automations=off; hidden=True, order=0, auto=True, assumed_state=False, entity_id=('automation.cooldown', 'automation.heatup'), friendly_name=all automations @ 2017-12-06T18:54:02.461982+02:00>, new_state=<state group.all_automations=on; hidden=True, order=0, auto=True, assumed_state=False, entity_id=('automation.cooldown', 'automation.heatup'), friendly_name=all automations @ 2017-12-06T18:54:04.037940+02:00>>
Dec 06 18:54:08 pine64 systemd[1]: Stopping Tapulin Kotitonttu for user homeassistant...
Dec 06 18:54:08 pine64 hass[6799]: 2017-12-06 18:54:08 INFO (MainThread) [homeassistant.core] Bus:Handling <Event homeassistant_stop[L]>
Dec 06 18:54:11 pine64 hass[6799]: 2017-12-06 18:54:11 INFO (MainThread) [homeassistant.core] Bus:Handling <Event homeassistant_close[L]>
Dec 06 18:54:11 pine64 hass[6799]: Config directory: /home/homeassistant/.homeassistant
Dec 06 18:54:12 pine64 systemd[1]: Stopped Tapulin Kotitonttu for user homeassistant.
Dec 06 18:54:12 pine64 systemd[1]: Starting Tapulin Kotitonttu for user homeassistant...
Dec 06 18:54:42 pine64 systemd[1]: Started Tapulin Kotitonttu for user homeassistant.
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=turn_off>
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=turn_on>
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=toggle>
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=stop>
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=restart>
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=check_config>
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=reload_core_config>
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=persistent_notification, service=create>
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=persistent_notification, service=dismiss>
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.bootstrap] Home Assistant core initialized
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.loader] Loaded history from homeassistant.components.history
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.loader] Loaded recorder from homeassistant.components.recorder
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.loader] Loaded http from homeassistant.components.http
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.loader] Loaded mqtt from homeassistant.components.mqtt
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.loader] Loaded frontend from homeassistant.components.frontend
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.loader] Loaded api from homeassistant.components.api
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.loader] Loaded websocket_api from homeassistant.components.websocket_api
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.loader] Loaded system_log from homeassistant.components.system_log
Dec 06 18:54:47 pine64 hass[6842]: 2017-12-06 18:54:47 INFO (MainThread) [homeassistant.setup] Setting up mqtt
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 ERROR (MainThread) [homeassistant.setup] Error during setup of component mqtt
Dec 06 18:54:48 pine64 hass[6842]: Traceback (most recent call last):
Dec 06 18:54:48 pine64 hass[6842]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/setup.py", line 190, in _async_setup_component
Dec 06 18:54:48 pine64 hass[6842]:     result = yield from component.async_setup(hass, processed_config)
Dec 06 18:54:48 pine64 hass[6842]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 387, in async_setup
Dec 06 18:54:48 pine64 hass[6842]:     success = yield from hass.data[DATA_MQTT].async_connect()
Dec 06 18:54:48 pine64 hass[6842]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 498, in async_connect
Dec 06 18:54:48 pine64 hass[6842]:     self._mqttc.connect, self.broker, self.port, self.keepalive)
Dec 06 18:54:48 pine64 hass[6842]:   File "/usr/lib/python3.5/asyncio/futures.py", line 361, in __iter__
Dec 06 18:54:48 pine64 hass[6842]:     yield self  # This tells Task to wait for completion.
Dec 06 18:54:48 pine64 hass[6842]:   File "/usr/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
Dec 06 18:54:48 pine64 hass[6842]:     future.result()
Dec 06 18:54:48 pine64 hass[6842]:   File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
Dec 06 18:54:48 pine64 hass[6842]:     raise self._exception
Dec 06 18:54:48 pine64 hass[6842]:   File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
Dec 06 18:54:48 pine64 hass[6842]:     result = self.fn(*self.args, **self.kwargs)
Dec 06 18:54:48 pine64 hass[6842]:   File "/srv/homeassistant/lib/python3.5/site-packages/paho/mqtt/client.py", line 768, in connect
Dec 06 18:54:48 pine64 hass[6842]:     return self.reconnect()
Dec 06 18:54:48 pine64 hass[6842]:   File "/srv/homeassistant/lib/python3.5/site-packages/paho/mqtt/client.py", line 895, in reconnect
Dec 06 18:54:48 pine64 hass[6842]:     sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
Dec 06 18:54:48 pine64 hass[6842]:   File "/usr/lib/python3.5/socket.py", line 711, in create_connection
Dec 06 18:54:48 pine64 hass[6842]:     raise err
Dec 06 18:54:48 pine64 hass[6842]:   File "/usr/lib/python3.5/socket.py", line 702, in create_connection
Dec 06 18:54:48 pine64 hass[6842]:     sock.connect(sa)
Dec 06 18:54:48 pine64 hass[6842]: ConnectionRefusedError: [Errno 111] Connection refused
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=message=The following components and platforms could not be set up:
Dec 06 18:54:48 pine64 hass[6842]:  - [mqtt](https://home-assistant.io/components/mqtt/)
Dec 06 18:54:48 pine64 hass[6842]: Please check your config., notification_id=invalid_config, title=Invalid config, domain=persistent_notification, service=create, service_call_id=548421938592-1>
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=None, new_state=<state persistent_notification.invalid_config=notifying; message=The following components and platforms could not be set up:
Dec 06 18:54:48 pine64 hass[6842]:  - [mqtt](https://home-assistant.io/components/mqtt/)
Dec 06 18:54:48 pine64 hass[6842]: Please check your config., title=Invalid config @ 2017-12-06T18:54:48.111675+02:00>, entity_id=persistent_notification.invalid_config>
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=548421938592-1>
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.setup] Setting up recorder
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=recorder, service=purge>
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.setup] Setting up http
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.setup] Setup of domain http took 0.0 seconds.
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=http>
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.setup] Setting up api
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.setup] Setting up system_log
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.setup] Setting up websocket_api
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.setup] Setup of domain websocket_api took 0.0 seconds.
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=websocket_api>
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.setup] Setup of domain api took 0.1 seconds.
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=api>
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=system_log, service=clear>
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.setup] Setup of domain system_log took 0.1 seconds.
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=system_log>
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.setup] Setting up frontend
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.setup] Setup of domain frontend took 0.1 seconds.
Dec 06 18:54:48 pine64 hass[6842]: 2017-12-06 18:54:48 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=frontend>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.setup] Setup of domain recorder took 1.2 seconds.
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=recorder>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.setup] Setting up history
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.setup] Setup of domain history took 0.0 seconds.
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=history>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.loader] Loaded switch from homeassistant.components.switch
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.loader] Loaded group from homeassistant.components.group
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.loader] Loaded switch.mqtt from homeassistant.components.switch.mqtt
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.loader] Loaded sensor from homeassistant.components.sensor
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.loader] Loaded sensor.mqtt from homeassistant.components.sensor.mqtt
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.setup] Setting up sensor
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.loader] Loaded config from homeassistant.components.config
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.loader] Loaded panel_iframe from homeassistant.components.panel_iframe
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.loader] Loaded google from homeassistant.components.google
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.loader] Loaded automation from homeassistant.components.automation
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.loader] Loaded automation.time from homeassistant.components.automation.time
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.setup] Setting up group
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.setup] Setting up config
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.setup] Setting up panel_iframe
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of sensor.mqtt. Setup failed for dependencies: mqtt
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.mqtt: Could not setup all dependencies.
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of sensor.mqtt. Setup failed for dependencies: mqtt
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.mqtt: Could not setup all dependencies.
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of sensor.mqtt. Setup failed for dependencies: mqtt
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.mqtt: Could not setup all dependencies.
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of sensor.mqtt. Setup failed for dependencies: mqtt
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.mqtt: Could not setup all dependencies.
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.loader] Loaded config.group from homeassistant.components.config.group
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=config.group>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.loader] Loaded config.core from homeassistant.components.config.core
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=config.core>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.loader] Loaded config.hassbian from homeassistant.components.config.hassbian
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.loader] Loaded config.automation from homeassistant.components.config.automation
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=config.automation>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.loader] Loaded config.customize from homeassistant.components.config.customize
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=config.customize>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.loader] Loaded config.script from homeassistant.components.config.script
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=config.script>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=message=The following components and platforms could not be set up:
Dec 06 18:54:49 pine64 hass[6842]:  - [mqtt](https://home-assistant.io/components/mqtt/)
Dec 06 18:54:49 pine64 hass[6842]:  - sensor.mqtt
Dec 06 18:54:49 pine64 hass[6842]: Please check your config., notification_id=invalid_config, title=Invalid config, domain=persistent_notification, service=create, service_call_id=548421938592-2>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=message=The following components and platforms could not be set up:
Dec 06 18:54:49 pine64 hass[6842]:  - [mqtt](https://home-assistant.io/components/mqtt/)
Dec 06 18:54:49 pine64 hass[6842]:  - sensor.mqtt
Dec 06 18:54:49 pine64 hass[6842]: Please check your config., notification_id=invalid_config, title=Invalid config, domain=persistent_notification, service=create, service_call_id=548421938592-3>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=message=The following components and platforms could not be set up:
Dec 06 18:54:49 pine64 hass[6842]:  - [mqtt](https://home-assistant.io/components/mqtt/)
Dec 06 18:54:49 pine64 hass[6842]:  - sensor.mqtt
Dec 06 18:54:49 pine64 hass[6842]: Please check your config., notification_id=invalid_config, title=Invalid config, domain=persistent_notification, service=create, service_call_id=548421938592-4>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=message=The following components and platforms could not be set up:
Dec 06 18:54:49 pine64 hass[6842]:  - [mqtt](https://home-assistant.io/components/mqtt/)
Dec 06 18:54:49 pine64 hass[6842]:  - sensor.mqtt
Dec 06 18:54:49 pine64 hass[6842]: Please check your config., notification_id=invalid_config, title=Invalid config, domain=persistent_notification, service=create, service_call_id=548421938592-5>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.setup] Setup of domain panel_iframe took 0.2 seconds.
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=panel_iframe>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state persistent_notification.invalid_config=notifying; message=The following components and platforms could not be set up:
Dec 06 18:54:49 pine64 hass[6842]:  - [mqtt](https://home-assistant.io/components/mqtt/)
Dec 06 18:54:49 pine64 hass[6842]: Please check your config., title=Invalid config @ 2017-12-06T18:54:48.111675+02:00>, new_state=<state persistent_notification.invalid_config=notifying; message=The following components and platforms could not be set up:
Dec 06 18:54:49 pine64 hass[6842]:  - [mqtt](https://home-assistant.io/components/mqtt/)
Dec 06 18:54:49 pine64 hass[6842]:  - sensor.mqtt
Dec 06 18:54:49 pine64 hass[6842]: Please check your config., title=Invalid config @ 2017-12-06T18:54:48.111675+02:00>, entity_id=persistent_notification.invalid_config>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=548421938592-2>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=548421938592-3>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=548421938592-4>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=548421938592-5>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.setup] Setup of domain sensor took 0.3 seconds.
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=sensor>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=group, service=reload>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=group, service=set>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=group, service=remove>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=group, service=set_visibility>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.setup] Setup of domain group took 0.3 seconds.
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=group>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.setup] Setup of domain config took 0.3 seconds.
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=config>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.setup] Setting up switch
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.setup] Setting up automation
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=None, new_state=<state automation.cooldown=off; friendly_name=Cooldown, last_triggered=None @ 2017-12-06T18:54:49.791048+02:00>, entity_id=automation.cooldown>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=None, new_state=<state automation.heatup=off; friendly_name=Heatup, last_triggered=None @ 2017-12-06T18:54:49.793629+02:00>, entity_id=automation.heatup>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of switch.mqtt. Setup failed for dependencies: mqtt
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform switch.mqtt: Could not setup all dependencies.
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=object_id=all_automations, entities=['automation.cooldown', 'automation.heatup'], name=all automations, visible=False, domain=group, service=set, service_call_id=548421938592-6>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=message=The following components and platforms could not be set up:
Dec 06 18:54:49 pine64 hass[6842]:  - [mqtt](https://home-assistant.io/components/mqtt/)
Dec 06 18:54:49 pine64 hass[6842]:  - sensor.mqtt
Dec 06 18:54:49 pine64 hass[6842]:  - switch.mqtt
Dec 06 18:54:49 pine64 hass[6842]: Please check your config., notification_id=invalid_config, title=Invalid config, domain=persistent_notification, service=create, service_call_id=548421938592-7>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=None, new_state=<state group.all_automations=off; hidden=True, assumed_state=False, friendly_name=all automations, order=0, auto=True, entity_id=('automation.cooldown', 'automation.heatup') @ 2017-12-06T18:54:49.852154+02:00>, entity_id=group.all_automations>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=548421938592-6>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=<state persistent_notification.invalid_config=notifying; message=The following components and platforms could not be set up:
Dec 06 18:54:49 pine64 hass[6842]:  - [mqtt](https://home-assistant.io/components/mqtt/)
Dec 06 18:54:49 pine64 hass[6842]:  - sensor.mqtt
Dec 06 18:54:49 pine64 hass[6842]: Please check your config., title=Invalid config @ 2017-12-06T18:54:48.111675+02:00>, new_state=<state persistent_notification.invalid_config=notifying; message=The following components and platforms could not be set up:
Dec 06 18:54:49 pine64 hass[6842]:  - [mqtt](https://home-assistant.io/components/mqtt/)
Dec 06 18:54:49 pine64 hass[6842]:  - sensor.mqtt
Dec 06 18:54:49 pine64 hass[6842]:  - switch.mqtt
Dec 06 18:54:49 pine64 hass[6842]: Please check your config., title=Invalid config @ 2017-12-06T18:54:48.111675+02:00>, entity_id=persistent_notification.invalid_config>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=548421938592-7>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=automation, service=trigger>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=automation, service=reload>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=automation, service=toggle>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=automation, service=turn_on>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=automation, service=turn_off>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.setup] Setup of domain automation took 0.1 seconds.
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=automation>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=switch, service=turn_off>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=switch, service=turn_on>
Dec 06 18:54:49 pine64 hass[6842]: 2017-12-06 18:54:49 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=switch, service=toggle>

Actually, it seems that Mosquitto is having problems with shell startup aswell

2017-12-06 19:14:07 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of switch.mqtt. Setup failed for dependencies: mqtt
2017-12-06 19:14:07 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform switch.mqtt: Could not setup all dependencies.
2017-12-06 19:14:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_call_id=548195917160-6, service=set, service_data=name=all automations, visible=False, object_id=all_automations, entities=['automation.cooldown', 'automation.heatup'], domain=group>
2017-12-06 19:14:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_call_id=548195917160-7, service=create, service_data=notification_id=invalid_config, title=Invalid config, message=The following components and platforms could not be set up:

 - [mqtt](https://home-assistant.io/components/mqtt/)
 - switch.mqtt
 - sensor.mqtt

Please check your config., domain=persistent_notification>
2017-12-06 19:14:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=group.all_automations, new_state=<state group.all_automations=off; friendly_name=all automations, assumed_state=False, auto=True, entity_id=('automation.cooldown', 'automation.heatup'), order=0, hidden=True @ 2017-12-06T19:14:07.953585+02:00>, old_state=None>
2017-12-06 19:14:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=548195917160-6>
2017-12-06 19:14:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=persistent_notification.invalid_config, new_state=<state persistent_notification.invalid_config=notifying; title=Invalid config, message=The following components and platforms could not be set up:

 - [mqtt](https://home-assistant.io/components/mqtt/)
 - switch.mqtt
 - sensor.mqtt

Please check your config. @ 2017-12-06T19:14:06.060755+02:00>, old_state=<state persistent_notification.invalid_config=notifying; title=Invalid config, message=The following components and platforms could not be set up:

 - [mqtt](https://home-assistant.io/components/mqtt/)
 - sensor.mqtt

Please check your config. @ 2017-12-06T19:14:06.060755+02:00>>

This is HA complaining that it cannot understand the config file, rather than a problem with mosquitto.

I got it working by removing
mosquitto package
mosquitto database
HA database
and reverting to earlier HA configuration backup that I kept

I also restarted my wlan box
and HA box was booted 10x during the process

It works now, and I don’t know why.

This error means that the client cannot connect to the port on the computer running server script. This can be caused by few things, like lack of routing to the destination or you have a firewall somewhere between your client and the server - it could be on server itself or on the client etc. Note that a server must perform the sequence socket(), bind(), listen(), accept() (possibly repeating the accept() to service more than one client), while a client only needs the sequence socket(), connect(). Also note that the server does not sendall()/recv() on the socket it is listening on but on the new socket returned by accept(). Try the following:

  • Check if you really have that port listening on the server (this should tell you if your code does what you think it should): based on you OS, but on linux you could do something like netstat -ntulp
  • Check from the server, if you’re accepting the connections to the server: again based on your OS, but telnet LISTENING_IP LISTENING_PORT should do the job
  • Check if you can access the port of the server from the client , but not using the code: just us the telnet (or appropriate command for your OS) from the client