logo elektroda
logo elektroda
X
logo elektroda

How to Rename openBK Switch Entity and Separate External Switch in HASS with BK7231N?

brazoayeye 177 7
ADVERTISEMENT
  • #1 21581787
    brazoayeye
    Level 4  
    I flashed without problems a device like this one
    I want to use the device with HASS in the most flexible way, I set with default parameters and they works without problems but i'm unable to understand if some features can be used with openBK or if the firmware doesn't support it
      "pins": {
        "6": "TglChanOnTgl;1",
        "7": "Rel;1",
        "23": "Btn_Tgl_All;0",
        "26": "WifiLED_n;0"
      },
      "command": "PowerSave 1",


    Since it can't work with HASS Api (Am I wrong?) I setup MQTT and I recive following informations in HASS:

    How to Rename openBK Switch Entity and Separate External Switch in HASS with BK7231N?

    Here my questions:
    1. Is there a way to change from openBK the "1" name for the switch with a more friendly one? Inside cfg_name i only see device name (Short, full).
    2. Is there a way to see the external switch as a separate identity keeping the switch function on the relay?

    I used another identical device with EspHome with following config:
    esphome: 
      name: "aubess-switch-4"
    bk72xx: 
      board: generic-bk7231n-qfn32-tuya
    
    # Enable Home Assistant API
    api:
    logger:
    ota:
      platform: esphome
    
    wifi:
      power_save_mode: HIGH
      networks:
        - ssid: "Dim-GB"
          password: !secret wifi_password
    
      # Enable fallback hotspot (captive portal) in case wifi connection fails 
      ap: 
    
    binary_sensor: 
      - platform: gpio
        pin: 
          number: P23 
          mode: 
            input: true 
            pullup: true 
          inverted: true
        name: "PB_reset" 
        on_press: 
          - switch.toggle: relay
    
      - platform: gpio 
        pin: 
          number: P6 
          mode: 
            input: true 
            pullup: True 
          inverted: true
        name: "PB_ext"
        on_press: 
          - switch.toggle: relay
        on_release: 
          - switch.toggle: relay
    
      - platform: status 
        name: "Status"
    
    sensor: 
      - platform: wifi_signal 
        update_interval: 30s 
        name: "signal"
      - platform: uptime
        name: "Uptime" 
    
    output: 
      - platform: gpio 
        pin: P26
        id: led
    
    switch: 
      - platform: gpio 
        name: "relay" 
        pin: P7 
        id: relay
        restore_mode: RESTORE_DEFAULT_OFF
        on_turn_on: 
          then: 
            - output.turn_on: led 
        on_turn_off: 
          then: 
            - output.turn_off: led
    
    captive_portal: 


    But i read on internet that even with power_save_mode: HIGH che espHome consumption is much higher than openBK with startup "PowerSave 1".
    Does someone have proof or tested that consumption (and how can you measure it?)

    Last, Is there a well known device with power monitor that I can buy and flash to be used locally without clouds?

    Thanks
  • ADVERTISEMENT
  • #2 21581797
    p.kaczmarek2
    Moderator Smart Home
    What is HASS API? we have HASS Discovery in OBK.

    1. Sure, use SetChannelLabel
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md
    2. You can set separate channel index for your button or whatever you want, you can also set channel type toggle for that in the web app and it should work good, along with HASS Discovery

    I don't recommend untested software, last time I checked they didn't even have powersave, but I seem to remember that one of our user just copied some of OBK power save to them, maybe not reliably, cause OBK power save requires less frequent tick for dynamic sleep to kick in.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 21581825
    brazoayeye
    Level 4  
    HASS discovery works, but it's an MQTT packet to be sent to HASS to describe the device.
    HASS API is described here and it's also written the main advantages. For me the main advantage is that there is nothing to set up, but also MQTT works well


    1. Perfect, I wrote in app -> Log -> Console "SetChannelLabel 1 switch". It would be useful to have the link you provided directly on the web UI near the console (I tried help w/o results)
    2. I set as shown above, but in hass I only see the switch

    How to Rename openBK Switch Entity and Separate External Switch in HASS with BK7231N?

    setting dInput I see the value in HASS but even if it's ok when I connect a bistable button, it's not good for a push button pressed very fast. It would be better to have a variable that toggles between on and off with the push so I'm sure to detect the push even with network latency.

    Many thanks
  • ADVERTISEMENT
  • #4 21582177
    p.kaczmarek2
    Moderator Smart Home
    Interesting, I'll think about it.

    2. I am not sure what do you mean, if you have switch in HA, then you can still use it in automations. Or do you really want to force it to be Read Only? Just allow change from OBK and disallow changes from HA? Then maybe try setting channel type.... ReadOnly. Maybe. Or please explain in detail and I will try to help futher.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #5 21582535
    brazoayeye
    Level 4  
    I'm sorry if I'm not clear, but I'm flashing all devices I have and I want to be sure to understand firmware capabilities.

    Here an example:
    module 1
    relay -> lamp1
    in <- button1 (monostable)
    module 2
    relay -> lamp2
    in <- button2 (monostable)

    with button 1 I want to switch lamp1
    with button 2 I want to turn off lamp 1 (I must give the informations to HASS, but if I use dInput the signal transmitted is 1 when button is pressed but a very fast click could be skipped for a network latency)
    I turn on and off the lamp2 from the app (relay from HASS)

    Is there a way to create a variable (not linked to an output) that flips every time the button is pressed?

    Thanks
  • #6 21582612
    p.kaczmarek2
    Moderator Smart Home
    Is this like the classic "bulb and switch" situation? I think we have a lot of capabilities..

    1. you could use Tasmota Device Groups and it would work without HA, set the same group on both device, set channel 1 to be used
    2. You can use just Btn pin for monostable button on device 2, Btn pin will toggle linked channel, set linked channel type to ReadOnly, and use this channel (after ha discovery) in HA to set up automations
    3. You can use just Btn pin and do custom publish and catch it in HA:
    
    // Btn_ScriptOnly is set on P26
    // remaining events do MQTT publishes
    // NOTE: publish [topicName] [payload]. Final topic will be like obk0696FB33/[Topic]/get
    addEventHandler OnClick 26 publish myClickIs singleClick
    addEventHandler OnDblClick 26 publish myClickIs doubleClick
    addEventHandler On3Click 26 publish myClickIs tripleClick
    addEventHandler On4Click 26 publish myClickIs quadraClick
    addEventHandler On5Click 26 publish myClickIs pentaClick
    

    4. You can send TOGGLE directly in click event:
    
    addEventHandler OnClick 26 SendGet http://192.168.0.112/cm?cmnd=Power0%20TOGGLE
    

    This requires static IP on target device.
    5. You can send commands from channel change, and let button automatically toggle local channel, send on channel target:
    
    addChangeHandler Channel1 == 0 SendGet http://192.168.0.112/cm?cmnd=Power0%20TOGGLE
    addChangeHandler Channel1 == 1 SendGet http://192.168.0.112/cm?cmnd=Power0%20TOGGLE
    

    6. For more advanced logic, you can use berry...
    https://www.elektroda.com/rtvforum/topic4117238.html
    PS:
    Quote:

    Is there a way to create a variable (not linked to an output) that flips every time the button is pressed?

    Isn't that done automatically? You can assign like up to 60 channels to a button. When you press (click) Btn role, the channel is flipped. Then you can use addChangeHandler on OBK to do something or just watch this channel for toggle on HA....
    Helpful post? Buy me a coffee.
  • #7 21582774
    brazoayeye
    Level 4  
    Thanks for your precious help.

    1. Where can I find a tutorial or informations for tasmota groups? I can only see this config and it's seem cryptic to me
    How to Rename openBK Switch Entity and Separate External Switch in HASS with BK7231N?

    2. That was the first though, but I can't see in HASS that channel.
    With this setup:
      "pins": {
        "6": "TglChanOnTgl;2",
        "7": "Rel;1",
        "23": "Btn;1",
        "26": "WifiLED_n;0"
      },

    I only see when I publish to hass the following infos
    Message 6 received on homeassistant/sensor/openBK_4_ip/config at 11:56:
    {"dev":{"ids":["openBK_4"],"name":"openBK_4","sw":"1.18.111","mf":"Beken Corporation","mdl":"BK7231N","cu":"http://192.168.32.147/index"},"name":"IP","~":"openBK_4","avty_t":"~/connected","uniq_id":"openBK_4_ip","qos":1,"stat_t":"~/ip","entity_category":"diagnostic","icon":"mdi:ip-network"}
    
    Message 5 received on homeassistant/sensor/openBK_4_ssid/config at 11:56:
    {"dev":{"ids":["openBK_4"],"name":"openBK_4","sw":"1.18.111","mf":"Beken Corporation","mdl":"BK7231N","cu":"http://192.168.32.147/index"},"name":"SSID","~":"openBK_4","avty_t":"~/connected","uniq_id":"openBK_4_ssid","qos":1,"stat_t":"~/ssid","entity_category":"diagnostic","icon":"mdi:access-point-network"}
    
    Message 4 received on homeassistant/sensor/openBK_4_build/config at 11:56:
    {"dev":{"ids":["openBK_4"],"name":"openBK_4","sw":"1.18.111","mf":"Beken Corporation","mdl":"BK7231N","cu":"http://192.168.32.147/index"},"name":"Build","~":"openBK_4","avty_t":"~/connected","uniq_id":"openBK_4_build","qos":1,"stat_t":"~/build","entity_category":"diagnostic"}
    
    Message 3 received on homeassistant/sensor/openBK_4_uptime/config at 11:56:
    {"dev":{"ids":["openBK_4"],"name":"openBK_4","sw":"1.18.111","mf":"Beken Corporation","mdl":"BK7231N","cu":"http://192.168.32.147/index"},"name":"Uptime","~":"openBK_4","avty_t":"~/connected","uniq_id":"openBK_4_uptime","qos":1,"dev_cla":"duration","stat_t":"~/uptime","unit_of_meas":"s","entity_category":"diagnostic","stat_cla":"total_increasing"}
    
    Message 2 received on homeassistant/sensor/openBK_4_rssi/config at 11:56:
    {"dev":{"ids":["openBK_4"],"name":"openBK_4","sw":"1.18.111","mf":"Beken Corporation","mdl":"BK7231N","cu":"http://192.168.32.147/index"},"name":"RSSI","~":"openBK_4","avty_t":"~/connected","uniq_id":"openBK_4_rssi","qos":1,"dev_cla":"signal_strength","stat_t":"~/rssi","unit_of_meas":"dBm","entity_category":"diagnostic","stat_cla":"measurement"}
    
    Message 1 received on homeassistant/sensor/openBK_4_temp/config at 11:56:
    {"dev":{"ids":["openBK_4"],"name":"openBK_4","sw":"1.18.111","mf":"Beken Corporation","mdl":"BK7231N","cu":"http://192.168.32.147/index"},"name":"Temperature","~":"openBK_4","avty_t":"~/connected","uniq_id":"openBK_4_temp","qos":1,"dev_cla":"temperature","stat_t":"~/temp","unit_of_meas":"°C","entity_category":"diagnostic","stat_cla":"measurement"}
    
    Message 0 received on homeassistant/switch/openBK_4_relay_1/config at 11:56:
    {"dev":{"ids":["openBK_4"],"name":"openBK_4","sw":"1.18.111","mf":"Beken Corporation","mdl":"BK7231N","cu":"http://192.168.32.147/index"},"name":"relay","~":"openBK_4","avty_t":"~/connected","pl_on":"1","pl_off":"0","uniq_id":"openBK_4_relay_1","qos":1,"stat_t":"~/1/get","cmd_t":"~/1/set"}

    But nothing regarding channel 2

    3. Very nice, work well. Is there a list of all events? Is it possible to publish with QoS 1 instead of 0?

    I prefer to avoid get requests because they are quite slow (compared to other udp choices)
    I will deepen Berry

    Thanks
  • #8 21583265
    p.kaczmarek2
    Moderator Smart Home
    1. just set the same group name and check what you want to sync. Still, here is some tutorial:



    2. If given channel is not published, you need to set a desired channel type in the Web App, and redo the discovery:
    How to Rename openBK Switch Entity and Separate External Switch in HASS with BK7231N?
    3. I think 1 is by default, but maybe mqtt from lwip does not support it well, i don't remember at the moment
    How to Rename openBK Switch Entity and Separate External Switch in HASS with BK7231N?
    We don't have full list of events yet, but autoexec.bat samples should cover most of them https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md
    Helpful post? Buy me a coffee.

Topic summary

The discussion addresses configuring openBK firmware on BK7231N-based devices for flexible integration with Home Assistant (HASS). Key points include renaming switch entities from default numeric labels using the SetChannelLabel command and managing MQTT-based HASS Discovery for device integration. Users seek to separate external physical switches as distinct entities while maintaining relay control, aiming to handle monostable push buttons reliably despite network latency. Solutions involve setting separate channel indices and types (e.g., toggle, ReadOnly) via the openBK web app, using MQTT custom publish events for button presses, and leveraging Tasmota Device Groups for synchronized control. The importance of proper channel type configuration and rediscovery in HASS is emphasized to expose all relevant channels. Documentation and examples for commands and autoexec scripts are referenced to implement advanced button event handling and power-saving features. The discussion clarifies that openBK supports HASS Discovery over MQTT but not a dedicated HASS API, and highlights firmware capabilities and limitations compared to alternatives like ESPHome.
Summary generated by the language model.
ADVERTISEMENT