Sonoff/ESPEasy/HA but MQTT Noob - please help!

Hi,

Let me introduce myself, I’m Alex and I am really into home automation but have hit a stumbling block.

I am trying to set up some Sonoff S20’s with Home Assistant but I am COMPLETELY stumped by quite how MQTT works. I posted to the letscontrolit website but the help I got was limited due to the responders lack of understanding HA.

I have flashed the Sonoff’s with ESP Easy Mega and believe me have searched high and low for help on this forum and elsewhere to no avail.

I don’t think I am understanding “topics” very well.

I am trying to use the built in MQTT server in Home Assistant which seems to be fine.

Quite simply I would be very, very grateful if someone with the knowledge could just put in layman’s terms where I’ve gone wrong, what does and doesn’t need to be there. Whether this will work at-all:

I put all the screenshots in here for the website to tell me new users can only put in one image :frowning:
So I have linked to the original post I put on letscontolit which contains the screenshots!

_Sonoff/ESPEasy/MQTT/HA Noob - please help! - Let's Control It
Here you will find:

Configuration file in Home Assistant
ESP Easy Mega config screen
ESP Easy Mega controller screen
ESP Easy Mega devices screen
ESP Easy Mega rules screen
An image of my Home Assistant states

Pressing the “MQTT Switch” switch does nothing - and the switch goes back to “off” within a second (and all other NON-MQTT related accessories work)

If I navigate to the following in a web browser:

http:// 192.168.0.69/control?cmd=GPIO,12,0 - the switch DOES turn off

or

http:// 192.168.0.69/control?cmd=GPIO,12,1 - the switch DOES turn on

All help will be very well received, I’m sure you guys will be able to tell me exactly where I am going wrong! :frowning:

I must stress please be kind and put things in plain English because this is one thing that is really stumping me and as I say I am a complete noob!

If my ESP Easy settings look OK then please could anyone please tell me exactly what needs to be in the fields below in my configuration.yaml file? I know I’m very close but I just don’t know quite where I’m going wrong!

switch:
- platform: mqtt
mqtt_name: “???
state_topic: “???
command_topic: “???
qos: 0
payload_on: “???
payload_off: “???
optimistic:
retain: true

Thank you so much in advance,

Regards,

Alex

I think you were nearly right the first time…

switch:
       - platform: mqtt
         mqtt_name: "SleeperLights"
         state_topic: "/sleeperlights/status"
         command_topic: "/sleeperlights/cmd"
         qos: 0
         payload_on: "GPIO,12,1"
         payload_off: "GPIO,12,0"
         optimistic:
         retain: true

except that the topics should be…

         state_topic: "/SleeperLights/Sonoff"
         command_topic: "/SleeperLights/Sonoff"

and payload should be…

         payload_on: "PowerOn"
         payload_off: "PowerOff"

I don’t use ESP Easy but that looks about right to me. You basically need to know what sysname and taskname is and use that exactly as you have set it up in the ESP Easy code. If you use a mqtt subscription program you can snoop on the topics by subscribing to /# and using the ESP Easy web i/f to flip the switch and see what comes out maybe?

Hi mate,

Thanks for the advice.

Unfortunately nothing happens still when I changed my configuration.yaml as you suggested :frowning:

I am so stumped. Any other ideas?

Regards,

Alex

Hi,

I use some ESP8266 with EspEasy firmware and the system works very good with MQTT and its very stable.

Tomorrow i try send you a example of my config and my config in a EspEasy…

Antoni.

Thank you, that would be very appreciated!

I am using ESP Easy Mega, is that ok? Also is the built in HA MQTT server good?

Just trying to figure out where I’m falling down.

Alex

Hi,

I use the same thing exactly!

Antoni.

Cool! I look forward to the files :slight_smile:

Thank you!!!

@alex101087

Here is my working MQTT config using the integrated Hass broker.

# switch 2:
- platform: mqtt
  name: "Sonoff1"
  state_topic: "/sonoff1/relay/state"
  command_topic: "/sonoff1/gpio/12"
  payload_on: "1"
  payload_off: "0"
  qos: 1
  retain: true
  
# switch 3:
- platform: mqtt
  name: "Sonoff2"
  state_topic: "/sonoff2/relay/state"
  command_topic: "/sonoff2/gpio/12"
  payload_on: "1"
  payload_off: "0"
  qos: 1
  retain: true
  
# switch 4:
- platform: mqtt
  name: "Sonoff3"
  state_topic: "/sonoff3/relay/state"
  command_topic: "/sonoff3/gpio/12"
  payload_on: "1"
  payload_off: "0"
  qos: 1
  retain: true
1 Like

Hi Alex,

What @xbmcnut says is correct, he use my example…

Antoni.

Hi,

I just wanted to say thanks for your help guys.

I got it working - seems I was getting my topics/payloads completely wrong! After checking these properly it now works seemlessly and has done for a few months.

Thanks again, and take care :smiley:

Alex

Hi,

I have same problem, the solution was:

add to configuration.yaml:
 state_on: 1
 state_off: 0

Peter