Elektroda.com
Elektroda.com
X

Search our partners

Find the latest content on electronic components. Datasheets.com
Elektroda.com

[BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

p.kaczmarek2 39843 858
This content has been translated flag-pl » flag-en View the original version here.
  • p.kaczmarek2
    Level 26  
    There is currently no way to set it via command, but no problem, I can add it, if you want.

    Out of curiousity, why do you need to configure it via cmd?
  • marioalmeida
    Level 8  
    @pkaczmarek2
    Its difficult for other users to change the state from different UI, my family is familiar with HA interface
    Currently I have manage to do it this way

    Create input_select
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

    rest_command in configuration.yaml
    Code: yaml
    Log in, to see the code

    automation.yaml
    Code: yaml
    Log in, to see the code


    Added after 59 [minutes]:

    In file src/cmnds/cmd_eventHandlers.c, line number 15 it says this
    Code:
    // addEventHandler OnChannelChanged 5 ???

    Based on that, I tried to set
    Code:
    addEventHandler OnChannelChanged 1 setChannel 2 0

    but it says
    Code:
    Info:EVENT:CMD_AddEventHandler: OnChannelChanged is not a valid event
  • p.kaczmarek2
    Level 26  
    I will need to create documentation for that (unless someone here wants to help?), but:
    Code:

    setPinRole 10 Btn
    setPinChannel 10 0
    setPinRole 11 Btn
    setPinChannel 11 0
    setPinRole 26 PWM
    setPinChannel 26 1
    addEventHandler OnClick 10 setChannel 1 100
    addEventHandler OnHold 10 addChannel 1 10
    addEventHandler OnClick 11 setChannel 1 0
    addEventHandler OnHold 11 addChannel 1 -10

    //
    // On change listeners
    // Full example of on change listeners:
    // addChangeHandler Channel0 < 50 echo value is low
    // addChangeHandler Current > 100 setChannel 0 0
    // addChangeHandler Power > 40 setChannel 1 0
    //
    //
    // LCD demo:
    // backlog startDriver I2C; addI2CDevice_LCD_PCF8574 I2C1 0x23 0 0 0
    // addChangeHandler Channel1 != 0 backlog lcd_clearAndGoto I2C1 0x23 1 1; lcd_print I2C1 0x23 Enabled
    // addChangeHandler Channel1 == 0 backlog lcd_clearAndGoto I2C1 0x23 1 1; lcd_print I2C1 0x23 Disabled


    AddEventHandler OnClick 0 addChannel 1 -10 0 100 AddEventHandler OnClick 1 addChannel 1 10 0 100

    So I would say:
    Code:

    addChangeHandler Channel0 == 0 echo "First channel is now ZERO"
    addChangeHandler Channel0 == 1 echo "First channel is now ONE"


    log of setting command in console:
    Code:

    Debug:CMD:cmd [addChangeHandler Channel0 == 0 echo "First channel is now ZERO"]
    Info:EVENT:CMD_AddChangeHandler: added Channel0 with cmd echo "First channel is now ZERO"

    Debug:API:POST to api/cmnd
    Debug:CMD:cmd [addChangeHandler Channel0 == 1 echo "First channel is now ONE"]
    Info:EVENT:CMD_AddChangeHandler: added Channel0 with cmd echo "First channel is now ONE"

    Result while changing:
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

    NOTE: actually the "echo" command is not implemented yet, but still, you can see that command line receives it so let's say it work

    I will also add a responsiveness improvement soon
  • marioalmeida
    Level 8  
    Thanks @pkaczmarek2 , and this is how I have set countdown from HA.

    autoexec.bat
    Code:

    // Relay is connected to pin 6
    setPinRole 6 Rel

    // Set external switch pin
    setPinRole 8 TglChanOnTgl

    // Set led pin
    setPinRole 9 LED

    // Set button pin
    setPinRole 26 Btn

    // Assign pin 6, 8, 9 and 26 to channel 1
    setPinChannel 6 1
    setPinChannel 8 1
    setPinChannel 9 1
    setPinChannel 26 1

    // Set countdown channel
    setChannelType 2 TextField

    // Set countdown channel(2) to 0 when channel 1 state is 0 or 1
    addChangeHandler Channel1 == 0 setChannel 2 0
    addChangeHandler Channel1 == 1 setChannel 2 0


    HA Configuration
    configuration.yaml
    Code: yaml
    Log in, to see the code


    Automation
    Code: yaml
    Log in, to see the code
  • p.kaczmarek2
    Level 26  
    That's a very nice setup, you can consider posting this as a separate article with a brief explanation of how it works, so I can add a link to that from a Github.

    Is this a final version?

    I've been working on a small scripting backend for OpenBeken for a few weeks already (but only mostly on weekends), so soon it will be possible to write small programs to exec on our devices, with IF blocks, GOTOs, delays, etc.
  • marioalmeida
    Level 8  
    p.kaczmarek2 wrote:
    That's a very nice setup, you can consider posting this as a separate article with a brief explanation of how it works, so I can add a link to that from a Github.

    Yes, I'll do a teardown post for this device

    p.kaczmarek2 wrote:
    Is this a final version?

    No, I'll post it along with the teardown.
    Is there a way to set a channel value from another channel?
    Is it possible to get feedback of addRepeatingEvent remaining seconds sent via MQTT?

    p.kaczmarek2 wrote:
    I've been working on a small scripting backend for OpenBeken for a few weeks already (but only mostly on weekends), so soon it will be possible to write small programs to exec on our devices, with IF blocks, GOTOs, delays, etc.

    Definitely would like see this
  • p.kaczmarek2
    Level 26  
    marioalmeida wrote:

    Yes, I'll do a teardown post for this device

    I'm eager to see it

    marioalmeida wrote:

    Is there a way to set a channel value from another channel?

    Right now no, but I can add this tomorrow in a very simple way.
    Would a syntax "$Channel0" for Channel0 value be ok?
    So:
    Code:

    setChannel 2 $Channel0

    that would set channel 2 to current value from channel 0.

    marioalmeida wrote:

    Is it possible to get feedback of addRepeatingEvent remaining seconds sent via MQTT?

    What exactly would you like to receive and how? Please be more specific and I will look into it



    marioalmeida wrote:

    Definitely would like see this

    I am designing my own syntax and interpreter because I have a very specific idea for that and because I like C syntax. Here are screenshots from scripting unit tests that I already have working.
    Generic script execution testing:
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    Abstract syntax tree testing:
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    The scripts will be able to contain commands like "delaySeconds(15);" etc,
  • marioalmeida
    Level 8  
    p.kaczmarek2 wrote:

    Would a syntax "$Channel0" for Channel0 value be ok?
    So:
    Code:

    setChannel 2 $Channel0

    that would set channel 2 to current value from channel 0.

    Will that also be possible for addRepeatingEvent
    Code:
    addRepeatingEvent $Channel0 1 setChannel 1 0
    This way I can use MQTT to set the countdown instead of HTTP API

    p.kaczmarek2 wrote:
    What exactly would you like to receive and how? Please be more specific and I will look into it

    Basically I need to know what is the remaining time left. In my case I am using it as countdown. So If I set to 1200 sec, I need to know how may seconds are left as they are decremented.
  • rupertst
    Level 2  
    Hi,
    How about Domoticz support? Do You plan including some settings of MQTT configuration like in Tasmota?
    Something like that:
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

    or maybe some autodiscovery support? It is also supported by Domoticz (at least it is written so, I did not tested)
  • p.kaczmarek2
    Level 26  
    @rupertst would you be able to test that Domoticz syntax? One user already asked for it so I have it on my list.

    marioalmeida wrote:

    Will that also be possible for addRepeatingEvent
    Code:
    addRepeatingEvent $Channel0 1 setChannel 1 0
    This way I can use MQTT to set the countdown instead of HTTP API

    I am not sure if your idea is logically correct, but since today commit, every call to:
    Code: c
    Log in, to see the code

    supports following three syntaxes:
    - simple decimal number - 1234 etc
    - hex number - 0xFF
    - constant value - $CH0 for channel 0, $CH1 for channel 1, etc. It will return current channel value as integer
    Right now I am not sure if it's a final solution, but I don't see how it could break things. Still, report to me if there is any issue with that.

    NOTE: the syntax is evaluated at the time when you enter the command in the commandline!

    It would be much harder for it to be evalulated at runtime.

    If you need to get a channel value at runtime, wait for the "scripting" update that is coming soon.

    Demonstration:
    Quote:

    Debug:API:POST to api/cmnd
    Debug:CMD:cmd [SetChannel 13 2022]
    Debug:API:POST to api/cmnd
    Debug:CMD:cmd [GetChannel 13]
    Info:CMD:CMD_GetChannel: channel 13 is 2022
    Debug:API:POST to api/cmnd
    Debug:CMD:cmd [SetChannel 12 $CH13]
    Debug:API:POST to api/cmnd
    Debug:CMD:cmd [GetChannel 12]
    Info:CMD:CMD_GetChannel: channel 12 is 2022
  • Tych0
    Level 4  
    Some of my lights have to start with a default brightness and color when powered on. I use a startup command for that. This works just fine.
    But when the light ia on and I change the brightness and/or color in HA. Turn off the light (cut power). And turn it on again. The light starts with the brightness and color as I configured it in the strap command. But... HA still shows the brightness and color that I changed in the GUI before I turned it off.
    I noticed the temp and dimmer messages in the MQTT state topic are not updated when the light is completely booted. Do I need to change something, misconfigured anything? Or is this a feature request?
  • p.kaczmarek2
    Level 26  
    @Tych0 maybe you are referring to LED state change MQTT feedback?
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    if not, specify how do you drive your lights and show the HA yaml config.
  • rcayadi
    Level 2  
    Hi All,

    I'm new to try flash smart breaker from brand BARDI (indonesia brand) https://bardi.co.id/products/on-off-breaker-sb-10a-nem/ they using WB2S , the flash is going OK and im using
    P24 - Rel
    P6 - Btn
    P7 - LED (but this led is on when OFF and led off wen ON) how to solve this?

    and then the wifi connection is offline immediately ? first i thought that about limited user in my router but it going off after i try off some wifi it's still happen. This flash device not offline immediately before i configure module. How to solved this
  • p.kaczmarek2
    Level 26  
    rcayadi wrote:

    P7 - LED (but this led is on when OFF and led off wen ON) how to solve this?

    Use LED_n option, which is an inverted LED. Same goes for REL (if you want), there is a REL_N option.

    rcayadi wrote:

    and then the wifi connection is offline immediately ? first i thought that about limited user in my router but it going off after i try off some wifi it's still happen.

    I am not sure what you mean. Is the device still pingable? Is the device responding to the Button, but offline? Or maybe is the device 100% dead?

    I will double check this with my WB2S modules when I come back to home today.
  • rcayadi
    Level 2  
    p.kaczmarek2 wrote:

    Use LED_n option, which is an inverted LED. Same goes for REL (if you want), there is a REL_N option.


    Thx now its working correctly
    P6 - Btn
    P7 - Led_n
    P24 - Rel

    p.kaczmarek2 wrote:

    I am not sure what you mean. Is the device still pingable? Is the device responding to the Button, but offline? Or maybe is the device 100% dead?


    Device is pingable if i power off then on the device then it will not pingable randomly about a 10sec to xx sec .

    The strange is if i could reach the device via browser http://openbekendeviceIP/index and it trigger the device to on/off it not down anymore and stable working . now i try to figure out what happen so the device is not pingable . any log i can look?

    Build on Aug 6 2022 17:35:36 version 1.0.0
    Online for 21 minutes and 1 seconds
    Device MAC: XXXXXXX
    Short name: obk66C08C6A, Chipset BK7231T
  • p.kaczmarek2
    Level 26  
    Can you try latest version (update OTA, by WiFi to latest build for your platform - do not chose wrong platform!)?
  • Tych0
    Level 4  
    p.kaczmarek2 wrote:
    if not, specify how do you drive your lights and show the HA yaml config.

    I've set flag 0 but that doesn't fix the issue. I assume, and makes sense, that the startup command is executed before the module has connected to the WiFi and MQTT and therefore does not send the new state message.
    YAML light configuration example I use for a CW light:
    Code:
      - platform: mqtt
    
        name: "obk06B22AC7"
        unique_id: "obk06B22AC7"
        command_topic: "cmnd/obk06B22AC7/led_enableAll"
        state_topic: "obk06B22AC7/led_enableAll/get"
        availability_topic: "obk06B22AC7/connected"
        payload_on: 1
        payload_off: 0
        brightness_command_topic: "cmnd/obk06B22AC7/led_dimmer"
        brightness_scale: 100
        brightness_state_topic: "obk06B22AC7/led_dimmer/get"
        brightness_value_template: "{{value}}"
        color_temp_command_topic: "cmnd/obk06B22AC7/led_temperature"
        color_temp_state_topic: "obk06B22AC7/led_temperature/get"
        optimistic: true
        retain: false

    My 2 cents... when we are using a startup command to change the channel values. A state message should be send when the device is connected to WiFi and MQTT.
  • p.kaczmarek2
    Level 26  
    I know what's wrong. The "publish all self state" mechanism on MQTT connect does not include LED driver.

    I will fix that tomorrow, will you be able to test that?