How to Toggle a 2 Gang switch?

Hi!
First post here.
I have tried for a week now but i can't find a sulotion.

I have a Sonoff t0 2 gang with tasmota on, that i want to have the relays to be oppsite to eachother att all time.
Like Power1 is ON then Power2 is OFF, and Power1 is OFF then Power2 is ON.

I only want to have one swtich in the Node-Red UI to change the states, and when i press one of the buttons on the Sonoff gang the state of the switch in the UI should change.

Any ideas for this problem?

Regards

Bifrost

Do you have two topics in MQTT, one for each switch state? If not then that is where I would start. Once you have that you can feed those into the node(s) to perform the logic. Get the node-red bit going first, add the sonoff button action after.

This one works in the UI
I tryed to use a http requset and you can see the http command in the text node.

But when i connect the stat it will be a never ending loop..

"Hallen_nere" is Swedish words..

Or is there a comand that i can put in topic like "cmnd/Hallen_nere/POWER2/OFF" since "/OFF" dosent work.

[{"id":"f06670c8.982bf","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"4d6e01e7.2f531","type":"ui_switch","z":"f06670c8.982bf","tab":"31b95423.40f18c","name":"Switch","topic":"","group":"","order":1,"onvalue":"on","offvalue":"off","x":600,"y":340,"wires":[["290763e4.54710c"]]},{"id":"290763e4.54710c","type":"switch","z":"f06670c8.982bf","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":750,"y":340,"wires":[["f3dbd8bf.571c"],["f0e78528.607c5"]]},{"id":"8cbb47d7.a9b758","type":"mqtt out","z":"f06670c8.982bf","name":"","topic":"cmnd/Hallen_nere/POWER2","qos":"","retain":"","broker":"e2f7a181.dc3568","x":1170,"y":380,"wires":[]},{"id":"43e6c4e8.97d48c","type":"rbe","z":"f06670c8.982bf","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":410,"y":340,"wires":[[]]},{"id":"da84220b.121f58","type":"mqtt in","z":"f06670c8.982bf","name":"","topic":"stat/Hallen_nere/POWER1","qos":"0","datatype":"auto","broker":"e2f7a181.dc3568","x":220,"y":300,"wires":[[]]},{"id":"f191be68.54266","type":"mqtt in","z":"f06670c8.982bf","name":"","topic":"stat/Hallen_nere/POWER2","qos":"0","datatype":"auto","broker":"e2f7a181.dc3568","x":220,"y":420,"wires":[[]]},{"id":"f0e78528.607c5","type":"http request","z":"f06670c8.982bf","name":"","method":"use","ret":"txt","paytoqs":false,"url":"http://192.168.1.232/cm?cmnd=Backlog%20Power1%20off%3BPower2%20on","tls":"","persist":false,"proxy":"","authType":"","x":890,"y":380,"wires":[["8cbb47d7.a9b758"]]},{"id":"f3dbd8bf.571c","type":"http request","z":"f06670c8.982bf","name":"","method":"use","ret":"txt","paytoqs":false,"url":"http://192.168.1.232/cm?cmnd=Backlog%20Power1%20on%3BPower2%20off","tls":"","persist":false,"proxy":"","authType":"","x":890,"y":280,"wires":[["50cf5d24.10fde4"]]},{"id":"50cf5d24.10fde4","type":"mqtt out","z":"f06670c8.982bf","name":"","topic":"cmnd/Hallen_nere/POWER1","qos":"","retain":"","broker":"e2f7a181.dc3568","x":1170,"y":280,"wires":[]},{"id":"be0fdb84.4d2f2","type":"ui_text","z":"f06670c8.982bf","tab":"31b95423.40f18c","name":"http://192.168.1.232/cm?cmnd=Backlog%20Power1%20off%3BPower2%20on","group":"","order":1,"format":"{{msg.payload}}","x":1090,"y":220,"wires":[]},{"id":"b8b6f206.dfa61","type":"ui_text","z":"f06670c8.982bf","tab":"31b95423.40f18c","name":"http://192.168.1.232/cm?cmnd=Backlog%20Power1%20on%3BPower2%20off","group":"","order":1,"format":"{{msg.payload}}","x":1050,"y":460,"wires":[]},{"id":"31b95423.40f18c","type":"ui_tab","z":"","name":"ESP devices","icon":"dashboard","order":10},{"id":"e2f7a181.dc3568","type":"mqtt-broker","z":"","name":"","broker":"192.168.1.131","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

What are you using the http node for?

I'd suggest to only use one Switch/Button...combine the two relays inside tasmota.

  1. set each relay into their wanted starting position, either manually from the tasmota console (Power1, Power2 and values on/off respectively or in node-red via an inject node.
  2. then use Power0 with value 2 (to toggle both (all) relays simultaneously, see: https://tasmota.github.io/docs/#/Commands?id=control

Don't forget about the PowerOnState setting/control in tasmota.

Another option might be the "interlock" control in tasmota, which allows you to group relays together

@Colin
I tried to use the backlog command. Like
http://192.168.1.232/cm?cmnd=Backlog%20Power1%20off%3BPower2%20on for one state and http://192.168.1.232/cm?cmnd=Backlog%20Power1%20on%3BPower2%20off for the other state.

which is working, but probobly not the right way to solve the problem.

How do i lock the relys in tasmota?

...this might be the RTFM moment ;-)....look at the control commands...the link, I referred to in my post above

I have, but i dont understand all of it :slight_smile:
I got the interlock to work.
its Interlock ON 1,2 by the way.
Thanks.

But when i push the button that is On on the sonoff then both are off, what do i have to look for to change that?

Did you try to set power1 to ON and power2 to OFF before grouping them?
Then maybe interlock will sync the relays in a group to be always in the same state.

Then, as you have only these two relays in your device, did you try the "power0 2" as I suggested before?

Edit: next best option is to create a rule in tasmota to sync/toggle both relays when one of them gets switched, then trigger that rule from nodered

You don't need to use http to send commands, you can publish them direct to MQTT and the device will pick them up.
As for the logic to work out what to do, you will need to use a Join node in key/value pair mode so that you can get a single message with the current state of both inputs. Set the Join to expect two inputs and also select And On Every Subsequent Message. Then once that is working (as shown with a debug node) pass that to a Function node which determines what to do. It will be able to use the topic of the message to know which one has just changed and can then look at the other and decide if it needs to change.

@hominidae
Yes i did type Power1 on and Power2 off before i group.
The Power0 2 command is used in node red only right?

OK, then grouping will not work with using interlock mode, I guess.
Power0 is a control command available in tasmota, as described in the docs.
Basically it is a default group, with all relays in it...as you only have the two available, there is no harm in using that group for your two relays....it offers a toggle command.

It can be used from the tasmota console for testing (issue power1 to ON, then power2 to OFF and then test with toggling via power0).
When this is working as desired, you should be able to use it via node-red mqtt
Remember that the initial state ON/OF for both relays will need to be monitored to stay in their interchanged state, especially after a reset/reboot or power loss.

Don't understand what you mean by that.

My switch is sending "On Value 2" and "Off Value 2" and it works fine, the sonoff is responding to the switch in the UI. Interlock mode works fine.

switch

Initial power on is set, relay 1 is active.

I dont get the MQTT feedback to work on the switch button in UI, when i press on the sonoff, im not sure what to type in in the MQTT in. I have tried "stat/Hallen_nere/POWER1"; stat/Hallen_nere/POWER0, but it will go in a bad loop.

stat

Problem to solve:
When i press an active relay on the sonoff it will go 0, then both could be inactive.

@Colin

If i was to use that command in node-red only.
Nevermind about that one.

Thanks for the patience!

When you press the physical button (assuming you have two, one for each relay), what you describe means that the button is directly configured to one relay only...hence both buttons and relays are not linked on the device, but only by using power0 command via node-red.
There is an option to configure the buttons to generate a publish message on mqtt instead of physically switching the relays.
When feeding these back into node-red, you can use that to manipulate the switch.
Check in the tasmota console what topics get generated/published to mqtt when the buttons are pressed, after you reconfigure them.
Obviously, when doing so, the physical buttons will only work when the device is connected to mqtt-broker as well is node-red.

Its this one T0 2 gang EU
to2gang

Result from tasmota

tasmota

Or did i not understand you?

OK, this is what happens, when you push button1 or button2 on the device:

  • the 2 mqtt messages (Power1/2 and Result) are published
  • the relay is also switched

...have a look here: https://tasmota.github.io/docs/#/Buttons-and-Switches
There it says:

By default a switch toggles the corresponding relay. Every time the switch gets flipped, the relay changes its state (ON or OFF). Instead of the default toggling of the relay, switches can be configured to send messages to different MQTT topics or send commands to other Tasmota devices. To ignore the default behaviour define a rule which triggers on Switch<x>#State or use Switchtopic .

What I am suggesting is that you should change the behaviour of the buttons on the T0 to stop switching the relay directly but sending the "power0 2" command for each press instead....like you send from node-red

Edit: ..and read the rules examples for buttons/switches and their states, from here: https://tasmota.github.io/docs/#/Rule-Cookbook?id=button-with-single-press-double-press-and-hold

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.