logo elektroda
logo elektroda
X
logo elektroda

[BK7231N/CB3S] Tuya Wi-Fi Curtain Module - config for hold button and finishing timout

jbaltes 960 2
ADVERTISEMENT
  • #1 20854572
    jbaltes
    Level 2  

    I did not find the exact config for https://de.aliexpress.com/item/1005005664191871.html.

    So I started from here: https://www.elektroda.com/rtvforum/topic4011762.html#20795168.

    But the button function was not as expected: only holding a button should activate a relay - there should be no push button mode. Nevertheless, I want to keep the 30 seconds relay active time. So I changed the autoexec.bat to the following:

    
    // Autoexec.bat file for Tuya Wi-Fi Curtain Module, please adapt to your hardware if different
    startDriver SSDP
    PowerSave 1
    // P7 - L1 Relay Channel 1 Close
    // P23 - L2 Relay Channel 3 Open
    // P24 - S1 Btn Channel 1 Close
    // P26 - S2 Btn Channel 3 Open
    // Channel 2 - Stop
    // Channel 4 - Close is finished
    // Channel 5 - Open is finished
    // P8 - Wifi Btn
    // P6 - Wifi LED
    // ntp setup
    ntp_setServer 192.168.178.1
    ntp_timeZoneOfs +01:00
    startDriver NTP
    // daily automatic close/open
    addClockEvent 19:00 0x7f backlog SetChannel 1 1; startScript autoexec.bat resetClose
    addClockEvent 09:00 0x7f backlog SetChannel 3 1; startScript autoexec.bat resetOpen
    // description
    SetChannelLabel 1 Close
    SetChannelLabel 2 Stop
    SetChannelLabel 3 Open
    // configure buttons
    addEventHandler OnHold 24 if Channel4 == 0 then backlog setChannel 1 1
    addEventHandler OnRelease 24 backlog setChannel 1 0
    addEventHandler OnHold 26 if Channel5 == 0 then backlog setChannel 3 1
    addEventHandler OnRelease 26 backlog setChannel 3 0
    // logic
    alias Reset_Stop_Close backlog SetChannel 2 0; SetChannel 1 0
    alias Reset_Stop_Open backlog SetChannel 2 0; SetChannel 3 0; SetChannel 4 0; SetChannel 5 0
    alias Reset_Close_Open backlog SetChannel 1 0; SetChannel 3 0
    addChangeHandler Channel1 == 1 backlog Reset_Stop_Open; startScript autoexec.bat resetClose
    addChangeHandler Channel2 == 1 backlog Reset_Close_Open; startScript autoexec.bat resetStop
    addChangeHandler Channel3 == 1 backlog Reset_Stop_Close; startScript autoexec.bat resetOpen
    // do not proceed
    return
    // Scripts
    resetClose:
    delay_s 30
    // stop close and notice close is finished
    SetChannel 1 0
    SetChannel 4 1
    return
    resetStop:
    delay_s 1
    // disable button
    SetChannel 2 0
    stopAllScripts
    return
    resetOpen:
    delay_s 30
    // stop open and notice open is finished
    SetChannel 3 0
    SetChannel 5 1
    return

  • ADVERTISEMENT
  • #2 20854608
    p.kaczmarek2
    Moderator Smart Home
    Hello, is your pin role a Button (Btn) or Script Button (Btn_ScriptOnly)?

    Btn_ScriptOnly will only fire scripting events. A simple Button (Btn) will fire script events but it will also automatically toggle linked channel.
    Helpful post? Buy me a coffee.
  • #3 20857277
    jbaltes
    Level 2  

    Thank you for this hint.

    I changed the Button definitions to Btn_ScriptOnly and retested the script but nothing worked as before, then I realized there were some errors.

    * Correct conditions in if statement
    * Change if commands to one word with aliases
    * Add more aliases

    Here is the new script:

    
    // Autoexec.bat file for Tuya Wi-Fi Curtain Module, please adapt to your hardware if different
    startDriver SSDP
    PowerSave 1
    // P7 - L2 Relay Channel 1 Close
    // P23 - L1 Relay Channel 3 Open
    // P24 - S2 Btn_ScriptOnly Channel 1 Close
    // P26 - S1 Btn_ScriptOnly Channel 3 Open
    // Channel 2 - Stop
    // Channel 4 - Close hold active
    // Channel 5 - Open hold active
    // P8 - Wifi Btn
    // P6 - Wifi LED
    // ntp setup
    ntp_setServer 192.168.178.1
    ntp_timeZoneOfs +01:00
    startDriver NTP
    // logic
    alias StartClose backlog SetChannel 1 1
    alias StopClose backlog SetChannel 1 0
    alias StartOpen backlog SetChannel 3 1
    alias StopClose backlog SetChannel 3 0 
    alias OnHold_Close backlog SetChannel 1 1; SetChannel 4 1
    alias OnHold_Open backlog SetChannel 3 1; SetChannel 5 1
    alias OnRelease_Close backlog StopClose; SetChannel 4 0; stopAllScripts
    alias OnRelease_Open backlog StopOpen; SetChannel 5 0; stopAllScripts
    // daily automatic close/open
    addClockEvent 19:00 0x7f backlog StopOpen; StartClose
    addClockEvent 09:00 0x7f backlog StopClose; StartOpen
    // description
    SetChannelLabel 1 Close
    SetChannelLabel 3 Open
    // configure buttons
    addEventHandler OnHold 24 if $CH4==0 then OnHold_Close
    addEventHandler OnRelease 24 OnRelease_Close
    addEventHandler OnHold 26 if $CH5==0 then OnHold_Open
    addEventHandler OnRelease 26 OnRelease_Open
    addChangeHandler Channel1 == 1 backlog StopOpen; startScript autoexec.bat resetClose
    addChangeHandler Channel3 == 1 backlog StopClose; startScript autoexec.bat resetOpen
    // do not proceed
    return
    // Scripts
    resetClose:
    delay_s 30
    // stop close
    StopClose
    return
    resetOpen:
    delay_s 30
    // stop open and notice open is finished
    StopOpen
    return
    

ADVERTISEMENT