logo elektroda
logo elektroda
X
logo elektroda

[OpenBeken] Push button actions multi press and hold down etc

matt303 8403 37
ADVERTISEMENT
  • #31 20619006
    p.kaczmarek2
    Moderator Smart Home

    It looks like you are looking for OnHoldStart event.
    https://github.com/search?q=repo%3Aopenshwprojects%2FOpenBK7231T_App%20OnHoldStart&type=code
    Well, I admit, it seems the docs for that part are not ready yet. I will have to find some time for that.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #32 20619638
    jrhenk
    Level 10  

    Ah perfect, would have bet you already thought about this scenario and added an option for it :) And indeed, this could have been documented somewhere but then again you are really active here so with a bit of googling people can get there already.

    Maybe fun to hear what I did with this: I now choose between either OnPress together with OnHoldStart or OnClick together with OnHoldStart. The first one works great if I only rarely use the second option with the button or don't mind it doing two things. For a LED strip e.g. OnPress changes the preset (and switches power on when off) and OnHoldStart switches the power to the strip off, and in that case I really don't care if it also changes the preset before switching off when I can enjoy a snappier reaction for changing presets.
  • ADVERTISEMENT
  • #33 20619718
    p.kaczmarek2
    Moderator Smart Home

    I can see how that can be a dilemma. You could just use onClick instead of onPress, but then again, you wouldn't get an immediate reaction to touches.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #34 20622075
    jrhenk
    Level 10  

    Well, you always have to make a choice, and this double function with OnPress and OnHoldStart is also a fun thing for guests :)

    Now that I get what to do with the OnClick etc button triggers, I would like to fully understand the syntax for relay/power states as triggers. My goal is to use the first button for controlling the first relay onclick but to do something else on hold. I managed to make button1 toggle relay1 but since the LED of the button is decoupled from the button and the relay, the LED does not light up when the relay is on, so this is what I want to achieve.

    In my case, the LED that should turn on when the relay is on is power4 (pin14), the first relay is power1 (pin6). I thought it could be as easy as something like "addeventhandler poweron 14 power4 on" but just guessing the trigger and syntax for this wasn't yet successful :) Then I saw addchangehandler, which might need to be used here instead, but I do not really understand the syntax. How could I make the first LED switch on when the relay is turned on?
  • #35 20622349
    p.kaczmarek2
    Moderator Smart Home

    First of all - why don't you set the LED channel to the same channel as the relay has? So they are in the same group?
    Helpful post? Buy me a coffee.
  • #36 20622508
    jrhenk
    Level 10  
    I noticed that if I set the relays to 1, 2, 3 and the LEDs to 4, 5, 6 that the LEDs turn up as separate lights/switches, also in HA, which makes it far easier to control them in automations, e.g. when a light that's not physically attached to the switch switches on, I can just add a little action to switch a LED on that switch to indicate that. As a workaround, I did the same for this LED now.

    But now that you are mentioning groups, could I just put the relay and the LED in a group so they change state together? How would I do that? I just saw the group menu item, but there I only see the option for the whole device to listen to group commands.
  • #37 20622515
    p.kaczmarek2
    Moderator Smart Home

    By groups, I mean channels. Just set the relay and LED to the set channel.

    If not, you can do that:
    
    addEventHandler OnChannelChange 2 setChannel 20 $CH2
    

    When channel 2 changes, set channel 20 to the value from channel 2.
    Or:
    
    addChangeHandler Channel2 == 0 setChannel 20 1
    addChangeHandler Channel2 == 1 setChannel 20 0
    

    When channel 2 changes to 0, set 20 to 1. When 2 changes to 1, set 20 to 0.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #38 20622560
    jrhenk
    Level 10  

    Ah ok, I misunderstood. But thanks so much for this code, works perfectly! And in addition, I now understand the addchangehandler syntax, which opens a door to do even more.

    What I noticed btw: Openbk uses the autostart.bat commands much faster/more efficiently than Tasmota uses rules. With rules (and the optically identical switches from Athom), you actually notice the position of a command - so when I put a publish MQTT command before a command for the LEDs, I notice a delay for the LEDs, which goes away if I turn the commands around. With Openbk, I don't have to care about this - it's really amazing that in this short amount of time, your project already surpassed Tasmota in this and several other aspects!

Topic summary

The discussion revolves around the implementation of multi-press and hold actions for Tuya devices using the OpenBeken firmware, specifically targeting devices with the BK7231N module. Users seek to replicate functionalities from Tasmota, such as controlling light brightness through various button presses and holds. The conversation includes scripting examples for button actions, event handling, and MQTT integration with Home Assistant (HA). Key features discussed include OnHoldStart, OnRelease events, and the need for improved documentation. Users also address issues with flashing devices, MQTT message delays, and the importance of Last Will and Testament (LWT) for device status updates in HA. Suggestions for enhancements, such as custom JSON for MQTT discovery and improved LED control, are also proposed.
Summary generated by the language model.
ADVERTISEMENT