Sonoffs not all recognized in new HA install

Hi all,
First time poster and new to HA, so don’t be too cruel :slight_smile:

I just installed hassio (HassOS 2.11) on Pi 3B+ and find it very hard to get clear and accurate instructions for some items like MQTT.
I created a new file called /config/switch.yaml using the configurator add-on with details of two Sonoff devices with Tasmota 6.5.0, but only the first one is recognized and controllable.
The MQTT topic is the same on both( yes, I know about having unique topics), but I use the fallback topic in my configuration switch.yaml.
I can use MQTT pub message to control both switches manually using the fallback topics, but the second one in the config is not available in HA.

I tried using unique topics on the sonoffs, but there is still just one in HA.

- platform: mqtt 
  name: "Sonoff Switch R2 0669" 
  command_topic: "cmnd/sonoff1/power" 
  state_topic: "stat/sonoff1/POWER" 
  qos: 1 
  payload_on: "ON" 
  payload_off: "OFF" 
  retain: true
- platform: mqtt 
  name: "Sonoff Switch 2439" 
  command_topic: "cmnd/sonoff1/power" 
  state_topic: "stat/sonoff1/POWER" 
  qos: 1 
  payload_on: "ON" 
  payload_off: "OFF" 
  retain: true

Any ideas what to check? This is really frustrating.

Thanks

I’ll be gentle. If you ‘know’ about it, DON’T DO IT. They have to be unique.

Thanks Mate, did you see my last few lines where I used unique topics and it still didn’t work?
My fallback topics are all unique.

Using the built-in mosquitto broker, what does my configuration.yaml need to contain?
I use the mosquitto add-on config section only to setup MQTT

Any reason you don’t use MQTT discovery?

It’s hard to know what the issue is as you’ve posted a config that won’t work and no screenshot of MQTT in the sonoff settings. (Tasmota MQTT settings)

I have option 19 set to 1 on both sonoffs. Anything I need to do in HA?
Do you think the config I posted is not going to work? Why so?

this is the second sonoff. The topic on the first has a topic of “sonoff1”.

So the topic will be sonoff2/cmnd etc… but if using discovery you don’t need manual config anyway.

Hey, welcome :slight_smile:
I know the struggle, dont worry, we ll figure it out.

First off, is there a line switch: !include switch.yaml in your configuration.yaml or something similar?

Second, In order to improve your current and future troubleshooting, i would start by installing on hassio one of those:

  1. A Mosquitto add-on (there’s two, one just server, one with client) so you can see what is going on on your mqtt server. Unless you have ssh access to check things and you are comfortable with that (I’m not)
  2. Tasmoadmin to see what your sonoffs are up to.

Both are available in the add-on store.

Hi, Thanks for the help so far.

I added switch: !include switch.yaml to my configuration.yaml file and have my two sonoffs in there:

- platform: mqtt 
  name: "Sonoff Switch R2 0669" 
  command_topic: "cmnd/sonoff1/power" 
  state_topic: "stat/sonoff1/POWER" 
  qos: 1 
  payload_on: "ON" 
  payload_off: "OFF" 
  retain: true
- platform: mqtt 
  name: "Sonoff Switch 2439" 
  command_topic: "cmnd/sonoff2/power" 
  state_topic: "stat/sonoff2/POWER" 
  qos: 1 
  payload_on: "ON" 
  payload_off: "OFF" 
  retain: true

I already had the Add-On Mosquitto MQTT broker installed and don’t have any mqtt settings in my configuration.yaml file, what should it contain? The add-on has its own configuration section.

I see you still have not corrected the topic. If you enabled Option 19 (discovery) your topics are wrong.

If you check the device names on the configure>configure other page


Make sure they are unique.

Then also as I said before, if you use MQTT Discovery, don’t manually configure the switches anyway.

Then check switch.-name- like here:
image

and they should be listed.

Also, your retain: true has already screwed up the connection behaviour (when the switch reconnects to WiFi after losing connection) so when you get them working I can tell you how to fix that as well…

One other thing, you’ll benefit by installing MQTT explorer…

Hi ,
I have updated the topic and have not posted an updated screenshot, sorry.
How would my entity names “switch.xxx” relate to my config above? Is the xxx supposed to match the topic name or the “name” field?

If you use MQTT Discovery, the switches will be automatically created with the MQTT Integration. They will be called switch.whatever-the-config-name-is by default… (see my screengrabs) You don’t need to manually configure the switches if you use MQTT discovery. (SetOption 19 On turns on MQTT Discovery)

(Note it does drop the ‘-’ from the friendly name)

I removed my manual config for the switches and my mqtt config in configuration.yaml looks like this:

mqtt:
  broker: core-mosquitto
  username: !secret mqtt_user
  password: !secret mqtt_password
  discovery: true
  discovery_prefix: homeassistant

HA now discovered my Sonoffs and I can see the correct status of both.
One of them is a Sonoff POW R2 and I see the readings for it as well.

My next step is to try and add some ESP32 (running Micropython) with temperature and humidity readings as well.
Any suggestions, I suppose they will need to be added manually?

Thanks for the help so far. It helped a lot.
BTW: I don’t see the MQTT explorer add-on. Do I need another repository?

MQTT Explorer is a stand alone program that makes it easy to see what is happening with MQTT. It will also fix the retained messages issue you will eventually discover.

I don’t even have a mqtt section AT ALL in config - that is not needed if the broker is on the same machine as HA.

Thanks Mate