Sonoff tasmota problem

Hello, I’m trying to setup my first sonoff switch (flashed with Tasmota) but I have a problem, it doesn’t work and on the frontend it appears this warning message: “The following components and platforms could not be set up: - mqtt - switch.mqtt. Please check your config”. Could anyone help me please?

I don’t know if it’s important, I’m using a DDNS with Let’s Encrypt. HA (on hassbian) version 0.63.2. Configuration.yaml has no errors.

My sonoff settings are:

Host: 192.168.0.113 (HA ip)
Port: 1883
Client: home-assistant-1 (is it correct?)
Username: homeassistant (is it correct?)
Password: *** (web password)
Topic: sonoff_os
Full topic: %prefix%/%topic%/

My configuration.yaml is:

mqtt:
broker: 192.168.0.113
port: 1883
client_id: home-assistant-1
username: homeassistant
password: *** (HA web psw)
protocol: 3.1

switch:

  • platform: mqtt
    name: “Open Space”
    state_topic: “stat/sonoff_os/POWER”
    command_topic: “cmdn/sonoff_os/POWER”
    availability_topic: “tele/sonoff/LWT”
    qos: 1
    payload_on: “ON”
    payload_off: “OFF”
    payload_available: “Online”
    payload_not_available: “Offline”
    retain: true

The error log is this:

2018-02-20 15:48:33 ERROR (MainThread) [homeassistant.setup] Error during setup of component mqtt
    Traceback (most recent call last):
      File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/setup.py", line 145, in _async_setup_component
        result = yield from component.async_setup(hass, processed_config)
      File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 399, in async_setup
        success = yield from hass.data[DATA_MQTT].async_connect()
      File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/mqtt/__init__.py", line 506, in async_connect
        self._mqttc.connect, self.broker, self.port, self.keepalive)
      File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
        yield self  # This tells Task to wait for completion.
      File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
        future.result()
      File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
        raise self._exception
      File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
        result = self.fn(*self.args, **self.kwargs)
      File "/srv/homeassistant/lib/python3.5/site-packages/paho/mqtt/client.py", line 768, in connect
        return self.reconnect()
      File "/srv/homeassistant/lib/python3.5/site-packages/paho/mqtt/client.py", line 895, in reconnect
     sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
  File "/usr/lib/python3.5/socket.py", line 712, in create_connection
    raise err
  File "/usr/lib/python3.5/socket.py", line 703, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
2018-02-20 15:48:34 ERROR (MainThread) [homeassistant.setup] Unable to setup dependencies of switch.mqtt. Setup failed for dependencies: mqtt
2018-02-20 15:48:34 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform switch.mqtt: Could not setup all dipendencies

Anyone could help me please? Thank you very much!

The password for the MQTT server on the Tasmota must be the same as in your cofiguration.yaml mqtt definitions.

A quick glace makes me say that hass cannot connect to your mqtt server. Can you connect to it with your command-line tool to verify username, password?

Yeah, it’s the same :wink:

I think my next question will be very very st*pid, sorry for this: isn’t HA my mqtt server? :face_with_raised_eyebrow:
How to verify it? Sorry, I’m a noob

If in config you write only

mqtt:

HA will start a very simple MQTT server. If you provide an IP address, password etc., HA will not start the embedded server but try to connect to the one specified.

My advice is to setup a Mosquitto server on hassbian, some features of the embedded one are a bit rough.

@bruhautomation has a video on setting up a MQTT server. I found it easy to follow and his test at the end helped my understanding of how MQTT messages are posted and how devices/HA subscribe to topics to monitor for state changes.

https://m.youtube.com/watch?t=&v=AsDHEDbyLfg

I’ve done all like in the youtube video, something goes better now (no more warning cards) but it still doesn’t work.

With the settings I wrote in the first post, in HA the switch is “unavailable” and from sonoff console I see a loop with:

23:34:09 MQT: tele/sonoff_os/LWT = Online (saved)
23:34:09 MQT: cmnd/sonoff_os/POWER =
23:34:10 MQT: Trying to connect…
23:34:10 MQT: Connected

And it go back to tele/sonoff_os/LWT = Online etc…

If I try to use only “mqtt:” without settings in configuration.yaml, I see an error in the HA frontend but the Sonoff console write:

23:35:10 MQT: tele/sonoff_os/STATE = {“Time”:“2018-02-20T23:35:10”,“Uptime”:0,“Vcc”:3.173,“POWER”:“OFF”,“Wifi”:{“AP”:1,“SSId”:“myssid”,“RSSI”:76,“APMac”:“99:99:BF:F5:2F:4F”}}
23:40:14 MQT: tele/sonoff_os/STATE = {“Time”:“2018-02-20T23:40:14”,“Uptime”:0,“Vcc”:3.173,“POWER”:“OFF”,“Wifi”:{“AP”:1,“SSId”:“myssid”,“RSSI”:76,“APMac”:“99:99:BF:F5:2F:4F”}}

Any ideas? Thanks!

Can you post your sonff and HA configuration again in full? They both need to be pointing to the same broker and it would be good to check your settings.

if the switch settings are the same it looks like the availability topic should be updated from “availability_topic: “tele/sonoff/LWT”” to "availability_topic: “tele/sonoff_os/LWT”

Yeah, they’re here!

Mosquitto setted as in this video: https://www.youtube.com/watch?t=&v=AsDHEDbyLfg&app=desktop with username homeassistant and password (not really this) pwexample

Sonoff:

Host: 192.168.0.113
Port: 1883
Client: home-assistant-1
User: homeassistant
Pw: pwexample
Topic: sonoff_os
Full topic: %prefix%/%topic%/

HA configuration.yaml:

mqtt:
broker: 192.168.0.113
port: 1883
client_id: home-assistant-1
keepalive: 60
username: homeassistant
password: pwexample
protocol: 3.1
birth_message:
topic: “tele/hass1/LWT”
payload: “Online”
qos: 1
retain: true
will_message:
topic: “tele/hass1/LWT”
payload: “Offline”
qos: 1
retain: true

switch:

  • platform: mqtt
    name: “Open Space”
    state_topic: “stat/sonoff_os/POWER”
    command_topic: “cmnd/sonoff_os/POWER”
    availability_topic: “tele/sonoff/LWT”
    qos: 1
    payload_on: “ON”
    payload_off: “OFF”
    payload_available: “Online”
    payload_not_available: “Offline”
    retain: true

I’ve two doubts (client_id and mqtt topic, where there was setted? I done a copy-paste from tasmota) but I tried other values without success.

Thank you silvrr!!

Create separate client IDs for each device. Doesn’t really matter what they are as long as they are unique.

Your topic is listed as sonoff_os and sonoff. This should all be the same for the sonoff setup and the HA switch setup.

See my previous post about updating the availability topic.

You’re right!! All solved with these 2 tips!
Thank you very much!!

Glad to hear it. The client ID being different and the missing the availability topic tripped me up in the past to.