Configuration.yaml and MQTT problems

Hi
I am trying to get my configuration.yaml file to load properly and have spent most of yesterday editing and all my additions seem to produce errors. I am hoping someone here can point me in the correct direction.

My Home assistant front page produces these errors:

Invalid config
The following components and platforms could not be set up:

switch.mqtt
mqtt
device_tracker.owntracks

Please check your config


My configuration.yaml file contains:

homeassistant:
  # Name of the location where Home Assistant is running
  name: HOME
  # Location required to calculate the time the sun rises and sets
  latitude: 51.40
  longitude: -0.34
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 10
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Europe/London

# Show links to resources in log and frontend
introduction:

# Enables the frontend
frontend:

# Enables configuration UI
config:

http:
  # Uncomment this to add a password (recommended!)
  # api_password: PASSWORD
  # Uncomment this if you are using SSL or running in Docker etc
  # base_url: example.duckdns.org:8123

# Checks for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# For more information, please see:
# https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
updater:
  # Optional, allows Home Assistant developers to focus on popular components.
  # include_used_components: true

# Discover some devices automatically
discovery:

# Allows you to issue voice commands from the frontend in enabled browsers
conversation:

# Enables support for tracking state changes over time.
history:

# View all events in a logbook
logbook:

# Track the sun
sun:

# Weather Prediction
sensor:
  platform: yr

# Text to speech
tts:
  platform: google

group: !include groups.yaml
automation: !include automations.yaml
 
mqtt:
    broker:  m21.cloudmqtt.com
    port: 1152
    client_id: home-assistant-1
    keepalive: 60
    username: ****
    password: ***
  
  
switch:
  - platform: mqtt
    name: "socket"
    command_topic: "cmnd/sonoff/power"
    state_topic: "stat/sonoff/POWER"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: true 
  
  
device_tracker:
  - platform: owntracks
  


And my log shows:

2017-07-23 11:40:01 ERROR (MainThread) [homeassistant.setup] Error during setup of component mqtt
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/setup.py”, line 187, in _async_setup_component
result = yield from component.async_setup(hass, processed_config)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/mqtt/init.py”, line 380, in async_setup
success = yield from hass.data[DATA_MQTT].async_connect()
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/mqtt/init.py”, line 490, in async_connect
self._mqttc.connect, self.broker, self.port, self.keepalive)
File “/usr/lib/python3.4/asyncio/futures.py”, line 388, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.4/asyncio/tasks.py”, line 286, in _wakeup
value = future.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/homeassistant/.homeassistant/deps/paho/mqtt/client.py”, line 760, in connect
return self.reconnect()
File “/home/homeassistant/.homeassistant/deps/paho/mqtt/client.py”, line 887, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File “/usr/lib/python3.4/socket.py”, line 509, in create_connection
raise err
File “/usr/lib/python3.4/socket.py”, line 500, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
2017-07-23 11:40:21 WARNING (MainThread) [homeassistant.setup] Setup of sensor is taking over 10 seconds.
2017-07-23 11:40:21 WARNING (MainThread) [homeassistant.setup] Setup of group is taking over 10 seconds.
2017-07-23 11:40:21 ERROR (MainThread) [homeassistant.components.device_tracker] Unable to load /home/homeassistant/.homeassistant/known_devices.yaml: Config file not found: /home/homeassistant/.homeassistant/known_devices.yaml
2017-07-23 11:40:21 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of switch.mqtt. Setup failed for dependencies: mqtt
2017-07-23 11:40:21 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform switch.mqtt: Could not setup all dependencies.
2017-07-23 11:40:21 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of device_tracker.owntracks. Setup failed for dependencies: mqtt
2017-07-23 11:40:21 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform device_tracker.owntracks: Could not setup all dependencies.


I am pretty new to setting up home automation and Yaml files
so any help would be greatly appreciated.

Thanks in anticipation

Try to use 2 spaces in front of mqtt data…

Like this:

instead of -

mqtt:
    broker:  m21.cloudmqtt.com
    port: 1152
    client_id: home-assistant-1
    keepalive: 60
    username: ****
    password: ***

Use -

mqtt:
  broker:  m21.cloudmqtt.com
  port: 1152
  client_id: home-assistant-1
  keepalive: 60
  username: ****
  password: ***

Gil :slight_smile:

1 Like

There seem to be an (intermittent?) problem with the m21 cloudmqtt host on 1152. Here is trying to connect to it compared to another of their hosts.

pi@raspberrypi:~ $ telnet m21.cloudmqtt.com 1152
Trying 34.251.42.52...
telnet: Unable to connect to remote host: Connection refused

pi@raspberrypi:~ $ telnet m12.cloudmqtt.com 24938
Trying 52.3.184.147...
Connected to ec2-52-3-184-147.compute-1.amazonaws.com.
Escape character is '^]'.

The clue was in the log you posted.

Thank you for that, that is very helpful ,not quite sure what I can do about it though

Guess your options are to wait, or ping the cloudmqqt folks. Maybe recreate your account and hope you get another host/port that works assigned - or set up a MQTT broker elsewhere e.g. by following this guide:

That setup will have the upside that you will also – optionally – get remote access to the HA front end and you don’t depend on CloudMQTT.
Downside is you now have a few more services to maintain. To minimize the effort to keep DuckDNS, Let’s Encrypt and Mosquitto up to date I would install them as Add-ons in a Hass.io deployment.

Thanks again I am following the instruction link you forwarded and we will see how we get on.
You wouldn’t by any chance know how you automatically start cron on reboot, duckdns tells you up until then and then assumes you have a GUI for that bit instead of using Putty,
Thanks again

You’re welcome :slight_smile:

Sorry, the last bit was not clear to me. Are you asking about this section about setup via sudo crontab -e? At that point when I ssh (or “Putty”) into my Raspberry I see this:

pi@raspberrypi:~ $ sudo crontab -e
no crontab for root - using an empty one

Select an editor.  To change later, run 'select-editor'.
  1. /bin/ed
  2. /bin/nano        <---- easiest
  3. /usr/bin/vim.tiny

Choose 1-3 [2]:

If I then choose 2 I see:

  GNU nano 2.2.6                     File: /tmp/crontab.0Q89oZ/crontab                                                  
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command




^G Get Help         ^O WriteOut         ^R Read File        ^Y Prev Page        ^K Cut Text         ^C Cur Pos
^X Exit             ^J Justify          ^W Where Is         ^V Next Page        ^U UnCut Text       ^T To Spell

At that screen simply paste the two lines after all the # commented instruction lines press Ctrl-X and answer Y to save.

*/5 * * * * ~/duckdns/duck.sh >/dev/null 2>&1
40 11,23 * * * ~/certbot/certbot-auto renew --quiet --no-self-upgrade >> ~/certbot/certbot_renew.log

Hope that was what you were asking about?

Edit: Oh – and I assuming right that you are on a Raspberry Pi too?

Thanks
Yes I had basically done that though I hadn’t included the second line which I have now.
I was referring to setting up duckdns where it says to:

The final task for Raspbmc is to make the cron autostart on reboot for Raspbian you don't need to do this
first we simply manualy start the crontab

sudo service cron start

Then to automatically start cron on reboot, in Raspmbc you check the option in the Programs Raspbmc menu in XBMC"

I was wondering if there is anything I needed to set up to automatically run this on startup but I think probably it will run on startup as in Raspbian.
I have managed to get things to boot up cleanly now and without errors by changing to mosquito running locally. so that is good and my switch is now being seen by homeassistant but not yet functioning properly but i will sort that out hopefully.
Thanks again

Ah, now I see buried a few link-clicks away from there at the end of the DuckDNS instructions for a Pi. Must admit I haven’t actually yet followed those instructions myself :blush:

Yeah, I’d think that cron autostart setup only is something you have to do for a Raspbmc distribution with a XBMC user interface. Looks like pi and raspbmc share the same description. Checking it with sudo service cron status on my Rasbian based Pi cron seems to be already running.

Great to hear you’ve gotten thus far & good luck on the final bits!

Thanks again
And now I have a switch functioning so things are definitely looking up.
Thanks again you were a great help.

It should actually be contab -e as the pi user. No sudo. I’ve updated the steps.

1 Like