logo elektroda
logo elektroda
X
logo elektroda

[Solved] [OpenBK] How to control 10+ MQTT devices with Tuya Mini multi-click button?

antonioriosarroyo 711 9
Best answers LABEL_AI_GENERATED

How can I use a Tuya Mini with OpenBK to trigger more than 10 MQTT actions from multi-click button presses?

Use an OpenBK build/branch that adds extra click events, such as `On6Click` through `On10Click`, instead of relying only on the default 1–5 click handlers [#21927334][#21927510] A custom `onxclick` branch/build was shared, with downloadable GitHub artifacts for logged-in users [#21927334] If you implement it yourself, use a `switch` for all click counts and keep the result bounded so you do not generate ghost events beyond `CMD_EVENT_PIN_ON10CLICK` [#21927510] Do not map the event IDs with simple arithmetic like `CMD_EVENT_PIN_ONCLICK + clickCount - 1`, because the existing event enum is not contiguous after `OnDblClick` and that would mis-map events or require renumbering [#21927524]
AI summary based on the discussion. May contain errors.
ADVERTISEMENT
  • Need exact OpenBK build and button pin setup

    #1 21926871
    antonioriosarroyo
    Level 5  
    Posts: 15
    Rate: 1
    Hi, I have a question about multitouch. I want to use a Tuya Mini with OpenBK and use the button to turn several devices on and off, 10 or more in total, via MQTT.

    I know up to 5 presses is fine, but I need more. Any ideas?

    
    addEventHandler OnClick 14 publish Habitacion1/1/set toggle
    addEventHandler OnDblClick 14 publish Habitacion2/1/set toggle
    addEventHandler On3Click 14 publish Habitacion3/1/set toggle
    addEventHandler On4Click 14 publish Habitacion4/1/set toggle
    addEventHandler On5Click 14 publish Habitacion5/1/set toggle
    addEventHandler On6Click 14 publish Habitacion6/1/set toggle
    addEventHandler On7Click 14 publish Habitacion7/1/set toggle
    addEventHandler On8Click 14 publish Habitacion8/1/set toggle
    addEventHandler On9Click 14 publish Habitacion9/1/set toggle
    


    I know this code is wrong, it's just to express the idea.

    Thank you very much, have a good day


    Hi, what exact OpenBK firmware version/build are you using on the Tuya Mini?
    1.18.295
    Can you share the exact Tuya Mini model and your current button/channel configuration, especially what pin/channel 14 is set to in OpenBK?
    Yes
  • ADVERTISEMENT
  • #2 21926991
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14814
    Help: 659
    Rate: 12985
    Well... are you sure that would be intuitive? I think @divadiow can easily add those events for you, if you really think they can be useful.
    Helpful post? Buy me a coffee.
  • #3 21927092
    antonioriosarroyo
    Level 5  
    Posts: 15
    Rate: 1
    That would be great, and you could even use it to adjust the light intensity with a button: 10%, 20%...
  • ADVERTISEMENT
  • #4 21927246
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14814
    Help: 659
    Rate: 12985
    For light intensity, why not a hold even? Repeating one, as long as button is held.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • ADVERTISEMENT
  • #6 21927446
    antonioriosarroyo
    Level 5  
    Posts: 15
    Rate: 1
    Thanks a lot—that was quick! I'll give it a try when I have a moment.

    Added after 14 [minutes]:

    @divadiow , @p.kaczmarek2 , thanks.

    I think I'll start with an RF fan I have—a 6-speed model. It uses 7 presses: 6 speeds plus off, and a long press for the light. I already have Node-RED and RF set up... thanks a lot again.
  • Suggesting a calculated multi-click event mapping

    #7 21927510
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14814
    Help: 659
    Rate: 12985
    Not bad,however, this:
    Code: C / C++
    Log in, to see the code

    If you are going to use switch statement, why not use it for all click counts?
    Followup question: why not convert to calculation like return CMD_EVENT_PIN_ONCLICK + clickCount - 1 ? Also bounded to avoid doing ghost events past CMD_EVENT_PIN_ON10CLICK.
    Helpful post? Buy me a coffee.
  • Noncontiguous event enum prevents simple click-count mapping

    #8 21927524
    divadiow
    Level 38  
    Posts: 5246
    Help: 451
    Rate: 921
    p.kaczmarek2 wrote:
    If you are going to use switch statement, why not use it for all click counts?

    https://github.com/divadiow/OpenBK7231T_App/commit/3707162e39fdcd8c7c982d3a2260ec03e139ee01

    p.kaczmarek2 wrote:
    why not convert to calculation like return CMD_EVENT_PIN_ONCLICK + clickCount - 1 ? Also bounded to avoid doing ghost events past CMD_EVENT_PIN_ON10CLICK.


    "because the existing event enum is not contiguous after OnDblClick; doing that would mis-map events or require renumbering existing IDs."
  • OpenBK script for multi-click MQTT fan control

    #9 21927686
    antonioriosarroyo
    Level 5  
    Posts: 15
    Rate: 1
    In the end, I decided to increase the fan speed—and make the relay click so I could locate it. I'm posting this here in case it helps anyone. As for the lights, I am going to install the multitouch system.
    
    setChannelType 5 Custom
    setChannel 5 0
    
    addEventHandler OnClick 14 addChannel 5 1 0 5 1
    
    alias Pulso backlog setChannel 50 1; delay_s 1; setChannel 50 0
    alias Pulso1 backlog Pulso; delay_s 1; Pulso
    alias Pulso2 backlog Pulso; delay_s 1; Pulso; delay_s 1; Pulso
    alias Pulso3 backlog Pulso; delay_s 1; Pulso; delay_s 1; Pulso; delay_s 1; Pulso
    alias Pulso4 backlog Pulso; delay_s 1; Pulso; delay_s 1; Pulso; delay_s 1; Pulso; delay_s 1; Pulso
    alias Pulso5 backlog Pulso; delay_s 1; Pulso; delay_s 1; Pulso; delay_s 1; Pulso; delay_s 1; Pulso; delay_s 1; Pulso
    
    addEventHandler OnChannelChange 5 if $CH5==0 then publish cmnd/boton/rfsend cero 1 fi
    addEventHandler OnChannelChange 5 if $CH5==1 then backlog Pulso; publish cmnd/boton/rfsend uno 1 fi
    addEventHandler OnChannelChange 5 if $CH5==2 then backlog Pulso2; publish cmnd/boton/rfsend dos 1 fi
    addEventHandler OnChannelChange 5 if $CH5==3 then backlog Pulso3; publish cmnd/boton/rfsend tres 1 fi
    addEventHandler OnChannelChange 5 if $CH5==4 then backlog Pulso4; publish cmnd/boton/rfsend cuatro 1 fi
    addEventHandler OnChannelChange 5 if $CH5==5 then backlog Pulso5; publish cmnd/boton/rfsend cinco 1 fi
    
  • Debounce multi-presses with 2-second timeout script

    #10 21928170
    antonioriosarroyo
    Level 5  
    Posts: 15
    Rate: 1
    In the end, I removed the clicks I didn't like—and the multi-press feature was driving me crazy because it wasn't counting correctly—so I decided to ask ChatGPT, and it gave me this solution:

    Each press increments the counter. After 2 seconds without any new presses, the script executes the corresponding action based on the number of presses, publishes the MQTT message, resets the counter to zero, and waits for a new sequence of presses.
    Autoexec.bat
    
    setChannelType 5 Custom
    setChannel 5 0
    
    addEventHandler OnClick 14 backlog addChannel 5 1 0 5 5; stopScript CLICK 0; startScript clicks.scr inicio CLICK
    

    clicks.scr
    
    inicio:
    setChannel 10 $CH5
    
    
    inicio:
    setChannel 10 $CH5
    
    delay_s 2
    
    if $CH10 != $CH5 then goto inicio
    
    if $CH5==1 then backlog publish cmnd/boton/rfsend uno 1 fi
    if $CH5==2 then backlog publish cmnd/boton/rfsend dos 1 fi
    if $CH5==3 then backlog publish cmnd/boton/rfsend tres 1 fi
    if $CH5==4 then backlog publish cmnd/boton/rfsend cuatro 1 fi
    if $CH5==5 then backlog publish cmnd/boton/rfsend cinco 1 fi
    
    setChannel 5 0
    exit
    

    Basically, every time you press it, it increments channel 5 by 1, runs the secondary script, and pauses for 2 seconds; if there are new presses, it starts over. If there are no further presses, it sends the MQTT message and resets the counter to zero. Feel free to edit my post if it isn't clear—since it was translated via Google, I'm not sure how it reads—and thank you for your time and patience.

Topic summary

LABEL_AI_GENERATED
The discussion is about using a Tuya Mini running OpenBK firmware as a multi-click MQTT controller for more than 10 devices. The original idea was to map single, double, triple, and higher click counts to different MQTT toggle commands, but the available click events seemed limited. A response suggested that additional click events could be added to OpenBK if they are useful, and a custom build/branch was shared that implements extended click handling. The topic also touched on using repeated clicks for light dimming and using a hold action for continuous adjustment. The author later confirmed the new build and planned to test it with an RF fan setup requiring seven actions, including six speeds, off, and a long-press light function.
AI summary based on the discussion. May contain errors.
ADVERTISEMENT