Mqtt what am I missing?

flamingm, by “switch” do you mean the tasmota board itself? I am very new so the lingo still confuses me a bit. I have different tasmotas set up. The CuartoVale at one point did work with mqtt via HA. I haven’t made ANY changes to that set up since, so I can only assume that set up is correct.

I have about 5 tasmotas. If I go to their console, then reboot the raspberry pi. I can see how it disconnects, LEDs start blinking, every 10 seconds it retries, and eventually I get a connected message to 10.0.0.227. To test at one point I changed the pw stored on the tasmota for mqtt user and I could see how it gets rejected.

David thank you for your support. Thanks to your advice I am now verifying code first, then restarting HA from the configuration restart option. Before I was doing a full system reboot via hass.io system reboot. Which not only gave me lots of boot ups with no web ui (hence so many fresh installs), but also took MUCH longer to restart.

I am running a hassio install on a rbp pi. I am using the built in mosquito add on (not the native mqtt which might have been taken out by now, but did read on of the literature). I took your advice, took the mqtt section out of the yaml and did the integration via config/integrations. Restarted HA and I could again see the Luz Cuarto Vale slider. But if I slide to turn on the light, stays there for a couple of seconds then slides back.

As for the HA user for MQTT not sure I follow you here. Is the advantage of doing it that way is not to have the user name and password visible in the add on config file or there is more to it? Do the tasmotas then log in using that HA user credentials?

I am trying to get over this hump as I am now panicking a bit. I have to have this done by Jan 4th the very latest, cause it is my gfs surprise xmas present, and she comes back on the 5th. Once I have everything “working” I do plan to follow good instructions on how to back up often, how to use the ssh, how to use the secrets file, etc.

I also followed your instructions for the switch part. Took out the switch section of the code, and did setoption12 1 on tasmota… now I have no idea what you mean about being able to see “switch.xxxxx in the entitites”. I have been scanning in both the tasmota options and the HA menus, and I can’t seem to find anything that reads entities

Ok, about to go look up what setoption12 does, but that didn’t do the trick. SetOpton19 turn auto discovery on, and that did the trick!.. so in order to keep on learning I did look up setoption12 which is Show current configuration flash usage option… do I need that enabled? Or did you mean to say option 19?

Yeah sorry option19

No. You keep getting told it’s LITERALLY the switch lines in your freaking configuration yaml.

You’ve been given exact instructions on how to fix it and you keep ignoring the documentation you’ve been provided.

If you want help you need to put forth a little effort.

flaming so do you ever offer real advice or do you just troll? Who in this thread told me the issue was with my switches set up on the yaml file? Or who pointed out what was wrong with it?

what is wrong with this entry?

    switch:
      platform: mqtt
      name: “Luz Cuarto Vale”
      command_topic: “cmnd/CuartoVale/power”
      state_topic: “stat/CuartoVale/POWER”
      qos: 1
      payload_on: “ON”
      payload_off: “OFF”
      retain: true

assuming I only have one switch set up as I had at that time?

I do appreciate all the time and effort folks put in to help me and others like me that don’t know as much. When you make statements like “if you want help you need to put forth a little effort” I do take it personal. David did offer me some great advice but he shared the wrong setoption. I took it upon myself to continue researching what he had suggested and figured out I had to turn setoption19 on not 12 as I was instructed. In my book that is putting effort forward.

I actually also pointed out what you were missing in the manual config!

If you setoption19 on then it should show up as a switch with no config anyway.

Thanks David. Yes doing it the way you suggested worked. Auto discovery, with nothing on my yaml file.

switch:
  - platform: mqtt

I was under the impression that the minus sign was only needed if I listed more than one switch. I had been following this Dr Zzs Video and he didn’t use the minus sign. And yesterday at one point I had one switch working with the code without the minus sign.

I am noticing that things change rather quickly and some videos that seem updated are not as updated.

I now posted a new mqqt question, since now I can’t seem to get the rules to work

If you look at the link to the docs I posted it shows the ‘-‘ for just one switch. You might be correct and it’s not needed. If you use discovery none of it is needed anyway.

You’ve been given advice in this very thread. I’m not here trolling.

David did. Read.

Tom did. Read.

I did. Read.

Fritske even gave you an example of exactly what it should look like if you were to use the method you were using.

It’s been mentioned numerous times in this thread. You’ve been given exact instructions on what will fix it and you’ve ignored all of that. I even provided a link to the documentation that explains HOW you add devices, yet ignored again.

1 Like

Ok not to beat a dead horse, but I seem to still have the same issues.

David was kind enough to teach me an alternative method to get my mqtt set up. If I do follow Davids instructions I am able to integrate the mqtt then auto discover devices, all without using the yaml file. But I can’t seem to get rules to work on the tasmota.

So I went ahead and undid the mqtt integreation. I assume my mosquito add on config is working fine.

So on my config.yaml I added:

mqtt:
  broker: 10.0.0.227
  username: mqttuser
  password: mqttUserPW
  
switch:
  - platform: mqtt
    name: "Luz Cuarto Miriam"
    command_topic: "cmnd/CuartoMiriam/power"
    state_topic: "stat/CuartoMiriam/POWER"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: true

When I reboot, I do see the new switch “Luz cuarto Miriami” listed, but when I slide the bar to turn on, after a couple of seconds it just slides right back.

Flaming has been riding me a bit hard, but before trying Davids suggestion I kept trying different code set ups (including minus sign ) with no results. I just didn’t keep reposting all my different attempts on this board.

Can anyone see what is wrong with the last code I shared? This time I am posting with the minus sign - before platform. Minus under the i, p under the c, just as in the examples given.

I did try changing 10.0.0.227 with core-mosquitto and got same results.

I wasn’t riding you hard but you literally ignored the recommendation and didn’t ever state that you had done it properly. All we had to work off of was an obvious bad config, and you weren’t assisting in that.

You don’t have a problem with your MQTT so stop thinking it’s an issue with mqtt broker.

If you’re using hassio, I would recommend using the core-mosquitto instead of an IP address. Is that the IP address of your hassio machine?

Check your device. What are it’s settings? Are you sure each device has a different client ID? If more than one device/client shares the same ID it will crash MQTT.

Stop making mqtt broker changes. MQTT is super simple and doesn’t really require any fiddling.

Hi flaming, I get your point. I never did come back and mentioned I was still having problems after following the suggestions of using the minus sign.

Yes, 10.0.0.227 is the ip of the raspberry pi with hassio and the mosquito broker add on. I have tried with both core-mosquito and straight IP with same results. Will follow your advice and use core-mosquitto.

Yes, the 3 tasmotas I am working with are CuartoVale, CuartoMiriam, and SwithMiriam. Well that is actually the Topic. On the tasmota on the mqtt parameters screen I do see a Client (DVES_553B4343) and underneat DVES_%06X. I am guessing the %06X is a variable for the Mac address so ends up with a unique Client ID. All the videos I’ve seen leave that part as is, and only change the Topic.

For what it is worth, if i do the mqtt integration method and set auto discovery on I am able to pickup all 3 devices with their unique names. Which leads me to believe the set up on the tasmotas is fine.

If that is the case, you need to fix your switch config to use the appropriate topics.

MQTT discovery in HA relies on specific formatting of the topics, and if discovery works, then the devices are using the topics that discovery expects

Look at the examples, and then compare them to the topics you have defined in your config. They are different. You need the same exact topics as what your devices are using.

I don’t use Tasmota/ESPHomelib/or any other preconfigured firmware for all my ESP8266/ESP32 devices, but whatever the config from your devices is sending out in the discovery phase will have your topics in them.

If I add discovery to my yaml file, it finds my devices just fine

```
mqtt:
  discovery: true
  discovery_prefix: homeassistant
```

both using the discovery prefix, and without. I guess that was to be expected, since we already know that if I use the mqtt integration process instead it does work.

Honestly I couldn’t make much sense of the switch topics. However all of the different videos that I saw on how to set up tasmotas they all cover the same thing. “Remember” what we used in the “topic” in the mqtt parameters screen, and that it has to be unique. Then on the config.yaml most use the same code (without the minus sign), and ask us just to change the info between stat and power to match the topic used on the tasmota.

Is there any chance I have what seems to be a good install but somehow it is corrupt? Before I learned how to properly check and then restart HA I ended up reflashing and starting from scratch. A few times I got it up and running following DrZzs video step by step. I was able to get one switch to work at a time, but I couldn’t get both to work. I would change the topic to match one switch, it would work. I would then change the topic of the switch on the yaml file, reboot, and it would control the new switch.

At that point the issue I had was not being able to list more than one switch, which is when I started this thread. During this timet I was also able to use the rules on tasmota, one could talk to the other but not vice versa. When trying to do the first suggestion that tom offered, I messed something up on the yaml file, and when I rebooted I didn’t have a web ui.

I know it is a very bad idea just to pull the power from the rsbpi, but that is what I kept doing every time I couldn’t get into the web ui. Well since then I did about 3 or 4 fresh installs following the same video instructions, and I just can’t seem to get the switch to work.

I tried to delete all the partitions on the SD using Gparted, there are about 8 of them. I was able to delete some, but 3 or 4 of them I couldn’t figure out how to keep unmounted.

Since I know the instructions on the video work, I am thinking that the only thing that could make sense is that I am not starting with a truly fresh install as I think, and something from a previous install is what is creating the issue.

As expected because the devices are sending the config over to HA. Please, once again, look at the documentation I have linked you to. It explains how discovery works and what is required. Tasmota has this built in. Look at the config.

Doesn’t matter. The default discovery (per the documentation I linked you to) is ‘homeassistant’. It’s the default which means if you don’t specify that, it’s what is used.

No. Stop thinking Home Assistant or MQTT is broken. It’s not. I don’t know how many times we can say this.

Which has been explained. Numerous times. It’s simply the way you formatted and wrote the config.

This is not even remotely possible. When you flash hassio to the sdcard you are literally wiping any remnants of anything that was on the card. Again, stop reflashing the sdcard, stop rebooting, stop breaking shit.

I can’t be any clearer.

Look at the config of your tasmota switches. On tasmota firmware NOT home assistant.

Use the topics that are configured ON THE SWITCH.

Or just use discovery! It works. I have all my ESP sensors using discovery now and it works wonderfully fine.

1 Like

flaming, again thank you.

Having a corrupt install was a long shot, but then the other only explanation would be that I am losing my mind.

I am pretty confident HA nor tasmota has made any major changes in the last 72 hours. So now sure how to explain that following the video with the same code worked a few times on some of my recent installs, but now they don’t. It must be that I am not following the video instructions to the T, but last couple of times I did it slow paying very good attention.

Since David tough me how to properly restart system I haven’t reflashed anything. I just integrate the mqtt, then delete the integration, play with the yaml config,

On the installs I did some I got the lets encrypt to work, then i figured I didn’t really need it now. I can’t remember if the few times I did had it working if I had lets encrypt on or no t, but again pretty sure that wouldn’t really have anything to do with it.

@CancunManny You are making this far more difficult than it needs to be. As you have been told on many occasions, the issue is with you switch configuration. See some of my Sonoff switch config below.

You will notice that each of the switches has it’s own command_topic and state_topic which relates to the name of the switch (that you have given it when setting it up). The naming needs to be IDENTICAL.

Stop wiping, formatting, re-installing, etc. Your code and naming of the Sonoffs appear to be the issue. Please follow the directions that you have been given, use discovery if need be.

Follow the docs.

- platform: mqtt
  name: "Sonoff_1"
  command_topic: "cmnd/sonoff_1/power"
  state_topic: "stat/sonoff_1/POWER"
  availability_topic: "tele/sonoff_1/LWT"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_not_available: "Offline"
  retain: true

- platform: mqtt
  name: "Sonoff_pow_1"
  command_topic: "cmnd/sonoff_pow_1/power"
  state_topic: "stat/sonoff_pow_1/POWER"
  availability_topic: "tele/sonoff_pow_1/LWT"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_not_available: "Offline"
  retain: true

- platform: mqtt
  name: "Sonoff_pow_2"
  command_topic: "cmnd/sonoff_pow_2/power"
  state_topic: "stat/sonoff_pow_2/POWER"
  availability_topic: "tele/sonoff_pow_2/LWT"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  payload_available: "Online"
  payload_not_available: "Offline"
  retain: true

Sonoff_2

Look… you are lurching back and forth here and probably within a whisker of getting it right before you suddenly change tack and end up back at square 1 again!

I suggest you use MQTT Discovery.

Here is my mqtt section in my configuration.yaml:

# Mqtt Config

Get that… ABSOLUTELY NOTHING, NADA, BLANK ZIP.

Here are my MQTT Switches:

# Mqtt Switches

YEP! your catching on. NOTHING

Here is my MQTT Broker config - the Hass.io core broker from the core addon repo:

{
  "logins": [],
  "anonymous": false,
  "customize": {
    "active": false,
    "folder": "mosquitto"
  },
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem"
}

that is standard with NOTHING added. Now this means that I do not have a local MQTT user defined at all!! I ADDED a Home Assistant User with the same username and password I used in my MQTT in Tasmota.

Here is my integration for MQTT in Home Assistant Configuration->Integrations->MQTT


My devices are called sonoff1-2914 etc.

If I go to the dev panel in HA:
image
I filtered by switch.sonoff because all my switches START with sonoff in the name… You would use whatever the switches are called.
If you open up the web interface of the Sonoff, go to the console and SetOption19 On and SetOption19 Off you will right before your eyes in the HA dev console see the switch appear and disappear in front of yur eyes as you enable/disable Discovery on the switch.

Note that when you enable discovery, ALL the switch config is done in Tasmota!!!

The name the switch gets is the name you configure in tasmota:

Here is the MQTT Config:

Once the switches show, you can use customization in HA to rename them…

I also use some automations in Home Assistant to do a few things… If you can get the above working and not get distracted in side configs we can discuss these later…

Ok I figured it out and it was thanks to Kanga’s post. The issue was with my tasmotas. None of the instruction videos mentioned changing the full topic, they just leave the default. I never changed them.

Well by looking at Kangas pictures I noticed my prefix and topic were backwards. Changed that, then checked the other two, and same thing all of them were swapped.

Then, it all started to work using the config.yaml mqtt set up. I then started working on the rules, and quickly got them to work as I want for my 3 way switch.

Then I figured why not try with the mqtt integration. Deleted mqtt and switches from yaml. Setoption19 on tasmotas back to 1.

Got all the switches to work again, but not my 3 way switch. When I went back to tasmota i noticed that again the prefix and topic were backwards. Not exactly sure what triggers that, my guess when toggle option19.

I changed them back to the correct way, and on the HA console it worked fine, but couldn’t get my 3 way switch to work.

So then I set CuartoMiram and MiriamSwitch back to setoption19 0, and added them on the yaml file instead. Again had to switch the order of the full topic. Now I finally got it to work!!!

I just checked the 3rd tasmota that I have that mqtt sets up automatically. It is working just fine, and in tasmota topci and prefix are backwards.

To sum it up, the main issue was the tasmota changing the full topic by itself.

I am pretty sure I could get the tasmota rules to work when auto discovered by mqtt, I just would have to have the correct syntax to publish.

David, the sonoff mqtt parameters picture you shared are from a running tasmota or a generic setup picture? Would you mind checking a couple of your live tasmotas to see what your Full Topic is? As Flaming sortha pointed out, I don’t have “special” software, so my guess is that other tasmotas are doing the same thing.

The video I watched was from Feb 2018 and seems there have been many updates since. For example back then official instructions said to use coremosquitto as broker and how to set it up on yaml, but today instructions tell us to go to integrations and do it there.

For me being able to run the tasmota rules is important, as it is much easier to set up a 3way switch that way, instead of setting up groups, with scrips and automation, just to accomplish the same thing.