logo elektroda
logo elektroda
X
logo elektroda

[Tutorial] Provisioning using HomeAssistant

nielspiersma 
OpenBeken Provisioning.
As an enthusiastic user of HomeAssistant and Smart Home solutions in general, I am always into something new. Recently I’ve become acquainted with OpenBeken. Not wholly voluntary, but is a response to the fact that more Smart Home Devices started using BK7231 vs. good-old ESP82xx.

Undoubtedly I like the fact of being able to log in to a device and configure it to my needs. However, from a manageability perspective, you need the ability to mass-configure devices. When looking at phone provisioning and large-scale OS deployments, provisioning is standard. There is no way you can log in to 200 web interfaces and set individual settings.

Luckily for a few weeks, OpenBeken has introduced the “MQTT Group Topic,” which has eased our life tremendously.
Furthermore, the OpenBeken developers are actively adding configuration parameters with the ability to set them (up) using the MQTT “cmnd”. Combined with the “MQTT Group Topic,” I can now quickly configure multiple devices.

So why is this important to us? Well, let me start by using our own office as an example. Everyone knows about the high costs of electricity and the new rules coming from the EU regarding Co2 emissions and taxes. Saving on electricity consumption is directly impacting these costs. In our office, we have ceiling lights. About 25 of them. Each is equipped with 8 led lamps but still consumes around 100 Watts when lit. Multiply that by 25, and you have a whopping 2500 watts. We found that, on average, we only need ten ceiling lights powered on at any given moment is fine. Thus reducing our average usage by more than 50%. All our ceiling lights were connected to standard earthed sockets. Reason enough to buy 30 or so Smart Sockets. Initially, I tested the Woox R6080, and after sacrificing one unit, I got it running with OpenBeken. At about the same time, I successfully managed to get cloud-cutter to work, which made my work even more straightforward. It took away the need to desolder 25 Tuya boards.

I flashed all 34 Smart Plugs in two evenings. So now my real problems have begun. How to configure all these babies in bulk. I wasn’t planning on logging on to each device setting the required settings. So I started playing around with the same commands I used for bulk configuring my Tasmota devices. Unfortunately, not all the commands I needed were implemented at that time. Thanks to the developers, quite some features were added. But things really got up to speed once the MQTT Group Topic was introduced. This made it possible for me to update all 34 plugs in one go. As well as fine-tuning. This is a breeze as I have the same plugs and the same underlying hardware.

Let me show how I’ve done this;
Flash your device and add it to your WiFi network. No pin settings are needed; we will configure all settings from HomeAssistant.
First, I recommend choosing an MQTT Group Topic based on your hardware chip. This will make updating relatively easy and at least somehow prevent you from pushing N setting to T chips and vice versa. Setting up the MQTT Group Topic is done under “Configure MQTT.” Please make sure you set up your username and password correctly so HomeAssistant can “take control.”



To follow up on this, your Beken Device must report its status (regularly) to HomeAssistant. I recommend setting it up with a special Startup command. This is done in the Change Startup command text.

You should add “scheduleHADiscovery 10”



Now reboot your OpenBeken device and check if it shows up in HomeAssistant



We are now ready to configure the device.
Firmware update example.
Now that your device is integrated in HomeAssistent, you might want to update it remotely. Download the latest firmware and store it in a repository accessible via http. This can be a any type of http server. Let us assume your file resides on a local server with IP address 192.168.1.66 and is called fw.rbl. The URL for the update would http://192.168.1.6/fw.rbl. In HomeAssistant create a new script with the following settings;



For completeness the yaml code;

alias: OpenBeken Firmware Update
sequence:
- service: mqtt.publish
data:
topic: cmnd/BK7321N/ota_http
payload: http://192.168.1.66/fw.rbl
mode: single
icon: mdi:cellphone-arrow-down



When you run the script, it will request all OpenBeken devices subscribed to “BK732N” to download new firmware from the web server.
I want to focus on the “topic” and “payload,” as this is where the actual magic happens.
cmnd/BK7321N/ota_http
• cmnd instructs sending a command.
• BK7321N is the MQTT (group) Topic. If you want an individual update, use the MQTT Client/device name
• ota_http is the command your want to send. You can use the commands from https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md and from https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands-extended.md
I can tell, it is fun to watch 35 devices updating and rebooting. The aforementioned “scheduleHADiscovery” warrants that your HomeAssistant information is updated. When a new IP address is given or the firmware version changes, this is correctly displayed in HomeAssistant. So you can keep track of the firmware versions and see which devices are not up to date.
Another example is setting the Flags. Sometimes is handy to have flags set. For instance, I like flag 6 being set. This makes sure all relays are triggered instantly. I also have the desire setting flag 10. Setting both flags will give us a flag value of 1088.
Again, we will create a script that updates the flag settings.


Again small breakdown:
cmnd/bekens/ota_http
• cmnd instructs sending a command.
• bekens is the MQTT (group) Topic.
• flags the command we want to send
• payload 1088 in the case representing Flag 6 and Flag 10
Run the script and all your devices in the MQTT Group “bekens” will get these injected.
We can also setup the device using the backlog command. This allows us to send multiple commands to a device. Quite handy for setting up the configuration.

For example, setting up the Action LSC Smart Plugs
Pins are empty:


The device has Wifi set up, has MQTT Group setup, has scheduleHADiscovery set as startup command, and the device has MQTT host, user, and password setup.

Now configure all pins.



Yaml code:
o service: mqtt.publish
o data:
o topic: cmnd/obkBF518BE1/backlog
o payload: SetPinRole 6 LED_n;SetPinChannel 6,1;SetPinRole 7 Btn;SetPinChannel 7,1;SetPinRole 8 rel; SetPinChannel 8,1;SetPinRole 26 WifiLED; SetPinChannel 26,0
Run the script and:



Pins setup.
This shows the power of the MQTT Group Topic and the way the OpenBeken developers have come making provisioning a breeze. I am quite sure any future command or setting will be addressable via a MQTT cmnd command.
You can also play around with HomeAssistant templates, giving you even more power on the commands you want to execute.
I hope you enjoyed this write up on provisioning on OpenBeken.

About Author
nielspiersma wrote 60 posts with rating 19 , helped 3 times. Been with us since 2022 year.

Comments

Add a comment
p.kaczmarek2 06 Jan 2023 22:47

Very good writeup. It will be certainly useful for people, even I can learn new interesting things from that. I will just add here two more notes. 1. If you need anything else (a command, a feature,... [Read more]

nielspiersma 07 Jan 2023 06:49

That is so good to hear. Let me know once the emulator is available. Would love to test that. Especially testing my mqtt provisioning . Cheers Niels [Read more]

ferbulous 13 Jan 2023 17:30

Hi, thanks for sharing this method Followed the instructions but it's not triggering the ota firmware download on my devices Using script and just testing with developer tools https://obrazki.elektroda.pl/3653274900_1673627366_thumb.jpg... [Read more]

p.kaczmarek2 13 Jan 2023 18:02

You must restart your device in order for GroupTopic to work. [Read more]

ferbulous 13 Jan 2023 18:04

@pkaczmarek2 hi, i also restarted the device but it's not working yet [Read more]

nielspiersma 13 Jan 2023 18:09

Correct, After setting up mqtt group topic you need to restart the device. Niels Added after 4 [minutes]: I am not sure, but I only tested with port 80 not with port 7000. I'll setup a server... [Read more]

ferbulous 13 Jan 2023 18:24

@nielspiersma i'm using http-here to share the files root@rpi4:/home/pi/firmware# http-here --host 0.0.0.0 7200 when i ran the mqtt publish, no changes in the openbk console/tcpdump but if... [Read more]

nielspiersma 13 Jan 2023 18:28

Your mqtt url is connecting to port 7000. Your tcpdump shows port 7200. Can you confirm the ports you are using? Niels [Read more]

ferbulous 13 Jan 2023 18:34

@nielspiersma it's 7200 now and i've the changed the mqtt publish to use 7200 http://192.168.1.40:7200/OpenBK7231N_1.15.318.rbl http://192.168.1.40:7200/fw.rbl do i need to leave the original firmware... [Read more]

nielspiersma 13 Jan 2023 19:29

Both in the home assistant script and on your http server? Added after 52 [minutes]: The file name just has to match. I named it fw.rbl so it was easy. Just rename it to fw.rbl so it matches... [Read more]

p.kaczmarek2 14 Jan 2023 02:13

Please try debugging the issue to determine where exactly is your point of failure. 1. Please try to broadcast a "POWER toggle" command using the same method and topic from HA and check if it works 2.... [Read more]

ferbulous 14 Jan 2023 08:04

@pkaczmarek2 Noted, will try a few other mqtt commands once i home to test it out Added after 5 [hours] 28 [minutes]: Looks like it's working now, not sure why it wasn't working earlier root@rpi4:/home/pi/firmware#... [Read more]

p.kaczmarek2 14 Jan 2023 09:11

@ferbulous you need a restart after MQTT group name change and you had a typo in port or something, if I've seen correctly. I think I will add some kind of notification about MQTT params restart re... [Read more]

chri5k 11 Mar 2023 13:46

I am also having difficulty getting the OTA update to trigger via MQTT. I have tried several variations of the strings and rebooted the module between each change to the MQTT configuration of the module.... [Read more]

p.kaczmarek2 11 Mar 2023 14:42

Hello, there are two things you can do. 1. replace command in your script to see if it's received correctly: sequence: - service: mqtt.publish data: topic: cmnd/BK7321T/POWER ... [Read more]

chri5k 11 Mar 2023 14:43

The power toggle command does not work via MQTT. The "ota_http http://192.168.4.200/OpenBK7231T_1.15.576.rbl" does work when executed on the module and via the module web application. [Read more]

p.kaczmarek2 11 Mar 2023 14:58

Power toggle does not work for you? Wait, it works for me, look: https://obrazki.elektroda.pl/4497694200_1678542981_thumb.jpg And look, Web App log says it was received: https://obrazki.elektroda.pl/8560653200_1678543041_thumb.jpg... [Read more]

chri5k 11 Mar 2023 15:04

Neither POWER Toggle, On or Off commands work. I can see the commands published in MQTT. The module log does not show it read the command from MQTT. I can go into Homeassistant and and control the lights... [Read more]

p.kaczmarek2 11 Mar 2023 15:28

Do you have the same version as me? Maybe there was a bug... but I never experienced anything like that. Have you tried rebooting your device? Btw, this also works for me: button: - platform:... [Read more]