logo elektroda
logo elektroda
X
logo elektroda

Converting Tasmota Button Rules for Use in OpenBeken BK7231 - Syntax Guidance Needed

omniron 4107 11
ADVERTISEMENT
  • #1 20942170
    omniron
    Level 11  
    Posts: 114
    Help: 1
    Rate: 6
    Still baffled why/that the syntax of Tuya is so different from Tasmota.
    Tried to replace WebSend with SendGet etc but got nowhere.

    Does anybody know both worlds and could be so kind to just translate this to Tuya please?
    Would really appreciate it.

    # This turns on or off all addressed lights from a button (of an outlet or light switch or dimmer etc) positioned at the entrance.
    # With one button all addressed lights/stereo/appliances can be turned on when entering, or off when leaving.
    # No MQTT or "ignoring default button behavior (SetOption73)" needed.
    # All done with just the tremendous capabilities of Tasmota and with the help of amazing sfromis and AndreKR.
    # https://github.com/sfromis
    # https://github.com/AndreKR
    
    # SETUP (all below in console of the entrance 10.10.10.80 unit, just once), no need to change anything with addressed (10.10.10.81, 10.10.10.82) units:
    
    # reduce long press from default 4 to 2 seconds, 4 seconds seemed too long. 
    SetOption32 20
    
    # button state 2 is 1 short press
    # Rule 1's first DO turns on local relay of the 10.10.10.80 unit, second DO turns on relay 3 of 10.10.10.81 unit, 2-second delay, then third DO turns on relay 2 of 10.10.10.82 unit
    
    Rule1 ON Button1#state=2 DO Backlog Power1 on; WebSend [10.10.10.81] Power3 on; Delay 20; WebSend [10.10.10.82] Power2 on ENDON
    
    # Activate Rule 1
    Rule1 1
    
    # Rule2 reverses the above
    # button state 3 is a long press
    
    Rule2 ON Button1#state=3 DO Backlog Power1 off; WebSend [10.10.10.81] Power3 off; WebSend [10.10.10.82] Power2 off ENDON
    Rule2 1
  • ADVERTISEMENT
  • #2 20942619
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14394
    Help: 650
    Rate: 12315
    Hello, what are you exactly trying to do? Button events in OBK? Do a SendGet on a button event?

    See here:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md
    Search for OnClick
    And for sending a command via GET, you can see here:
    
    SendGet http://192.168.0.112/cm?cmnd=Power0%20ON
    
    Helpful post? Buy me a coffee.
  • #3 20942740
    omniron
    Level 11  
    Posts: 114
    Help: 1
    Rate: 6

    Hi and thank you for your help, you are really the backbone of it all!

    I'm trying to use https://www.elektroda.com/rtvforum/topic4015180.html to implement the (Tasmota) automation of house entrance "turn several lights on" and turn them "off".

    Was using the "basic command line" to enter those above Tasmota commands, got "Error:CMD:cmd Rule1 NOT found" etc.
    Some reading made me realize that implementing the function of mentioned script is very different with tuya.
    I did understand that SendGet is similar to WebSend, but that was not enough.

    So should that Tasmota script be implemented with autoexec.bat??
    And use something like "Button_ScriptOnly" to start the actions as in the Tasmota script?
    Or something like this?

    Tuya unit (where the button is pressed) is at 192.168.0.112,
    remote unit 1 is 192.168.0.113,
    remote unit 2 is 192.168.0.114,

    // set button hold times
    SetButtonTimes 20 3 3
    //turn on after short click
    addEventHandler OnClick Power0%20ON; SendGet http://192.168.0.113/cm?cmnd=Power2%20ON; SendGet http://192.168.0.114/cm?cmnd=Power3%20ON
    //turn off after 2-second-long click
    addEventHandler OnClick 20 Power0%20OFF; SendGet http://192.168.0.113/cm?cmnd=Power2%20OFF; SendGet http://192.168.0.114/cm?cmnd=Power3%20OFF
    


    Again, I just want one "entrance" Tuya unit's short press button to turn on several other units, and turn them all off with a 2-second long press. I saw one info (video?) implementing something like what I need, but couldn't find it.
    Thanks!
  • #4 20942772
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14394
    Help: 650
    Rate: 12315
    Your script is not correct. After OnClick you need to put the P index of a button, not the command. You are also missing backlog required to run multiple commands.

    Futhermore, I'd suggest converting it to a script thread so we can have a delay between SendGet's.

    We don't have support for RULE syntax because we've decided that we can improve that part in OBK and make it more flexible.

    Create autoexec.bat , 10 is P10, it assumes Btn_ScriptOnly is on P10, change if required
    
    // set button hold times
    SetButtonTimes 20 3 3
    
    addEventHandler OnClick 10 startScript lights_on.bat *
    
    

    Create lights_on.bat:
    
    SendGet http://192.168.0.100/cm?cmnd=Power0%20ON
    delay_s 1
    SendGet http://192.168.0.101/cm?cmnd=Power0%20ON
    delay_s 1
    SendGet http://192.168.0.102/cm?cmnd=Power0%20ON
    delay_s 1
    SendGet http://192.168.0.103/cm?cmnd=Power0%20ON
    delay_s 1
    SendGet http://192.168.0.104/cm?cmnd=Power0%20ON
    
    
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #5 20942833
    omniron
    Level 11  
    Posts: 114
    Help: 1
    Rate: 6
    How do I turn on the relay of the main unit (where I press it's button) itself?
    Like this?

    lights_on.bat *:

    Power0%20ON
    delay_s 1
    SendGet http://192.168.0.101/cm?cmnd=Power0%20ON
    delay_s 1
    SendGet http://192.168.0.102/cm?cmnd=Power0%20ON
    delay_s 1
    SendGet http://192.168.0.103/cm?cmnd=Power0%20ON
    delay_s 1
    SendGet http://192.168.0.104/cm?cmnd=Power0%20ON

    Also, do I need to change the button's function to Btn_ScriptOnly or is it default?

    Thanks.
  • ADVERTISEMENT
  • #6 20943960
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14394
    Help: 650
    Rate: 12315
    I think you'd benefit a lot from reading our docs:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md
    The %20 escape character is only used in URLs. So you want:
    
    Power0 ON
    delay_s 1
    SendGet http://192.168.0.101/cm?cmnd=Power0%20ON
    delay_s 1
    SendGet http://192.168.0.102/cm?cmnd=Power0%20ON
    delay_s 1
    SendGet http://192.168.0.103/cm?cmnd=Power0%20ON
    delay_s 1
    SendGet http://192.168.0.104/cm?cmnd=Power0%20ON
    



    omniron wrote:

    Also, do I need to change the button's function to Btn_ScriptOnly or is it default?

    See:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/ioRoles.md
    If you use Btn, you will still have all "automatic" button behaviours, so the first Power command for this device will not be needed.
    On the other hand, if you use Btn_ScriptOnly, then you will have to "automatic" button behaviour, button will be only for scripts.
    Helpful post? Buy me a coffee.
  • #7 20944199
    omniron
    Level 11  
    Posts: 114
    Help: 1
    Rate: 6
    I read and re-read those pages, but couldn't find questions like what the * behind lights_on.bat * does.
    So I ommited the *.
    Couldn't find that you should not send an HTTP request to self

    SendGet http://192.168.0.112/cm?cmnd=Power0%20ON


    But did know about URL %20 stuff, same with Tasmota, forgot to take the %20 stuff out, my apologies.

    Then this was the situation:

    After short pressing the button on the (main, 192.168.0.112) entrance unit
    main,   Tuya    192.168.0.112's own relay does not turn on (or off)
    remote, Tuya    192.168.0.113's relay does not turn on (or off)
    remote, Tasmota 192.168.0.114's all 3 relay do turn on
    
    After long pressing (2+ seconds) the button on the (main, 192.168.0.112) entrance unit
    main,   Tuya    192.168.0.112's own relay does not turn off (or on)
    remote, Tuya    192.168.0.113's relay does not turn of (or on)
    remote, Tasmota 192.168.0.114's all 3 relays turn off
    

    Tasomta's all relays turning on but not tuya was the hint.

    So the problem seems to be the "Power0" command in Tuya.
    Tasmota responds to "Power0" with "all relays on", but tuya seems to ignore "Power0" completely.
    A search on those github pages found several references to Power0 though.
    I had just copy/pasted that "Power0" here.
    Once I changed "Power0" to "Power1" (or anything but Power0), the Tuya units also worked.

    It works now!!
    THANK you very much again!!

    Added after 1 [hours] 29 [minutes]:

    I put an X10->smart plugs howto together, could any of you readers please try it out to see if it works as descibed please?
    Thanks!

    // ********************************
    // Simulate X10 All lights on / All lights off with tuya
    // ********************************
    // This implements X10's "All lights on / All lights off" functions on a tuya device with OpenBK7231T.
    // https://en.wikipedia.org/wiki/X10_(industry_standard)
    // The tuya unit used here is a Xenon SM-PW801-U2 (bad unit, bad company, very low range).
    // https://www.elektroda.com/rtvforum/topic4015180.html
    // You can add more units (Tasmota or tuya) to be controlled, here only two remote lights were used.
    // For this to work, you just need to change the switch (button) role and add some files to the unit .
    
    
    // ********************************
    // Set Button Role
    // ********************************
    // on your unit's webpage/IP (mine is at 192.168.0.112) , select "Launch web Application"
    // select "Config"
    // under "Pin Settings:"
    // find "10" and change "Btn_Tgl_All" to "Btn_ScriptOnly"  <- change this pin to your unit's setting
    // click "Save Pins" at the very bottom
    
    
    // ********************************
    // Create autoexec.bat file
    // ********************************
    // select "File System"
    // select "Create File"
    // name it "autoexec.bat" (depending on your browser confirm with "ok")
    // click on new "autoexec.bat"
    // copy and paste below
    
    SetButtonTimes 20 3 3                                   // set button long press time to 2 seconds
    addEventHandler OnClick 10 startScript AllLights_on.bat // short pressing the button calls AllLights_on.bat
    addEventHandler OnHold 10 startScript AllLights_off.bat // long pressing (2+ seconds) the button calls AllLights_on.bat
    
    // click "Save"
    
    
    // ********************************
    // Create AllLights_on.bat file
    // ********************************
    // select "Create File" again
    // name it  "AllLights_on.bat" (depending on your browser confirm with "ok")
    // click on new "AllLights_on.bat"
    // copy and paste below
    
    Power1 ON                                         // turns own unit's relay1 on
    delay_s 1
    SendGet http://192.168.0.113/cm?cmnd=Power2%20ON  // turns remote Tasmota or tuya unit's relay2 on
    delay_s 1
    SendGet http://192.168.0.114/cm?cmnd=Power3%20ON  // turns remote Tasmota or tuya unit's relay3 on
    
    // click "Save"
    
    
    // ********************************
    // Create AllLights_off.bat file
    // ********************************
    // select "Create File" again
    // name it "AllLights_off.bat" (depending on your browser confirm with "ok")
    // click on new "AllLights_off.bat"
    // change the IP's to your settings
    // copy and paste below
    
    Power1 OFF                                         // turns own unit's relay1 off
    delay_s 1
    SendGet http://192.168.0.113/cm?cmnd=Power2%20OFF  // turns remote Tasmota or tuya unit's relay2 off
    delay_s 1
    SendGet http://192.168.0.114/cm?cmnd=Power3%20OFF  // turns remote Tasmota or tuya unit's relay3 off
    
    // click "Save"
    
    
    // ********************************
    // Reboot Unit to Apply New Feature
    // ********************************
    // back at unit's webpage/IP, click "Restart" 
    
  • ADVERTISEMENT
  • #8 21052330
    omniron
    Level 11  
    Posts: 114
    Help: 1
    Rate: 6

    Hi
    after flashing to
    Build on Apr 3 2024 07:20:17 version 1.17.532
    my precious autoexec etc files were gone!
    It was a work in progress and I hadn't backed up those files yet.
    A) is losing FS files normal?

    Since then even the simple (see prior post) autoexec and other files don't work anymore.
    If I set it to Btn it switches normally, but when I use Btn_scriptonly setting and add those files above nothing works!
    B) what can I do to restore script functionality? Reflash? go back to the last good version (don't even know which one that was).

    C) is there a remote press button command I could enter in the command tool window?
    I tried different commandos like setButtonCommand 10 11 etc but nothing worked.
    Something like "pressbutton X Y" where X is the button pin (pin 10 in my case) and y=11 is "keep pressed time" (for 1.1 seconds pressing in my case).
    This unit is at the other side of the building and laptop is cumbersome and phone too small for my old eyes.
    Would be great to have such a "remotely press button" simulation tool.
    Thanks!
  • #9 21052470
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14394
    Help: 650
    Rate: 12315
    omniron wrote:

    Hi
    after flashing to
    Build on Apr 3 2024 07:20:17 version 1.17.532
    my precious autoexec etc files were gone!
    It was a work in progress and I hadn't backed up those files yet.
    A) is losing FS files normal?

    It's a recurring bug due to the OTA file size growing, we will update WebApp to have a warning or something

    omniron wrote:

    Since then even the simple (see prior post) autoexec and other files don't work anymore.
    If I set it to Btn it switches normally, but when I use Btn_scriptonly setting and add those files above nothing works!
    B) what can I do to restore script functionality? Reflash? go back to the last good version (don't even know which one that was).

    Autoexec.bat should work, just restore old script and it should be ok.

    omniron wrote:

    C) is there a remote press button command I could enter in the command tool window?
    I tried different commandos like setButtonCommand 10 11 etc but nothing worked.
    Something like "pressbutton X Y" where X is the button pin (pin 10 in my case) and y=11 is "keep pressed time" (for 1.1 seconds pressing in my case).
    This unit is at the other side of the building and laptop is cumbersome and phone too small for my old eyes.
    Would be great to have such a "remotely press button" simulation tool.
    Thanks!

    Interesting, we haven't anything like that, but I may add this in the future.
    Helpful post? Buy me a coffee.
  • #10 21052554
    omniron
    Level 11  
    Posts: 114
    Help: 1
    Rate: 6

    Thank you for your reply.
    I didn't back up those files unfortunately, was still working on the scripts.
    One button / relay would turn on several other units, and when pressed long turn them off.
    And the other relay was powering the balcony light per the new sunrise and sunset program, but all that is all lost now.

    I cannot even get this going anymore:

    // Simulate X10 All lights on / All lights off with tuya

    autoexec.bat file
    SetButtonTimes 20 3 3 // set button long press time to 2 seconds
    addEventHandler OnClick 10 startScript AllLights_on.bat // short pressing the button calls AllLights_on.bat
    addEventHandler OnHold 10 startScript AllLights_off.bat // long pressing (2+ seconds) the button calls AllLights_on.bat

    AllLights_on.bat
    Power1 ON // turns own unit's relay1 on
    delay_s 1
    SendGet http://192.168.0.113/cm?cmnd=Power2%20ON // turns remote Tasmota or tuya unit's relay2 on
    delay_s 1
    SendGet http://192.168.0.114/cm?cmnd=Power3%20ON // turns remote Tasmota or tuya unit's relay3 on

    AllLights_off.bat file
    Power1 OFF // turns own unit's relay1 off
    delay_s 1
    SendGet http://192.168.0.113/cm?cmnd=Power2%20OFF // turns remote Tasmota or tuya unit's relay2 off
    delay_s 1
    SendGet http://192.168.0.114/cm?cmnd=Power3%20OFF // turns remote Tasmota or tuya unit's relay3 off

    so sad, took me much time to physically mount this ^x*@#$ unit.
  • #11 21064578
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14394
    Help: 650
    Rate: 12315
    Comments in single line with command are not supported. Futhermore, startScript may require an asterix, so do:
    
    // short pressing the button calls AllLights_on.bat
    addEventHandler OnClick 10 startScript AllLights_on.bat *
    

    See:
    Documentation snippet showing the startScript command highlighted in orange.
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands-extended.md
    Helpful post? Buy me a coffee.
  • #12 21064929
    omniron
    Level 11  
    Posts: 114
    Help: 1
    Rate: 6
    Can't believe it was that simple, saw those // but never thought they cannot be on same line, sorry.
    So I have to correct this example at bottom of
    https://www.elektroda.com/rtvforum/topic4033215.html#20944199
    also?
    Added the * and it works again, thank you!
    Am backing up the files on my unit this time.

    Added after 4 [minutes]:

    Finally, no more walking all the way to the end of the home/hallway just to press the buttons (for testing of the scripts) on this rear door unit...

Topic summary

✨ The discussion revolves around converting Tasmota button rules for use in OpenBeken (OBK) on the BK7231 device. The user seeks guidance on translating Tasmota commands, particularly regarding the differences in syntax and functionality between Tasmota and Tuya. Key points include the use of SendGet commands to control multiple devices, setting button hold times, and creating scripts for automation. The conversation highlights the need for proper syntax, such as using the correct button index and ensuring commands are executed in the right order. Issues with file loss after firmware updates and the need for backup are also addressed, along with troubleshooting steps for restoring script functionality.
Generated by the language model.

FAQ

TL;DR: Use scripts, not RULES: “We don’t have support for RULE syntax.” Add 1‑second SendGet delays and map button events. [Elektroda, p.kaczmarek2, post #20942772]

Why it matters: This helps Tasmota users migrate scenes to OpenBeken on BK7231/Tuya without MQTT or RULES.

Quick Facts

How do I translate a Tasmota Rule to OpenBeken BK7231?

Replace Tasmota RULES with event handlers and scripts. Create autoexec.bat, set hold times, and map OnClick to startScript. Then put PowerN and SendGet lines into a .bat script, adding delay_s between calls. OBK dropped RULE syntax in favor of flexible scripts. How-To:
  1. Create autoexec.bat with SetButtonTimes and addEventHandler OnClick 10 startScript lights_on.bat.
  2. Create lights_on.bat with Power1 ON and SendGet lines.
  3. Add delay_s 1 between SendGet calls for reliability. [Elektroda, p.kaczmarek2, post #20942772]

What goes after OnClick in OpenBeken?

Use the button’s P index, not a command. Example: addEventHandler OnClick 10 startScript lights_on.bat. If you need multiple actions, run them inside the script, not directly after OnClick. Scripts let you sequence actions with delays instead of backlog. [Elektroda, p.kaczmarek2, post #20942772]

How do I switch the local relay and remote devices together?

Run a local PowerN command, then SendGet to remotes. Example: Power1 ON, then SendGet http://IP/cm?cmnd=PowerX%20ON per device. Don’t URL‑encode local commands. “The %20 escape character is only used in URLs.” Add delay_s between commands for stability. [Elektroda, p.kaczmarek2, post #20943960]

Why does Power0 not work on OpenBeken like in Tasmota?

Power0 (all channels) isn’t implemented in OBK. Use explicit channels like Power1, Power2, etc. Users reported nothing happened with Power0, but replacing it with Power1 restored control on OBK devices, while Tasmota still honored Power0. [Elektroda, omniron, post #20944199]

How can I add safe delays between HTTP commands?

Put SendGet calls in a script thread and insert delay_s 1 between them. The developer’s example sequences multiple Power0 ON calls with 1‑second spacing to avoid congestion and ensure ordering. This pacing improves reliability in multi‑device scenes. [Elektroda, p.kaczmarek2, post #20942772]

Btn vs Btn_ScriptOnly: which should I choose?

Use Btn to keep automatic toggle behavior; you won’t need an initial local Power command. Use Btn_ScriptOnly to disable automatic behavior so the button only triggers scripts. Choose based on whether you want the relay to toggle by default. [Elektroda, p.kaczmarek2, post #20943960]

Why didn’t my autoexec.bat run? What did I miss?

Two common pitfalls: inline comments and missing asterisk. “Comments in single line with command are not supported.” Put // on its own line. Also, add an asterisk to startScript lines when needed: addEventHandler OnClick 10 startScript AllLights_on.bat *. [Elektroda, p.kaczmarek2, post #21064578]

How do I find the correct P index for my button?

Match the button’s configured pin role to its P index. In the example, 10 means P10. If your button is on another pin, replace 10 accordingly in addEventHandler OnClick 10. Confirm roles on the device’s Pin Settings page. [Elektroda, p.kaczmarek2, post #20942772]

How do I implement short press = ON and long press = OFF?

Set button times, then map handlers. Example: SetButtonTimes 20 3 3, addEventHandler OnClick 10 startScript AllLights_on.bat, and addEventHandler OnHold 10 startScript AllLights_off.bat. Put Power1 ON/OFF locally and SendGet lines for remotes in each script. [Elektroda, omniron, post #20944199]

Should I SendGet to the same device or run commands locally?

Run commands locally when controlling the same device. Use PowerN ON/OFF directly, and reserve SendGet for remote Tasmota or OBK targets. The developer’s example shows local Power commands and URL‑encoded cmnd strings for remotes only. [Elektroda, p.kaczmarek2, post #20943960]

My scripts vanished after an OTA update. What happened?

A known OTA size issue can wipe the filesystem during update. The developer acknowledged recurring losses and plans UI warnings. Restore your autoexec.bat and script files from backup, then retest handlers. Re‑create them if no backup exists. [Elektroda, p.kaczmarek2, post #21052470]

Can I simulate a button press remotely from the console?

Not yet. The developer confirmed there is no remote button press command currently and may add it in the future. For testing, call startScript directly or operate the GPIO input physically. [Elektroda, p.kaczmarek2, post #21052470]

How do I send a Tasmota command string from OpenBeken?

Use SendGet with the Tasmota HTTP API: SendGet http:///cm?cmnd=Power0%20ON. Replace spaces with %20 and ensure the target device accepts the command. Test in the console before scripting for consistency. [Elektroda, p.kaczmarek2, post #20942619]
Generated by the language model.
ADVERTISEMENT