Tasmota and Hass.io. Can't make them to work together

Hello

I know this has been talked over and over again… but I can’t make it to work. Let me start from the beginning…

I have tow Sonoff switches flashed with Sonota. I run Mosquitto in the Pi through the plugin and it’s bridged with cloudmqtt for Owncloud. That part is working fine, as Owncloud is reporting the location correctly to HA. Anyway, here is that config:

{
  "plain": true,
  "ssl": false,
  "anonymous": false,
  "logins": [
    {
      "username": "Eduardo",
      "password": "********"
    }
  ],
  "customize": {
    "active": true,
    "folder": "mosquitto"
  },
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem"
}

And the cloudmqtt.conf on my share/mosquitto folder

connection cloudmqtt
address m--.cloudmqtt.com:17566
remote_username ********
remote_password ********
clientid ha
try_private false
start_type automatic
topic # in

Then, this is my configuration.yaml regarding the MQTT broker:

# MQTT
mqtt:
  broker: 172.26.0.112
  port: 1883
  username: !secret mosquitto_user
  password: !secret mosquitto_password
  protocol: 3.1

And in the same file right now (I haven’t created the switch.yaml yet), this is the switch part for the first Sonoff

  - platform: mqtt
    name: "Sonoff 01"
    state_topic: "stat/sonoff01/POWER"
    command_topic: "cmnd/sonoff01/POWER"
    availability_topic: "tele/sonoff01/LWT"
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    qos: 1
    retain: true 

sonoff01 is what I configured in the switch itself. And by the way, here is the full configuration for the first one.

It appears in States, but with status unavailable. And obviously, it doesn’t work when I try to call any service to that Entity ID.

I think that I have included everything. So… what am I doing wrong? I have tried so many things that, right now, I don’t really know what is right and what is wrong.

Thanks

You don’t appear to have ‘switch:’ before the - platform: mqtt?

Is 172.26.0.112 the LAN IP address of the PI? That seems the internal IP address of the docker image, it works for communication between HA and the plugins but not for other devices in the network.
You should try to put in the Sonoff configuration the LAN IP of the RPi, usually in form of 192.168.xxx.yyy .

Well, it’s before that, as I also have one TPLink switch I did not include in the copy/paste. But it’s there

yep, that’s my PI LAN address

Anything useful in the Console log of the Sonoff? There you should find if it managed to connect to MQTT broker or not.

As far as i know the cmnd the power must be lowercase.
“cmnd/sonoff01/power”

This is my config.

platform: mqtt
name: “Sonoff104”
state_topic: “stat/sonoff104/POWER”
command_topic: “cmnd/sonoff104/power”
payload_on: “ON”
payload_off: “OFF”
optimistic: false
qos: 0
retain: true

Ok, that is the first clue. It’s not connecting to the broker, I didn’t see that before

14:48:32 MQT: Attempting connection…
14:48:32 MQT: Connect failed to 172.26.0.112:1883, rc 5. Retry in 10 sec
14:48:33 UPP: Multicast (re)joined
14:48:43 MQT: Attempting connection…
14:48:43 MQT: Connect failed to 172.26.0.112:1883, rc 5. Retry in 10 sec
14:48:44 UPP: Multicast (re)joined
14:48:54 MQT: Attempting connection…
14:48:54 MQT: Connect failed to 172.26.0.112:1883, rc 5. Retry in 10 sec
14:48:55 UPP: Multicast (re)joined
14:49:05 MQT: Attempting connection…
14:49:05 MQT: Connect failed to 172.26.0.112:1883, rc 5. Retry in 10 sec
14:49:06 UPP: Multicast (re)joined

The username and password I have to enter in sonoff configuration are the same I use on the Mosquitto settings, right?

Can MQTT connection and Hue Bridge emulation be enabled at the same time? I have been able to operate it after enabling the emulation, but still not able to make it work as MQTT switch. Here is the Console log after a reset.

00:00:00 Project sonoff Sonoff01 (Topic sonoff01, Fallback sonoff01, GroupTopic sonoffs) Version 5.9.1
00:00:00 WIF: Connecting to AP1 Eduardo in mode 11N as sonoff01-7247...
00:00:04 WIF: Connected
00:00:04 DNS: Initialized
00:00:04 HTP: Web server active on sonoff01-7247.local with IP address 172.26.0.133
00:00:04 UPP: Multicast (re)joined
00:00:05 UPP: Multicast (re)joined
14:50:23 MQT: Attempting connection...
14:50:23 MQT: Connected
14:50:23 MQT: tele/sonoff01/LWT = Online (retained)
14:50:23 MQT: cmnd/sonoff01/POWER = 
14:50:23 MQT: tele/sonoff01/INFO1 = {"Module":"Sonoff Basic", "Version":"5.9.1", "FallbackTopic":"sonoff01", "GroupTopic":"sonoffs"}
14:50:23 MQT: tele/sonoff01/INFO2 = {"WebServerMode":"Admin", "Hostname":"sonoff01-7247", "IPAddress":"172.26.0.133"}
14:50:23 MQT: tele/sonoff01/INFO3 = {"RestartReason":"Software/System restart"}
14:50:23 UPP: Multicast (re)joined
14:50:24 MQT: stat/sonoff01/RESULT = {"POWER":"OFF"}
14:50:24 MQT: stat/sonoff01/POWER = OFF
14:50:31 MQT: tele/sonoff01/STATE = {"Time":"2018-02-06T14:50:31", "Uptime":0, "Vcc":3.161, "POWER":"OFF", "Wifi":{"AP":1, "SSId":"Eduardo", "RSSI":74, "APMac":"00:1A:2B:0F:AE:37"}}
14:50:49 MQT: stat/sonoff01/RESULT = {"POWER":"ON"}
14:50:49 MQT: stat/sonoff01/POWER = ON

So MQTT is connected and the topics I use should be working… but they are not.

I never used HueBridge so I can’t advice. From the last lines of the log it seems to be working:

14:50:24 MQT: stat/sonoff01/RESULT = {"POWER":"OFF"}
14:50:24 MQT: stat/sonoff01/POWER = OFF
...
14:50:49 MQT: stat/sonoff01/RESULT = {"POWER":"ON"}
14:50:49 MQT: stat/sonoff01/POWER = ON

If you still see it as “unavailable” try adding “payload available” and “payload not available” to your switch config:

  - platform: mqtt
    name: "Sonoff 01"
    state_topic: "stat/sonoff01/POWER"
    command_topic: "cmnd/sonoff01/POWER"
    availability_topic: "tele/sonoff01/LWT"
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    optimistic: false
    qos: 1
    retain: true

NOW it’s working! Thanks, everything appears correctly after adding payload available.

By the way, both the switch and the light with Hue Bridge are working, and both show the same info on the console.

Thanks!

You’re welcome :+1:
Please flag the message as “solution” so for other users it will be easier to find.