Issue - MQTT, Sonoff switch -> manual integration

Hi,
I am new to Home Assistant and I need some help.
This is the situation:

  • installed Home Assistant on a Raspberry PI4.
  • installed MQTT Mosquitto and configured
  • Flashed Sonnof swithch with tasmota and configured the MQTT
  • Adapt the configuration.yaml

If I set up in sonoff console ‘SetOption19 1’ the device is properly discovered and displayed in HA overview.
If I set up in sonoff console ‘SetOption19 0’ the device is not available anymore.
Setting the switch manually does not work.
Could anybody please help me in this matter?

My configuration.yaml

mqtt:
  broker: core-mosquitto
  username: user
  password: pass
  discovery: true

switch:
  - platform: mqtt
    name: "Plug"
    command_topic: "cmnd/Plug1/power"
    state_topic: "stat/Plug1/power"
    availability_topic: "tele/Plug1/LWT"
    payload_on: "ON"
    payload_off: "OFF"
    qos: 0
    retain: true

The sonoff configuration
image

the MQTT config

logins:
  - username: user
    password: pass
anonymous: false
customize:
  active: false
  folder: mosquitto
certfile: fullchain.pem
keyfile: privkey.pem
require_certificate: false

For starters ther is a gotcha with Tasmota - state and command topics are different case. i.e:

  - platform: mqtt
    name: "Bar Room Light"
    command_topic: "cmnd/tasmota2/power"
    state_topic: "stat/tasmota2/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    retain: true

Thanks!
I’ve changed the state topic to:
state_topic: “stat/Plug1/POWER”

But still not working. :frowning:

These are the templates I use for manual adds.

I use manually configured MQTT for the majority of my devices, and nothing in your config jumps out as wrong…

Thank you!
I found already an issue based on your video.
Switching on/off SetOption9 0 and 1 changes the topic/prefix order in the tasmota device. I corrected that one but still not ok yet.
Do I have to add

  broker: core-mosquitto
  username: user
  password: pass
  discovery: true

Or is completely useless?

I just use the integration section in HA and let it add the MQTT broker stuff to connect HA to the Broker.

I removed the piece of code in config about the mqtt broker and applied your template. Now everything works very well. Thank you very much!