logo elektroda
logo elektroda
X
logo elektroda

OpenBeken Configuring Open/Stop/Close buttons on a Smart Life switch

richardsg307 2481 16
ADVERTISEMENT
  • #1 20544322
    richardsg307
    Level 5  
    I've flashed and partially configured a Smart Life Switch but I'm struggling with triggering scripts or backlog commands in the event of a button click. I'm familiar with Tasmota but have never used OpenBeken before.
    Here's the unit with the front panel removed:
    OpenBeken Configuring Open/Stop/Close buttons on a Smart Life switch
    Current configuration is Open btn, Open LED, Open Relay all on Ch 1, Stop btn & Stop LED on Ch 2, Close btn, Close LED and Close Relay all on Ch 3. No Channel Types have been set. I have an autoexec.bat file to label the buttons on the GUI and close the window.
    // Add names to the buttons
    setChannelLabel 1 Open 1
    setChannelLabel 2 Stop 1
    setChannelLabel 3 Close 1
    // Close window
    setChannel 1 0
    setChannel 2 0
    setChannel 3 1
    delay_s 10
    setChannel 3 0
    setChannel 2 1
    delay_s 3
    setChannel 2 0
    addEventHandler OnChannelChange 2 backlog setchannel 1 0; setchannel 2 1; setchannel 3 0; delay_s 3; setchannel 2 0

    But the Event Handler doesn't work when I click the Stop btn!
    ATM I'd like it to behave like it did with the Tuya firmware.
    On Open btn click, it should ensure the Close Relay is not on, then turn on the Open Relay and Open LED for 10 seconds then turn both off, then it should turn on the Stop LED for 3 seconds. The Close btn should do the opposite. The Stop btn should turn both relays off (Either one could be on) then turn on the Stop LED for 3 seconds.
    So I just need a bit of help linking the btn clicks to some action. Also, should I use different channels for the buttons away from the relays/LEDs to stop any automatic linkage. I don't want both relays on at the same time as that could blow up the actual opener itself!
    I will be writing this up as a project and new device in the repository when I'm done.
    Thanks in advance.
  • ADVERTISEMENT
  • #2 20545521
    p.kaczmarek2
    Moderator Smart Home
    Hello, first of all, what kind of behaviour are you trying to achieve? Is it supposed to be a shutter controller?

    Instead of delay_s 3, in backlog, you should use addRepeatingEvent 3 1 <command>, delay_s can now work inside a script thread, not yet in backlog.

    I can write following script if you want:
    Quote:

    On Open btn click, it should ensure the Close Relay is not on, then turn on the Open Relay and Open LED for 10 seconds then turn both off, then it should turn on the Stop LED for 3 seconds. The Close btn should do the opposite. The Stop btn should turn both relays off (Either one could be on) then turn on the Stop LED for 3 seconds.

    I wouldn't use channel labels for that. I would use scriptable buttons. But, is it a shutter controller? I can see tonight what I can get working for you.
    Helpful post? Buy me a coffee.
  • #3 20545650
    richardsg307
    Level 5  
    Yes, It's a 'Shutter' in concept but in this case it is opening/shutting a Skylight.
    OpenBeken Configuring Open/Stop/Close buttons on a Smart Life switch
    It's a 4 Wire system - Earth, Neutral, Live/Open and Live/Close. So i need either of the 2 Relays to be on but definitely not both. The way the switch operated with the Tuya firmware was that after about 10 seconds (presumably long enough for the window to be opened/closed, both relays went off (to save power and isolate the mechanism I guess).
    Within the File System I have created 3 simple script files. eg for closing, the close.bat file ensures that the Open relay is off before turning on the Close relay, waiting 10 seconds and then turning it off. It then turns the Stop Channel or LED on for just 3 seconds.
    / Close - Turns Open relay off, then turns Close relay on for 10s
    // Then shows Stop LED for 3s
    setchannel 1 0
    setchannel 2 0
    delay_ms 250
    setchannel 3 1
    delay_s 10
    setchannel 3 0
    setchannel 2 1
    delay_s 3
    setchannel 2 0
    
    Similar for the stop.bat and open.bat scripts. They all work when I press the "Save, Run file as script thread" button in the web interface.
    What I cannot figure out is how to get the scripts to run on a button click. I've tried adding event handlers in the autoexec.bat file but nothing seems to work.
    // Add names to the buttons
    setChannelLabel 1 Open 1
    setChannelLabel 2 Stop 1
    setChannelLabel 3 Close 1
    setChannel 1 0
    setChannel 2 0
    setChannel 3 1
    echo "Closing Skylight"
    delay_s 10
    setChannel 3 0
    echo "Loading Event Handlers"
    addEventHandler OnClick 1 startScript open.bat * 123

    I'm just missing something, so a few pointers in the right direction would help.
    On a side note - where do the echos get written out?
    Thanks
  • #4 20545686
    p.kaczmarek2
    Moderator Smart Home
    Ok, I will prepare an example for you, but first, can you tell me what should happen if user press open button and then after 1 second the close?
    a) open should interrupt and close should start
    b) open should continue and ignore close request
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #5 20545712
    richardsg307
    Level 5  
    Thanks. I think Option a).
  • Helpful post
    #6 20545714
    p.kaczmarek2
    Moderator Smart Home
    Maybe it would be better if I just create a dedicated driver for shutters? It seems your use case is very generic.

    Added after 3 [minutes]:

    Here is a untested (BE CAREFUL!) script idea:
    
    
    // Channel 10 - Relay 1
    // Channel 11 - Relay 2
    
    alias Set_Up setChannel 10 0; setChannel 11 1
    alias Set_Down setChannel 10 1; setChannel 11 0
    alias Set_None setChannel 10 0; setChannel 11 0
    
    // command "Start_Opening" will first kill other script threads, and start with clear open
    alias Start_Opening backlog stopAllScripts; startScript autoexec.bat openShutter
    // command "Start_Closing" will first kill other script threads, and start with clear close
    alias Start_Closing backlog stopAllScripts; startScript autoexec.bat closeShutter
    // command "Start_Closing" will first kill other script threads, and then stop
    alias Stop_All backlog stopAllScripts; Set_None
    
    // create GUI buttons for HTTP panel
    startDriver httpButtons
    setButtonEnabled 0 1
    setButtonLabel 0 "Open"
    setButtonCommand 0 Start_Opening
    
    setButtonEnabled 1 1
    setButtonLabel 1 "Close"
    setButtonCommand 1 Start_Closing
    
    setButtonEnabled 2 1
    setButtonLabel 2 "Stop"
    setButtonCommand 2 Stop_All
    
    // link the same commands to physical button on GPIO pins
    // 8 and 9 are GPIO indices, like P9, etc
    addEventHandler OnClick 8 Start_Opening
    addEventHandler OnClick 9 Start_Closing
    addEventHandler OnClick 10 Stop_All
    
    // do not proceed
    return
    
    // Script thread for opening
    openShutter:
    // setup none
    Set_None
    // wait 0.1 seconds
    delay_s 0.1
    // setup up
    Set_Up
    // wait 10 seconds
    delay_s 10
    Set_None
    // done
    return
    
    // Script thread for closing
    closeShutter:
    // setup none
    Set_None
    // wait 0.1 seconds
    delay_s 0.1
    // setup down
    Set_Down
    // wait 10 seconds
    delay_s 10
    Set_None
    // done
    return
    
    Helpful post? Buy me a coffee.
  • #7 20545826
    richardsg307
    Level 5  
    I'll give it a go once I understand it. I have the switch mounted in a test box at the moment with nothing wired to the relays so it should be safe!
    I'll report back.

    Update:
    Nearly there! I have 3 questions...
    1) [Solved] Can I disable the default buttons since the autoexec created its own? The problem is - with the default buttons I can have both the Open and Close relays on together! Can I disable them or perhaps make them run the same event handlers as the HTTP GUI buttons? (Found it - setChannelVisible command)
    2) [Solved] What is the number of the RXD1 pin for use in the addEventHandler OnClick command. RXD1 is the input from the Pause/Stop button on my panel! (Found it - RXD1 is Pin 10 and TXD1 is Pin 11)
    3) [Solved] I've connected via MQTT to Home Assistant and used the YAML code as given in the HA Cfg page but this only lets me turn the individual relays on or off. How can I send a command to activate the Open or Close scripts? (Found it - publish MQTT topic cmnd/skylight/Start_Opening where Start_Opening is the Alias of the routine that opens the skylight)

    I will wire up the opener tomorrow and if all good submit the whole thing as a teardown.
  • ADVERTISEMENT
  • #8 20548654
    richardsg307
    Level 5  
    >>20545714
    All sorted now and I've submitted a teardown thing with all the configurations and code. I think it's still pending at the moment. Do I get a free SD card?
  • #9 20548745
    p.kaczmarek2
    Moderator Smart Home
    Yes, you did a great job with that guide. We'll send you a PM. Remember that you can post another one as well.
    Helpful post? Buy me a coffee.
  • #10 20552378
    mbolty
    Level 3  
    OpenBeken Configuring Open/Stop/Close buttons on a Smart Life switch Hello, I have a cb2s module. I tried to enter the code to be able to use it as a shutter module by adding a second relay and a second push button, but it doesn't work for me. the code of the autoexec.bat is the following:
    // Channel 1 - Relay 1
    // Channel 2 - Relay 2
    setChannelVisible 1 0
    setChannelVisible 2 0
    
    alias Set_Up setChannel 1 0; setChannel 2 1
    alias Set_Down setChannel 2 0; setChannel 1 1
    alias Set_None setChannel 1 0; setChannel 2 0
    
    // command "Start_Opening" will first kill other script threads, and start with clear open
    alias Start_Opening backlog stopAllScripts; startScript autoexec.bat openShutter
    // command "Start_Closing" will first kill other script threads, and start with clear close
    alias Start_Closing backlog stopAllScripts; startScript autoexec.bat closeShutter
    // command "Start_Closing" will first kill other script threads, and then stop
    alias Stop_All backlog stopAllScripts; set_none
    
    // create GUI buttons for HTTP panel
    startDriver httpButtons
    setButtonEnabled 0 1
    setButtonLabel 0 "Open"
    setButtonCommand 0 Start_Opening
    
    setButtonEnabled 1 1
    setButtonLabel 1 "Close"
    setButtonCommand 1 Start_Closing
    
    setButtonEnabled 2 1
    setButtonLabel 2 "Stop"
    setButtonCommand 2 Stop_All
    
    // link the same commands to physical button on GPIO pins
    // 8 and 9 are GPIO indices, like P9, etc
    addEventHandler OnClick 24 Start_Opening
    addEventHandler OnClick 26 Start_Closing
    addEventHandler OnClick 10 Stop_All
    
    // do not proceed
    return
    
    // Script thread for opening
    openShutter:
    // setup none
    set_none
    // wait 0.1 seconds
    delay_s 0.1
    // set up
    Set_Up
    //wait 10 seconds
    delay_s 10
    set_none
    // done
    return
    
    // Script thread for closing
    closeShutter:
    // setup none
    set_none
    // wait 0.1 seconds
    delay_s 0.1
    // setup down
    Set_Down
    // wait 10 seconds
    delay_s 10
    set_none
    // done
    return

    But none of the outputs are activated.
    Please I appreciate any help
    OpenBeken Configuring Open/Stop/Close buttons on a Smart Life switch OpenBeken Configuring Open/Stop/Close buttons on a Smart Life switch OpenBeken Configuring Open/Stop/Close buttons on a Smart Life switch OpenBeken Configuring Open/Stop/Close buttons on a Smart Life switch


    Log:

    Info:CMD:CMD_StartScript: started autoexec.bat at label openShutter
    Info:CMD:[WebApp Cmd 'Start_Opening' Result] OK
    Info:GEN:No change in channel 1 (still set to 0) - ignoring

    Info:GEN:No change in channel 1 (still set to 0) - ignoring

    Info:MAIN:Time 451, idle 160941/s, free 68640, MQTT 1(2), bWi
  • #11 20552440
    p.kaczmarek2
    Moderator Smart Home
    Please edit post and use code tag to post code.

    Please attach some screenshot of your device pin configuration. Have you set the Relay roles for correct GPIOs and assigned the channels to them?

    Have you seen shutter tutorial?
    https://www.elektroda.com/rtvforum/topic3972935.html
    Helpful post? Buy me a coffee.
  • #12 20552484
    mbolty
    Level 3  
    Thanks, I had already read the post. I edited my post and added an image of the configuration and a part of the log.
  • ADVERTISEMENT
  • #13 20552493
    p.kaczmarek2
    Moderator Smart Home
    I can see you have two relays, one on channel 1 and second on channel 2.

    If you change the channel states from www panel, do relays click?
    Helpful post? Buy me a coffee.
  • #14 20552569
    mbolty
    Level 3  
    I have already solved.
    
    //Configurar alias  Aliases
    alias Set_Stop backlog setChannel 2 0; setChannel 1 0
    alias Set_Open backlog setChannel 1 1
    alias Set_Close backlog setChannel 2 1
    alias Start_Opening backlog stopAllScripts; startScript autoexec.bat openBlind
    alias Start_Closing backlog stopAllScripts; startScript autoexec.bat closeBlind
    alias Stop_All backlog stopAllScripts; startScript autoexec.bat stopBlind
    
    // Channel 60 segundos de trabajo
    setChannel 60 15
    
    //crear botones GUI  para el panel HTTP
    startDriver httpButtons
    
    setButtonEnabled 1 1
    setButtonLabel 1 "Open"
    setButtonCommand 1 Start_Opening
    
    setButtonEnabled 3 1
    setButtonLabel 3 "Close"
    setButtonCommand 3 Start_Closing
    
    setButtonEnabled 2 1
    setButtonLabel 2 "Stop"
    setButtonCommand 2 Stop_All
    setButtonColor 2 red
    
    // Ocultar los botones de los reles en la  GUI HTTP
    setChannelVisible 1 0
    setChannelVisible 2 0
    setChannelVisible 3 0
    
    // Cargar Event Handlers
    addEventHandler OnHold 26 Start_Closing
    addEventHandler OnHold 24 Start_Opening
    addEventHandler OnClick 11 Stop_All
    
    // Detener persiana al encender
    goto stopBlind
    return
    
    // Script abrir
    openBlind:
    Set_Stop
    delay_s 0.1
    Set_Open
    delay_s $CH60
    Set_Stop
    return
    
    // Script cerrer
    closeBlind:
    Set_Stop
    delay_s 0.1
    Set_Close
    delay_s $CH60
    Set_Stop
    return
    
    // Script detener
    stopBlind:
    Set_Stop
    return
    




    I only have one question, in the value of $CH60. The value could not be sent by MQTT by Home Assistant to be able to modify it according to the time of each motor?
    Thank you so much
    (I will send photos of the finished project)
  • #15 20552977
    richardsg307
    Level 5  
    In the end, I found that I could press the Open window button a second time and it would open a bit (lot) more. To shut it I needed longer so I changed that code back to a number like 25 (seconds) just to make sure it was closed no matter how far I'd opened it. The actuator has a cut-out when it reaches its closed position or when the window itself is shut (before the actuator closed position) and the motor stalls.
  • #16 20553095
    p.kaczmarek2
    Moderator Smart Home
    Very good job,
    mbolty wrote:

    I only have one question, in the value of $CH60. The value could not be sent by MQTT by Home Assistant to be able to modify it according to the time of each motor?


    By default, channels are only send if they are used for basic IO, but this behaviour can be overridden.
    I will give you two methods:
    1. Just manually publish channel value
    
    addEventHandler OnChannelChange 30 publishInt myCustomValue $CH30 
    

    2. You can also update OpenBeken to latest version, and then make sure you are using channel up to 31, and then in Web App change type:
    OpenBeken Configuring Open/Stop/Close buttons on a Smart Life switch
    If you set type, for example to "Custom", Obk will know there is something in this channel and it will publish it when it changes.
    OpenBeken Configuring Open/Stop/Close buttons on a Smart Life switch
    Keep in mind that you can also set any channel easily via MQTT.
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/mqttTopics.md
    Helpful post? Buy me a coffee.
  • #17 20556900
    mbolty
    Level 3  
    Hello, I have corrected my autoexec.bat and I have created some sensors and automations in home assistant.
    I would like to know your opinion and if it is possible to improve what I have created.
    Thank you all.
    
    //Configurar alias  Aliases
    alias Set_Stop backlog setChannel 2 0; setChannel 1 0
    alias Set_Open backlog setChannel 1 1
    alias Set_Close backlog setChannel 2 1
    alias Start_Opening backlog stopAllScripts; startScript autoexec.bat openBlind
    alias Start_Closing backlog stopAllScripts; startScript autoexec.bat closeBlind
    alias Stop_All backlog stopAllScripts; startScript autoexec.bat stopBlind
    
    // Channel 31 segundos de trabajo por defecto configurable por mqtt
    setChannel 31 5
    //crear botones GUI  para el panel HTTP
    startDriver httpButtons
    
    setButtonEnabled 1 1
    setButtonLabel 1 "Open"
    setButtonCommand 1 Start_Opening
    
    setButtonEnabled 3 1
    setButtonLabel 3 "Close"
    setButtonCommand 3 Start_Closing
    
    setButtonEnabled 2 1
    setButtonLabel 2 "Stop"
    setButtonCommand 2 Stop_All
    setButtonColor 2 red
    
    // Ocultar los botones de los reles en la  GUI HTTP
    setChannelVisible 1 0
    setChannelVisible 2 0
    setChannelVisible 3 0
    setChannelVisible 31 1
    setChannelVisible 32 0
    setChannelVisible 60 0
    
    // Cargar Event Handlers
    addEventHandler OnClick 26 Start_Closing
    addEventHandler OnClick 24 Start_Opening
    addEventHandler OnClick 10 Stop_All
    
    // Detener persiana al encender
    goto stopBlind
    return
    
    openBlind:
    Set_Stop
    delay_s 0.1
    Set_Open
    publish state_topic opening
    delay_s $CH31
    Set_Stop
    publish state_topic open
    return
    
    closeBlind:
    Set_Stop
    delay_s 0.1
    Set_Close
    publish state_topic closing
    delay_s $CH31
    publish state_topic close
    Set_Stop
    return
    
    stopBlind:
    Set_Stop
    publish state_topic stopped
    return
    

    
    sensor:
        - name: "estado persiana"
          state_topic: "obk_02/state_topic/get"
        - name: "tiempo persiana"
          state_topic: "obk_02/31/get"
    

    
    alias: timeblindha_2device
    description: send work time to device from home assistant
    trigger:
      - platform: state
        entity_id:
          - input_button.set_tiem_blind
    condition: []
    action:
      - service: mqtt.publish
        data:
          qos: 0
          retain: false
          topic: obk_02/31/set
          payload_template: "{{ states('input_number.timepersiana')|float }}"
    mode: single
    

    
    alias: timeblind_device2ha
    description: synchronize device working time with home assistant
    trigger:
      - platform: mqtt
        topic: obk_02/31/get
    condition: []
    action:
      - service: input_number.set_value
        data:
          value: "{{ states('sensor.tiempo_persiana')|float }}"
        target:
          entity_id: input_number.timepersiana
    mode: single
    

    Create the button "input_button.set_tiem_blind" so that the new work time is only sent when the button is clicked and not when the value of "input_number.set_value" is modified.
    I am waiting for the relays to arrive to add them to the modules.

Topic summary

The discussion revolves around configuring OpenBeken firmware for a Smart Life switch to control a skylight shutter. The user seeks assistance in triggering scripts for button clicks, having previously worked with Tasmota but not with OpenBeken. Various solutions are proposed, including using scriptable buttons instead of channel labels, and creating dedicated drivers for shutter control. The user describes their setup, including relay configurations and the need for specific timing in relay activation. They also inquire about disabling default buttons to prevent simultaneous relay activation and how to integrate with Home Assistant via MQTT. Ultimately, the user successfully implements their configuration and shares their findings with the community.
Summary generated by the language model.
ADVERTISEMENT