Mqtt and rules for a 3 way switch

Ok so I’ve been having a slew of issues with mqtt. I finally got some great advice from David on another post, and I was able to get mqtt working using integration and auto discovery, and not using config.yaml file.

I am now following this Video to try and set up a 3 way switch, but it doesn’t work. Yesterday at one point I was able to toggle the led of the switch with no relay (secondary swtich) to turn on and off when ever the main switch (with the relay) was toggled. However I was not able to the secondary switch to toggle the main switch. This was also when only one Switch would show up on HA because I didn’t have the proper formatting.

So on my secondary switch, when I press the switch this is what shows on the console

08:06:44 RUL: SWITCH1#STATE performs “publish cmnd/CuartoMiriam/POWER TOGGLE”
08:06:44 MQT: cmnd/CuartoMiriam/POWER = TOGGLE

and this is my rule1
08:08:25 MQT: CuartoMiriam/stat/RESULT = {“Rule1”:“ON”,“Once”:“OFF”,“StopOnError”:“OFF”,“Free”:447,“Rules”:“on power1#state do publish cmnd/MiriamSwitch/POWER %value% endon”}

I did verify on the main switch, and both the friendly name and the mqtt topic are both CuartoMiriam

Now on the mqtt entities on the integreation section I did notice that the IDs used there are different, switch.cuarto_miriam_2

Any ideas on how I can get the rules to work

So I was able to resolve my issue with help from another post I had on this site. Figured I would add my findings here in case someone else finds themselves on the same situation as me.

The error was on my Tasmota setup. Many instructions I was following mentioned setoption19 to 1, which is HA auto discovery mode. What they didn’t mention was that once you do that, Tasmota automatically swithes the order of the values under “Full Topic” on the mqtt parameters screen. If you do a setoption19 to 0 again Tasmota doesn’t “undo” the change to the order of the “Full Topic”.

If you have your switch info on the yaml file (not using auto discovery), your code probably looks something like this

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

And your tasmota’s “Full Topic” should read like this : %prefix%/%topic%

If you went with MQTT integration with discovery, you wouldn’t list your switch on the yaml file, HA would find it and set it up automagically. For this to work, you would have to set your tasmota setoption19 to 1, which would automatically switch the order of the topic, to read like this : %topic%/%prefix%/

So setting up with the mqtt integration (the official recommendation now) and you would like to use rules on your tasmotas, the rules should follow this syntax:

“Rule1”:“ON”,“Once”:“OFF”,“StopOnError”:“OFF”,“Free”:447,“Rules”:“on power1#state do publish MiriamSwitch/cmnd/POWER %value% endon”

With MiriamSwitch being the Topic (name of device), and cmnd being the prefix.

1 Like

I’m pretty sure it does actually… almost 100% certain.

I am running tasmota’s version 6.4.1 and I can confirm that it doesn’t switch back to normal. I just ran the test again to make sure.

If I don’t forget by next week, might find their main community (tasmotas) and inform them about this sudo bug (I don’t think it qualifies as a regular/real bug). Since I personally never changed that part of the code I never looked at the info until Kangas post.

I can see this throwing MANY newbies like myself for a long long loop! When I looked up the codes, on what I think their official github page it reads : SetOption19 1 / on Enable Home-Assistant automatic discovery. I think usually newbies like myself this often as far as they go on reading about setoption19.

I have 2 tasmota 3 way ss01 switches on the same light. Trying to figure out how to se this up to control them from home assistant with one button. Right now they work great without home assistant. When you turn on the light from either switch the led turns off then turns on when off the lights are on and off. Problem I’m getting is the state of the relay and home assistant. Ha sees the state of the relay and if one switch is on but the other is off the light may be on. Lots of different ways to turn the switches on or off to get the light to turn on or off because of the way a 3 way circuit works. How do I get home asssitant to just turn the light on or off even if the main switch or secondary switch is on or off?

Sorry, old post, just saw it now. Not sure if you figured it out yet or not. I did a couple 3 ways. I couldn’t make full sense of what you have set up, but this is what I have:

bottom of the stairs there is a switch plate with two push buttons (they don’t flip to one side or another like regular switch). The top button turns stairs light on/off, bottom button turns kitchen light on/off. On top of the stairs I have another wall plate with two buttons. The top one toggles the stairs light on/off, and the bottom button turns the upstairs hallway light on/off.

I made my own sonoff basic. With one chip I am controlling 3 relays (kitchen, stairs, hallway lights), and I have the 4 buttons connected. By accident I noticed that if you set up 4 switches with 3 relays, the 4th switch controls the same relay as switch #1 (so stairs switch downstairs is switch one, and stairs switch upstairs is on switch 4).

When the buttons are pressed, they toggle the current state of the light.

In my set up, I built my own set up, so I have more control. You seem to have a totally different setup. It almost seems you are trying to mix a conventional 3 way wiring system with HA.

I would be happy to give some advice if you still need it