logo elektroda
logo elektroda
X
logo elektroda

Looking for provisioning OpenBeken devices via URL or any other automated procedure

nielspiersma 3498 36
ADVERTISEMENT
  • #1 20338867
    nielspiersma
    Level 9  
    Hi,
    I am new to the forum, but I disassembled 3 Beken-based smart plugs and successfully flashed them using the tuya cloud cutter. And I was confronted with a BK7231T labeled as cb2s (BK7231N). Besides that, I've been working with Tasmota and HomeAssistant for over three years.

    I understand that from an economic perspective, Tuya uses the Beken chips instead of the ESP82xx chips. And as a result, I expect more and more Beken (compatible) chips will surface in the devices used for relays.

    I've fully automated my esp82xx conversions and created over 40 one-liners configuring my Tasmota devices. That's great if a device fails or gets bricked (yes, I accept a 10% bricking rate).

    Also, in our office, we use 100+ ESP32 / ESP82xx devices and have an excellent repository with on-liners that reprovision them in case of (hardware) failure or replacement.

    As I am new, maybe I've not found what I am looking for, and it is just there under my nose. But I am looking for instructions on configuring a freshly flashed device using a one-line URL, preferably when accessing the device for the first time in AP mode.

    For tasmota I inject the whole configuration in one line without needing to access the webpage.

    Is there any documentation on "backlog xyz"? I don't expect the full doc as available from tasmota commands.

    I recognize that in case ESP32 / ESP82xx won't get cheaper, they all will be replaced by BK7321 in de mid-long term; having a way to provision devices will significantly increase the install base for this project.

    Niels
  • ADVERTISEMENT
  • #2 20339004
    p.kaczmarek2
    Moderator Smart Home
    Hello, the basic commands you might need to use:
    - SetPinRole PIN ROLE
    - SetPinChannel PIN CHANNEL
    I also understand that you might want to set WiFi and MQTT data through the command, right?
    If so, I can add some commands for you, like "SetMQTTHost", because currently they are not present.
    Helpful post? Buy me a coffee.
  • #3 20339416
    nielspiersma
    Level 9  
    @p.kaczmarek2,
    Thanks for your quick reply. Provisioning the PINs is quite helpful. Any setting that can be provisioned, like option 6 (immediate response to button push) would be greatly appreciated.

    I've 20 LSC Smart Plugs on my desk, and it takes quite some time to set them up (for friends and family). A one-liner that pushes the configuration would speed up things tremendously.

    For example, I use this for some of my ESP8266 (tasmota) based devices.

    backlog ssid1 ssid_name; password1 ssid_pwd; hostname hostname; topic topic_name; DeviceName device_name; FriendlyName friendly_name; MqttClient mqqt_client_name; MqttHost ip_of_homeassistant; MqttUser ha_username; MqttPassword ha_password; PowerRetain 1; template {"NAME":"Sonoff MINIR2","GPIO":[17,0,0,0,9,0,0,0,21,56,0,0,0],"FLAG":0,"BASE":1}; Module 0; loghost 10.4.14.2; syslog 4; so19 0

    I'll put the ESP82xx in AP mode, connect, and paste the full config in the console command line. I know I can do it using REST, but this procedure is almost as fast.

    Using this approach makes replacing the units a breeze and gives you a working backup for emergencies, I don't know how it works at your place, but if the lights in our house don't work, my wife goes hunting.... FOR ME.


    Niels
  • #4 20339477
    p.kaczmarek2
    Moderator Smart Home
    nielspiersma wrote:

    backlog ssid1 ssid_name; password1 ssid_pwd; hostname hostname; topic topic_name; DeviceName device_name; FriendlyName friendly_name; MqttClient mqqt_client_name; MqttHost ip_of_homeassistant; MqttUser ha_username; MqttPassword ha_password; PowerRetain 1; template {"NAME":"Sonoff MINIR2","GPIO":[17,0,0,0,9,0,0,0,21,56,0,0,0],"FLAG":0,"BASE":1}; Module 0; loghost 10.4.14.2; syslog 4; so19 0

    I will use this as a reference and add commands for you (I will try to use Tasmota syntax), is there anything else apart from that string above that you need to be able to configure?
    Helpful post? Buy me a coffee.
  • #5 20339485
    nielspiersma
    Level 9  
    Hi,

    Will have a look. Already figured out that the backlog doesn't accept a very long string.. for provisoning a smart plug I need to execute two backlogs.. maybe a bit more storage in the command line ?

    Thanks
    Niels
  • ADVERTISEMENT
  • #6 20339514
    p.kaczmarek2
    Moderator Smart Home
    From a quick glance at code, the lenght of backlog string should not be limited, I can see that only there is a limit of a single command in backlog which is 128 chars at the moment.

    I will need to check later, but how did you figure out that backlog doesn't like long strings?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #7 20339536
    nielspiersma
    Level 9  
    Hi,

    I pasted the line:

    backlog SetPinRole 6 LED_n;SetPinChannel 6,1;SetPinRole 7 Btn;SetPinChannel 7,1;SetPinRole 8 relay; SetPinChannel 8,1;SetPinRole 26 wifiled_n;SetPinChannel 26,0

    This provisions my Smart Plug so all the leds, button and relay are set up. But as can see, it fails. When I split it up in two commands it works. But not very handy ;)

    "backlog SetPinRole 6 LED_n;SetPinChannel 6,1;SetPinRole 7 Btn;SetPinChannel 7,1;SetPinRole 8 relay; SetPinChannel 8,1;SetPinRol"

    Is being returned with the message:

    Info:CMD:CMD_SetPinRole: This role is not known
    Error:CMD:cmd SetPinRol NOT found (args )

    Looking for provisioning OpenBeken devices via URL or any other automated procedure
  • ADVERTISEMENT
  • #8 20339577
    p.kaczmarek2
    Moderator Smart Home
    Ah ok, it's not the fault of command line, it's HTTP snapping them to 128 bytes buffer. I will try to remove this limitations.
    Helpful post? Buy me a coffee.
  • #10 20339600
    ferbulous
    Level 18  
    nielspiersma wrote:
    Using this approach makes replacing the units a breeze and gives you a working backup for emergencies, I don't know how it works at your place, but if the lights in our house don't work, my wife goes hunting.... FOR ME.

    This is funny and true at the same time

    @p.kaczmarek2 just to clarify, if we need to prevent device reset if there's power brownout, this need to be set to the shortest time possible like 1 second right?

    Looking for provisioning OpenBeken devices via URL or any other automated procedure
  • Helpful post
    #11 20339711
    p.kaczmarek2
    Moderator Smart Home
    I have changed both HTTP command line behaviour and the "cmnd" HTTP syntax to handle command of any length (as long as it is able to malloc the buffer for that, but malloc only is used for commands longer than default 128).
    Can you check if it works? Both cmnd HTTP syntax and our console HTTP field.
    I also added a unit test for that.

    @ferbulous , are you sure with that 1 second? It's a very low time, how would reset that device in the case of issue? You can set it to 1, but it would be safer with something like 3 seconds setting, etc
    Helpful post? Buy me a coffee.
  • #12 20339845
    nielspiersma
    Level 9  
    p.kaczmarek2 wrote:
    I have changed both HTTP command line behaviour and the "cmnd" HTTP syntax to handle command of any length (as long as it is able to malloc the buffer for that, but malloc only is used for commands longer than default 128).
    Can you check if it works? Both cmnd HTTP syntax and our console HTTP field.
    I also added a unit test for that.

    @ferbulous , are you sure with that 1 second? It's a very low time, how would reset that device in the case of issue? You can set it to 1, but it would be safer with something like 3 seconds setting, etc


    Sweet, I can confirm the following will provision the PIN configuration

    http://10.4.15.96/cm?cmnd=backlog+SetPinRole%...207,1;SetPinChannel%206,1;SetPinChannel%208,1

    I'll now try and play what is there :).

    I hope we can soon have MQTT, hostname, and logging setup from one line :)

    Much appreciated.

    Niels
  • Helpful post
    #13 20339882
    p.kaczmarek2
    Moderator Smart Home
    I am adding those commands now.
    Added:
    Code: C / C++
    Log in, to see the code

    We also have:
    - ShortName
    - FriendlyName
    - MqttClient (client ID)
    Helpful post? Buy me a coffee.
  • #14 20339935
    nielspiersma
    Level 9  
    p.kaczmarek2 wrote:
    I am adding those commands now.
    Added:
    Code: C / C++
    Log in, to see the code

    We also have:
    - ShortName
    - FriendlyName
    - MqttClient (client ID)



    I will check it later tonight or tomorrow!. But this would certainly reduce the deployment time.
    Niels
  • Helpful post
    #15 20340035
    p.kaczmarek2
    Moderator Smart Home
    Anything more?

    Added SetFlag [bitIndex] [bOn]
    Helpful post? Buy me a coffee.
  • #17 20340101
    p.kaczmarek2
    Moderator Smart Home
    I can add such a command but it would need to wait for MQTT connect. We can't do HA discovery before MQTT is fully connected. So it would be something like "schedule HA discovery" and not "do it now".

    We also might want to have command to set short startup commandline? But that might require.... quotation string usage.
    Something like:
    backlog SetStartupCommand "backlog startDriver NTP; startDriver BL0937"....
    Helpful post? Buy me a coffee.
  • #18 20340112
    nielspiersma
    Level 9  
    nielspiersma wrote:
    p.kaczmarek2 wrote:
    Anything more?

    Added SetFlag [bitIndex] [bOn]


    @p.kaczmarek2, So far, it works as expected. wifi, buttons, superb.

    http://10.4.15.99/cm?cmnd=backlog+SetPinRole%...lsc006;SSID1%20ssid-iot;Password1%20putithere

    To finalize it, would it be possible adding a command for triggering homeassistant discovery with a cmnd?

    Niels



    I don't think the SetFlag(s) is accepted, or I am not using the correct syntax...



    Looking for provisioning OpenBeken devices via URL or any other automated procedure


    http://10.4.15.99/cm?cmnd=backlog+SetFlag%204
    http://10.4.15.99/cm?cmnd=backlog+SetFlag%204%201
    http://10.4.15.99/cm?cmnd=backlog+SetFlag%204%20On

    Don't work, using the execute command, doesn't either.

    Error:CMD:cmd SetFlag NOT found (args 4 on)

    Cheers
    Niels
  • #19 20340121
    p.kaczmarek2
    Moderator Smart Home
    SetFlag was added to repo just this minute. It will also need few minutes for automatic build for all platforms and release.
    Helpful post? Buy me a coffee.
  • #20 20340151
    nielspiersma
    Level 9  
    200 version is working ;)
    Sorry for my impatience...
    Cheers
    Niels

    Added after 1 [minutes]:

    p.kaczmarek2 wrote:
    I can add such a command but it would need to wait for MQTT connect. We can't do HA discovery before MQTT is fully connected. So it would be something like "schedule HA discovery" and not "do it now".

    We also might want to have command to set short startup commandline? But that might require.... quotation string usage.
    Something like:
    backlog SetStartupCommand "backlog startDriver NTP; startDriver BL0937"....


    Okay, thanks for clarifying that.
    Niels

    Added after 1 [hours] 30 [minutes]:

    The last one for today; After updating the the latest version I can now quickly configure and replace devices. When in AP mode I paste the following command in my browser;

    http://192.168.4.1/cm?cmnd=backlog+SetPinRole...rd%20password;MqttHost%20hassio.local;restart

    It sets and configures the PINs and Channels, sets up Wifi and MQTT and restarts the unit.

    My HomeAssistant automates further onboarding and configuration.

    Excellent! It now makes no difference for my environments if the device is ESP32/ESP82xx or BEKEN based!!

    Have a great Sunday,
    Niels
  • #21 20340966
    ferbulous
    Level 18  
    p.kaczmarek2 wrote:
    are you sure with that 1 second? It's a very low time, how would reset that device in the case of issue? You can set it to 1, but it would be safer with something like 3 seconds setting, etc

    For minimum 'Uptime seconds required to mark boot as ok:' time can this be added to the one line command?

    Any recommended site I can use to generate the command url with spaces?
  • #22 20341668
    nielspiersma
    Level 9  
    ferbulous wrote:
    p.kaczmarek2 wrote:
    are you sure with that 1 second? It's a very low time, how would reset that device in the case of issue? You can set it to 1, but it would be safer with something like 3 seconds setting, etc

    For minimum 'Uptime seconds required to mark boot as ok:' time can this be added to the one line command?

    Any recommended site I can use to generate the command url with spaces?


    I just did a search and replace. A space is "%20"

    Notepad++ does the job for me.
    NIels
  • #23 20342157
    ferbulous
    Level 18  
    p.kaczmarek2 wrote:
    Anything more?

    Added SetFlag [bitIndex] [bOn]

    Is there example if I need to enable several flags in general option?

    Looking for provisioning OpenBeken devices via URL or any other automated procedure
    nielspiersma wrote:
    I just did a search and replace. A space is "%20"

    Notepad++ does the job for me.
    NIels


    Thanks! Also, does your device gets picked up by homeassistant automatically after device restart or do you still need to manually start homeassistant discovery in openbk?
  • #24 20342221
    nielspiersma
    Level 9  
    I’ll double check if ha picks up the devices.
    I think not , but as i provisioned them for another network I can’t tell (right now).

    Niels
  • #25 20342271
    p.kaczmarek2
    Moderator Smart Home
    You need to do it manually, I still have to add a command for that
    Helpful post? Buy me a coffee.
  • #26 20345395
    nielspiersma
    Level 9  
    Hi @p.kaczmarek2,
    Just want to share we did 20 LCS smart plugs this evening and are pretty satisfied with the speed we can achieve now we can provision the smart plugs while in AP mode.
    Takes about 3 minutes a plug now. Me doing the hack-flash, my friend injecting the URL with the provisioning information.

    It would be helpful that after the reset provision to MQTT Home assistant can be run. Maybe a reset (x) that indicates a "fresh" MQTT auto discovery.

    Niels

    Added after 3 [minutes]:

    Just for fun;)


    Looking for provisioning OpenBeken devices via URL or any other automated procedure Looking for provisioning OpenBeken devices via URL or any other automated procedure
  • #27 20345651
    p.kaczmarek2
    Moderator Smart Home
    I am doing migration to automatic commands docs generation, but when I finish it, I will add that command for you. Do you need anything else?
    https://github.com/openshwprojects/OpenBK7231...mmit/016805258240124cd85c4def57170d178afa2f32
    Helpful post? Buy me a coffee.
  • #28 20346608
    nielspiersma
    Level 9  
    Evening,
    Yep, there are certainly some more requests besides triggering HomeAssistant discovery
    - Detach button from switch (SetOption 114 + switchmode x 15) so pressed button is not triggering relay, but can be used by HA as a mqtt trigger
    - trigger firmware update via http/https
    - full factory reset (back to AP mode)
    - partial factory reset (clean all except wifi)

    Very happy with the results; 20 units are now controlling the ceiling lights in our office.
    Today we acquired another 21 from various ACTION shops.

    Niels
  • #29 20347186
    p.kaczmarek2
    Moderator Smart Home
    Ok, let's add it one by one.

    nielspiersma wrote:

    - Detach button from switch (SetOption 114 + switchmode x 15) so pressed button is not triggering relay, but can be used by HA as a mqtt trigger

    if I understand correctly we already have Btn_ScriptOnly. Then you can do addEventHandler and run any command there, including publish or SendGet comman

    nielspiersma wrote:

    - full factory reset (back to AP mode)

    clearConfig command? Altough... you need to run clearConfig and restart so it goes back to AP mode ASAP.

    nielspiersma wrote:

    - trigger firmware update via http/https
    - partial factory reset (clean all except wifi)

    I will see what I can do.

    nielspiersma wrote:

    Very happy with the results; 20 units are now controlling the ceiling lights in our office.
    Today we acquired another 21 from various ACTION shops.

    If you have any device not listed here:
    https://github.com/openshwprojects/OpenBK7231T_App
    please do a teardown or a review and submit, with config template, thanks!
    Helpful post? Buy me a coffee.
  • #30 20362759
    nielspiersma
    Level 9  
    p.kaczmarek2 wrote:

    If you have any device not listed here:
    https://github.com/openshwprojects/OpenBK7231T_App
    please do a teardown or a review and submit, with config template, thanks!


    Already did, there are two. If I see another plug/device lying around, surely will pick it up and disassemble it.

Topic summary

The discussion revolves around provisioning Beken-based smart plugs using automated procedures via URL commands. The user, experienced with Tasmota and HomeAssistant, seeks efficient methods to configure multiple devices quickly. Key commands for setting up PIN roles and channels are shared, along with challenges related to command length limitations in the backlog feature. Solutions are proposed to enhance command handling, including the addition of commands for WiFi and MQTT configuration. The conversation highlights successful testing of commands that streamline the provisioning process, allowing for rapid setup of devices in AP mode. Suggestions for further enhancements, such as triggering HomeAssistant discovery and managing device flags, are also discussed.
Summary generated by the language model.
ADVERTISEMENT