Adding Multiple Sonoff to MQTT after flashing with Tasmota

I know others have posted this question but I have read the docs, watched the vids and cannot see my problem, please be gentle with me.
I have two sonoff basic ( more to come) I have flashed them with Tasmota, all good. I can control them by browsing to them.
I have Hassio configured with Mosquitto and can control them individually but only with one in the configuration.yaml file when I add the second, I lose the other, It seems to be the first in the list.

This is my conf

mqtt:
broker: 192.168.0.250
username: myusername ----it same as in sonoff basic config
password: mypassword-----it same as in sonoff basic config

switch:

  • platform: mqtt
    mqtt_name: “Lounge”
    command_topic: “cmnd/sonoffDEV1/power”
    state_topic: “stat/sonoffDEV1/POWER”
    qos: 1
    payload_on: “ON”
    payload_off: “OFF”
    retain: true
  • platform: mqtt
    mqtt_name: “Bedroom”
    command_topic: “cmnd/sonoffDEV2/power”
    state_topic: “stat/sonoffDEV2/POWER”
    qos: 1
    payload_on: “ON”
    payload_off: “OFF”
    retain: true

Please help with good suggestions not just to “read the manual” as I have and I cannot see where I am going wrong
Thanks

Personally I use the autodiscovery function on tasmota. But I mainly do this because sometimes after updating the firmware it will change the topic name with a “_1” at the end which makes the manual config unusable whenever I update.

To setup auto discovery on your sonoff you need to go to the sonoff webinterface>console and type:

SetOption19 on

This will enable home assistant auto discovery and you won’t need to restart HA to find it. This is the easiest way to set it up and the most failsafe. If you prefer it manually you will need to change your config.

Use:
- platform: mqtt

Instead of the dot. And if you do not have a username/pass on your mqtt broker don’t put it in anywhere (do not copy the username/pass from the sonoffs as they do nothing unless you have actually setup a username/pass on your mqtt broker. Next question, did you set up a mqtt broker? If not you will have to do this first.

2 Likes

@keithewilson, something to check…
From memory (so I might be wrong!!) I think Tasmota sets the same MQTT client ID in each unit you flash. However, it’s important that each unit has a unique client id, so you may need to change at least one to get it to work. (Ignore if you’ve already done this!)
HTH
Andrew

Thanks Andrew I did change the client ids

I am new to this but i do think that I have set the broker. I must have if I can control one switch that appears in the Overview screen. I can go into Hassio and see the state of two switches and control the on and off but not from the Overview screen which is where I expect to see multiple entries under switch

No it doesn’t.

Why don’t you try using the MQTT integration and MQTT Discovery?

Remove all MQTT stuff from config yaml including mqtt section and switch configurations.

Remove the MQTT Integration if you have one
Remove the broker

Restart Home Assistant.
Add the broker back. I created a HOme Assistant User with the broker logonn username and password - then you don’t need to define a user in the broker.
Add the MQTT integration

Restart Home Assistant

SetOption19 On in the console of all your devices. They will then automatically pop up in home assistant.

David. Thanks for the reply but I cannot see what I have done that is different to what you suggest.

Do you have a conf example that you could send or refer to as well as what the sonoff conf should look like?

That’s the point… there IS no config if you use discovery…

It might be worth checking the Full Topic is the correct way round in your MQTT settings on the Sonoff as per my mention in this thread.

I have had a few switches the wrong way round, while moving firmware versions.