logo elektroda
logo elektroda
X
logo elektroda

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

omniron 1527 11
ADVERTISEMENT
  • #1 20942170
    omniron
    Level 10  
    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
    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.
  • ADVERTISEMENT
  • #3 20942740
    omniron
    Level 10  

    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
    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.
  • #5 20942833
    omniron
    Level 10  
    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
    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.
  • ADVERTISEMENT
  • #7 20944199
    omniron
    Level 10  
    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" 
    
  • #8 21052330
    omniron
    Level 10  

    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
    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 10  

    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
    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 10  
    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.
Summary generated by the language model.
ADVERTISEMENT