Sonoff issue

I seem to not be able to get my switch to work for mqtt and my sonoff basic switch. Here is my config and other information! Now i do have cloudmqtt for tracking but i have not changed anything for that area all i added was the switch to config.yaml. what could be the issue?

  - platform: mqtt
    name: "Fish Tank"
    command_topic: "cmnd/Tank/POWER"
    state_topic: "stat/Tank/POWER"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: true 
    
mqtt:
  broker: XXXXXXXXXXX
  port: XXXX
  username: XXXXXX
  password: XXXXXXXXX

Try:

command_topic: "cmnd/Tank/power"

Still nothing :frowning:

You need to connect a client to your broker to listen to all topics, to see what your Sonoff is sending (if anything). The topic they use seems to vary by release.

I use mosquitto_sub, but I here many people use MQTT.FX

mosquitto_sub -t "#" -v -u user -P password

Of course, that is assuming that HA is connecting to your broker.

I use MQTT Box on my PC, and MyMQTT app on my Android phone.

“Still nothing”? Be more descriptive of “nothing”. Are you unable to turn the switch on or off?

Here’s how you can test your Sonoff outside of Home Assistant:

From a browser, log on to Tasmota.
Click on Toggle to make sure the hardware is connected. The relay in the Sonoff should turn on and off.
If not, then you have a problem in the Sonoff. (I’ve never had one fail this test).

Click on Console
In “Enter command”, type fulltopic
Unless you changed something you should see:

{"FullTopic":"%prefix%/%topic%/"}

Now type prefix and note the result.

Again, unless you changed something, you should get:

{"Prefix1":"cmnd"}

Now type topic.
In my case, I get:

{"Topic":"light"}

So, the complete command topic for this light is:

cmnd/light/power

Then go to your favorite MQTT tool, and send the payload “on” or “off” to topic "cmnd/light/power

If the MQTT tool turns the Sonoff on and off, then your problem is not in the Sonoff.

Thanks for the reply’s
I am able to access Tasmota and login into the device, i can turn the switch ON and OFF through the devices ip address now when using the console i get what is shown in the picture below. When using that information to send a packet like in the picture nothing takes place. There is ON and OFF shown in the picture but that is just me turning it on manually by pushing the switches button. So basically home assistant is sending the packet but the switch is not seeing the packet, One thing to add is that the device is picked up by mqtt as shown in the first post and picture

Take the quotes off the on off

This is the updated code with out the quotes!

  • platform: mqtt
    name: “Fish Tank”
    command_topic: “cmnd/Tank/power”
    state_topic: “stat/Tank/POWER”
    qos: 1
    payload_on: ON
    payload_off: OFF
    retain: true

This still does nothing to turn on the switch

Looking at your first image:
the TOPIC is cmnd/Tank/power
the PAYLOAD is on or off

Change those then press “Publish”

command_topic is case sensitive. It should be “cmnd/Tank/POWER”
You should also put an availability topic : “tele/Tank/LWT”

Your .yaml entry should look like this:

  • platform: mqtt
    name: “Fish Tank”
    command_topic: “cmnd/Tank/POWER”
    availability_topic: “tele/Tank/LWT”
    state_topic: “stat/Tank/POWER”
    retain: “true”
    payload_available: “Online”
    payload_not_available: “Offline”
    payload_on: “ON”
    payload_off: “OFF”

Yes, it is, but in the Sonoff Tasmota, which the OP is apparently running, the cmnd topic is ‘power’ and the stat topic is ‘POWER’

For example:

  - platform: mqtt
    name: "Garden Light"
    command_topic: "cmnd/Garden/power"
    state_topic: "stat/Garden/POWER"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: true

I really like using Tasmota on my ESP nodes and I am slowly moving all of them to that firmware, but I am frustrated by the bizarre topic hierarchy that we’re stuck with. I know you can change the prefix and topic, but we’re still stuck with ‘power’ and ‘POWER’ for the cmnd and stat topics respectively.

1 Like

This is not the case with latest Tasmota Versions. I have my Sonoff Basics running with Tasmota 6.2.1 and I confirm that both cmnd and stat topics are upper-case POWER

1 Like

Well, we’re both right. I just tested a light next to my desk, and it works with either ‘power’ or ‘POWER’ as the publish topic.

sidetable/light/cmnd/power

is equivalent to:

sidetable/light/cmnd/POWER

They both work.

I am going crazy with this mqtt tasmota setup issue. I 'm on hassio v0.78 and recently restored a snapshot but now my mqtt switches stop working. It did work before so I’m confused.

How should the yaml look like? Anyone has a step by step instruction how to get this working again?

MQTT Host	192.168.1.xx
MQTT Port	1883
MQTT Client &
 Fallback Topic	DVES_E88A33
MQTT User	pi
MQTT Topic	sonoff-FAN
MQTT Group Topic	sonoffs
MQTT Full Topic	cmnd/sonoff-FAN/

Start a new thread and use the code blocks when posting code.

What would the payload be?
Is this correct?

cmnd/Tank/power
OFF

Topic: cmnd/Tank/power
Payload: OFF

You first need to do verify that you can control the switch with MQTT messages using an MQTT tool on your PC or cellphone. I don’t recognize the tool in your image, above.

What did you get from the console when you entered fulltopic, topic and prefix?

Which tools do you mean because the tools i use are the tasmota with the ip address of the switch and then home assistant with nothing else but the mqtt broker now i do use mqtt for tracking who is at home but that should not have an effect on the switch!
Here is what i get when i type in prefix, fulltopic, topic in tasmota console!!

The tools that gpbenton and I told you about five days ago.

I use MQTT Box on my PC, and MyMQTT app on my Android phone. There are many more, but these I like. gpbenton is using the Mosquitto command line tool on his Pi. I prefer an app that lets me publish and subscribe in the same program.

Your console responses confirm this:
Topic: cmnd/Tank/power
Payload: OFF
(or ON)