logo elektroda
logo elektroda
X
logo elektroda

Preventing Simultaneous Activation of Both Relays in OpenBK7231T-Tuya Shutter Switch

hoezyhoest 2856 11
ADVERTISEMENT
  • #1 20413815
    hoezyhoest
    Level 2  
    I just flashed my tuya shutter switch with openbk7231t and everything is working correctly. but how can I prevent activating both relays at the same time? I need something like the shutter mode in tasmota. or is my only option to replace the WB3S chip with ESP and flash tasmota on it?
  • ADVERTISEMENT
  • #2 20413848
    p.kaczmarek2
    Moderator Smart Home
    Well, I can write any driver for you if you want, but it should be also possible to both configure or script OBK to suit your needs.

    You could, for example, set one relay Rel and second to Rel_n, and set them both to single channel, then they would work in mutually exclusive way.

    You could also use some scripting - for example, make a change handler and do something there:
    
    addChangeHandler Channel0 == 1 YourCommandHere
    addChangeHandler Channel0 == 0 YourCommandHere
    

    You can use any command in event handler, or even start a script.
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md
    You can also use repeating event with counter set to 1 to do something after a delay.
    
    addRepeatingEvent 2 1 setChannel 0 0
    


    but again, if you have a specific use case in mind, I can write a dedicated driver for you, as long as you can explain how is it supposed to work. Show your device configuration, etc.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 20414102
    hoezyhoest
    Level 2  
    i tried setting them both to single channel but it still keeps one of them constantly on.
    i tried the scripting part but that is a bit complicated for me :P (i do know how to run them)

    i'm using a switch like this and i need something like the InterLock setting in tasmota so that none can accidentally fire two relays on the physical touch buttons
    https://templates.blakadder.com/WF-CS01_EU.html

    these are my settings:

    Preventing Simultaneous Activation of Both Relays in OpenBK7231T-Tuya Shutter Switch
  • #4 20414125
    p.kaczmarek2
    Moderator Smart Home
    I am not sure yet, but just maybe, this autoexec.bat (in Web Application ->LittleFS tab) can help?
    
    // when channel 0 becomes 1, turn off channel 1
    addChangeHandler Channel0 == 1 SetChannel 1 0
    // when channel 1 becomes 1, turn off channel 0
    addChangeHandler Channel1 == 1 SetChannel 0 0
    

    I haven't done shutters yet. Futhermore, do they require turning off both relays after a given time?
    Helpful post? Buy me a coffee.
  • #5 20414151
    hoezyhoest
    Level 2  
    thnx alot! this is the same as the interlock from tasmota and works like a charm :)

    i'm using home assistant to time the relays so that's not a problem. this was only for protection so i won't blow up the motors by accident.


    cheers!
  • ADVERTISEMENT
  • Helpful post
    #6 20433363
    maliciamrg
    Level 2  
    hello ,

    Thks to you two i have complet the setting of my shutter switch WF-CS01_EU

    in complement of your setting , i post mine (5 leds , 3 buttons and 2 relai) :

    Preventing Simultaneous Activation of Both Relays in OpenBK7231T-Tuya Shutter Switch

    and like sugest p.kaczmarek2 , i add a autoexec.bat file , who mimic the original firmware :

    
    //blue led on
    SetStartValue 3 1
    
    // interlock relais
    addChangeHandler Channel0 == 1 SetChannel 2 0
    addChangeHandler Channel2 == 1 SetChannel 0 0
    
    //cancel button
    addChangeHandler Channel1 == 1 SetChannel 0 0
    addChangeHandler Channel1 == 1 SetChannel 2 0
    
    //toggle night led mode
    addEventHandler OnHold 10 ToggleChannel 3
    
    //auto cancel relais after delai 34s
    addChangeHandler Channel0 == 1 addRepeatingEventID 34 1 910 SetChannel 0 0
    addChangeHandler Channel2 == 1 addRepeatingEventID 34 1 912 SetChannel 2 0
    
    //auto cancel cancel button after 5s
    addChangeHandler Channel1 == 1 addRepeatingEventID 5 1 911 SetChannel 1 0
    
    //auto cancel cancel relai
    addChangeHandler Channel1 == 1 cancelRepeatingEvent 910
    addChangeHandler Channel1 == 1 cancelRepeatingEvent 912
    


    :spoko:
  • #7 20433374
    p.kaczmarek2
    Moderator Smart Home
    So you've made a shutters support entirely in our scripting language? Nice.

    I've been also prototyping something like that, here:
    https://github.com/openshwprojects/OpenBK7231...rc/selftest/selftest_demo_scriptForShutters.c
    Helpful post? Buy me a coffee.
  • #8 20433399
    maliciamrg
    Level 2  
    p.kaczmarek2 wrote:
    So you've made a shutters support entirely in our scripting language? Nice.

    I've been also prototyping something like that, here:
    https://github.com/openshwprojects/OpenBK7231...rc/selftest/selftest_demo_scriptForShutters.c


    Wow, now I know how to use "alias" and "backlog", pretty powerful.

    If I can suggest a use case to add in your demo, the possible mind changing of a user. (aka: I start to open my shutter but at the mid course I change my mind and decide to close it)

    Thanks for your work for developing this firmware which saves a lot of my wifi OT, you rock.
  • #9 20433581
    p.kaczmarek2
    Moderator Smart Home
    Your script seems pretty nice, you could submit it as another demo/self test (in separate file) via pull request
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #10 21587087
    spleefer90
    Level 7  
    I also need this, and the scripting works, but it triggers the relay before deactivating the second one.

    This happens near instantly, but it still means both are on for a split second, does it not?

    I cannot use the Rel Rel_n on the same channel, as I have two relays controlling my electric roller blinds going up or down.

    I want to either send UP with rel1, or DOWN with rel2, or neither when idle.
    I do not want to send them either an ON or OFF signal at all times, I want to send no signals when idle (both relays off).
    I do not want them to ever be ON and OFF at the same time (already fried one relay).

    The handler setchannel is my current solution for the time being, but I do hope I can hook something to turn the relay on another channel OFF before turning one ON.

    EDIT: This code seems to not be enough, seems like the split moment is enough to break my relay and invert it, broke another one. I think I want a small delay of OFF on both relays before one triggers on, but I am lost as to how to do this on OBK.
  • #11 21594298
    p.kaczmarek2
    Moderator Smart Home
    I'm working on alternate solution for that - ability to link two pins to single channel and use 3 channel values for disabled, up or down.
    Currently working self-test code:
    Code: C / C++
    Log in, to see the code
    Helpful post? Buy me a coffee.

Topic summary

✨ The discussion addresses preventing simultaneous activation of both relays in a Tuya shutter switch flashed with OpenBK7231T firmware. The main concern is to avoid damaging the motor by ensuring only one relay is active at a time, similar to the "shutter mode" or "InterLock" feature in Tasmota firmware. Solutions include configuring relays as single channels with mutual exclusivity or using scripting with event handlers (addChangeHandler) to turn one relay off when the other is activated. An example script in autoexec.bat uses change handlers to enforce interlock behavior by switching off the opposite relay upon activation. Users also shared more complex scripts mimicking original firmware behavior, including auto-cancel timers and button handling. Challenges remain with the brief overlap when switching relays, which can cause hardware damage; a proposed solution involves implementing a delay (dead time) between turning one relay off and the other on, with ongoing development of a PinMutex driver to manage this safely. The discussion includes references to scripting capabilities, demo scripts for shutter control, and integration with Home Assistant for timing relay deactivation.
Generated by the language model.

FAQ

TL;DR: To stop two relays energizing together, use a 100 ms dead time and “link two pins to a single channel.” For OBK/OpenBK7231T shutter switches, start with the PinMutex driver or a simple interlock script. [Elektroda, p.kaczmarek2, post #21594298]

Why it matters: Split-second overlap can damage shutter relays; enforced interlock protects motors and power supplies.

Quick Facts

How do I prevent both relays from turning on at the same time in OpenBK/OpenBK7231T?

Use an interlock script in autoexec.bat (LittleFS). Add change-handlers so each relay forces the other OFF when it turns ON. Example logic: when Channel0 becomes 1, set Channel1 to 0; when Channel1 becomes 1, set Channel0 to 0. This mimics a mutual exclusion latch without extra hardware. It’s simple, fast, and suitable when you only need immediate opposite-off behavior. [Elektroda, p.kaczmarek2, post #20414125]

Is there a built-in way to add dead time between UP and DOWN?

Yes. Use the PinMutex driver to bind two output pins to one channel with a configurable dead time. Example: setMutex 0 0 100 10 11 adds 100 ms where both outputs are OFF before switching directions. The channel becomes 3-state: 0=disabled, 1=up, 2=down. This guarantees no overlap during reversals and protects relays and motors. [Elektroda, p.kaczmarek2, post #21594298]

Does the simple script ever energize both relays for a moment?

It can, because the off and on actions race. One user observed a near-instant overlap that still damaged a relay. That edge case appears when changing direction quickly. Use PinMutex to enforce an OFF dead time before the new direction turns ON. This eliminates split-moment simultaneous activation and stops relay inversion issues. [Elektroda, spleefer90, post #21587087]

Can OpenBK mimic Tasmota’s InterLock?

Yes. The two change-handlers provide the same behavior. A user confirmed, “this is the same as the interlock from tasmota and works like a charm.” Use the script for mutual exclusion, and let your automation platform handle timing if needed. [Elektroda, hoezyhoest, post #20414151]

How do I configure the PinMutex driver?

  1. Run: startDriver PinMutex.
  2. Link your channel and pins with dead time: setMutex 0 0 100 .
  3. Drive the channel: setChannel 0 1 for UP, setChannel 0 2 for DOWN, setChannel 0 0 for idle. This ensures both relays are OFF during the 100 ms transition window. Adjust the delay to match your hardware. [Elektroda, p.kaczmarek2, post #21594298]

Why doesn’t the Rel/Rel_n single‑channel method suit roller blinds?

Mapping both relays to one channel with Rel/Rel_n can leave one relay constantly ON. A user reported that outcome after trying the single-channel approach. Blinds need an idle state with both relays OFF, then a safe, exclusive UP or DOWN. Use PinMutex or a script that explicitly returns to idle. [Elektroda, hoezyhoest, post #20414102]

When should I use Rel and Rel_n on one channel?

Use Rel/Rel_n when you need simple mutual exclusion on one logical channel, and a constant ON state is acceptable for the load. Set one output to Rel and the other to Rel_n, mapped to the same channel. They will not be ON simultaneously, but consider idle behavior for your device. [Elektroda, p.kaczmarek2, post #20413848]

How do I add a travel timeout and a cancel button?

Add change-handlers that schedule an auto-off after the movement starts, plus a cancel button that stops motion and clears timers. Example values used: 34 s auto-off for travel and 5 s auto-reset of the cancel button. Also cancel any pending travel timers when cancel is pressed. These patterns protect motors from overrun. [Elektroda, maliciamrg, post #20433363]

How do I set a night LED and a long‑press toggle?

Set a startup LED value and add a hold event to toggle it. For example, SetStartValue on the LED channel enables a default state at boot. Then add an OnHold event that calls ToggleChannel on that LED channel. This recreates the OEM night-light behavior alongside your interlock logic. [Elektroda, maliciamrg, post #20433363]

Will Home Assistant timing work alongside the OBK interlock?

Yes. You can let Home Assistant handle timing while OBK handles safety interlock. A user confirmed using HA to time the relays, with the OBK script solely preventing accidental dual activation. This separation of concerns works well for blinds. [Elektroda, hoezyhoest, post #20414151]

How can I safely reverse direction mid‑travel?

Use PinMutex so both outputs go OFF for the configured dead time before changing direction. Dead time, such as 100 ms, prevents overlap and protects relays when users change their minds mid-course. “Dead time” enforces off-before-on, even during rapid toggles. [Elektroda, p.kaczmarek2, post #21594298]

How can I insert a delay in a script before switching relays?

Use a repeating event with a single count to schedule a delayed action. For example, addRepeatingEvent 1 SetChannel 0 turns a channel OFF after a delay. Chain this with a second action to switch the other relay after the off-delay. This creates a scripted dead time. [Elektroda, p.kaczmarek2, post #20414125]

Is there a demo shutter script I can study?

Yes. The developer posted a prototype/demo script that models shutter behavior in the project’s self-test area. It shows aliases, backlogs, and control flow for safe operation. Review it to adapt patterns to your device and channel mapping. [Elektroda, p.kaczmarek2, post #20433374]

Can I submit my script as a demo to the project?

Yes. The maintainer encouraged contributions: “you could submit it as another demo/self test (in separate file) via pull request.” Package your script and open a PR to share it with others. This helps standardize safe shutter control. [Elektroda, p.kaczmarek2, post #20433581]

Can I request a dedicated shutter driver?

Yes. The maintainer said, “I can write any driver for you if you want,” and asked for clear requirements. Share your wiring, channel plan, and desired behavior. A tailored driver can embed interlock and timing in one place. [Elektroda, p.kaczmarek2, post #20413848]

Is there a simplified setup using the new mutex driver?

Yes. A user confirmed the new mutex driver avoids simultaneous triggering and requires only a fraction of the scripting. It links both directions to one channel safely. Use it to replace complex interlock scripts with a concise configuration. [Elektroda, spleefer90, post #21599659]
Generated by the language model.
ADVERTISEMENT