Elektroda.com
Elektroda.com
X

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

p.kaczmarek2 89289 1198
This content has been translated flag-pl » flag-en View the original version here.
  • bogran
    Level 6  
    I only have one problem now. The pin settings that are available for Nedis WIFIPO120FWT:

    Chipset: BK7231T
    Model: WIFIPO120FWT
    Pin 6: LED on channel 1
    Pin 10: Button on channel 1
    Pin 26: Relay_n on channel 1

    makes the status (on index and web app pages) show as inverted, i.e when the device is ON the app show status OFF, and the other way around. I've checked all configs but can't get what's wrongly configured.
  • p.kaczmarek2
    Moderator Smart Home
    I am not sure what is the backstory behing the "Relay_n" here, but I'd suggest using "Relay", with no "n" (negation, inversion).

    OBK English Video tutorial released! 2 gang switch flashing!



    Two next videos are almost ready (RGBCW bulb and simple relay switch), fourth video (LED controller) is in the making - give us a like or subscription for a good start, that's our first English guide.
  • ferbulous
    Level 15  
    pepesuriano wrote:
    Hello, I have a tuya smart plug which I couldn't flash via uart because some electrical thing is preventing the program to flash it. Is still uart the only way to flash it or there are some new ways to flash it?


    Use tuya-cloudcutter to flash via ota
    Just need to get the tuya firmware version first
    @bogran had success flashing openbk on his plug
  • bogran
    Level 6  
    p.kaczmarek2 wrote:
    I am not sure what is the backstory behing the "Relay_n" here, but I'd suggest using "Relay", with no "n" (negation, inversion).


    Yes, that did it. Would be interesting to know why different configurations work for the same device, but I just saw @boozeman's post #153 where he mentions Rel as well.
    Nevertheless I'm happy everything works as expected now. Thanx again!

    Added after 1 [hours] 1 [minutes]:

    ferbulous wrote:
    pepesuriano wrote:
    Hello, I have a tuya smart plug which I couldn't flash via uart because some electrical thing is preventing the program to flash it. Is still uart the only way to flash it or there are some new ways to flash it?


    Use tuya-cloudcutter to flash via ota
    Just need to get the tuya firmware version first
    @bogran had success flashing openbk on his plug


    Yeah, I'd definitely go for the ota. Works great once you get all the details correct.

    Added after 20 [minutes]:

    I noticed a strange behaviour when using the APIs, and it differs from Tasmota which behaves correctly.

    For example:
    1. Check the status
    ip_address/cm?cmnd=Power%20Status => returns e.g. {"POWER":"ON"}

    2. Toggle power either by Power%20Toggle or setting it explicitly
    ip_address/cm?cmnd=Power%20Off => returns "OFF"

    3. Check the status again
    ip_address/cm?cmnd=Power%20Status => now strangely returns "ON", so it actually also toggles the Power, instead of just showing the actual status which was OFF

    4. Check the status again
    ip_address/cm?cmnd=Power%20Status => returns "ON", i.e. this time it does not toggle the Power

    Any ideas?
  • p.kaczmarek2
    Moderator Smart Home
    Oh ok, not a problem here, I pushed a self test mechanism and a fix:
    https://github.com/openshwprojects/OpenBK7231...mmit/b39b99865bc5c2336e0aed495db1e4a796b4891e
    You are the first person to try "ip_address/cm?cmnd=Power%20Status" to get status, we assumed that you just need "ip_address/cm?cmnd=Power" to get status, so when you sent "ip_address/cm?cmnd=Power%20Status" it tried to parse "Status" string as an integer and atoi returned 0 and set power to OFF (your example is slightly wrong here, but I think I know what you mean)

    Can you check if it works now? Is there anything else that we might need to add?

    We don't have 1:1 TAS compatibility, but we strive to be functional.
  • MotoSpeed
    Level 3  
    @p.kaczmarek2 Since the 1.15.165 update, I am now receiving the following errors in the log every three seconds:
    Error:CMD:command with name uartSendHex already exists!
    Error:CMD:command with name uartSendASCII already exists!


    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 202, idle 703959/s, free 89752, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 203, idle 697152/s, free 89752, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 204, idle 708329/s, free 89752, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Error:CMD:command with name uartSendHex already exists!
    Error:CMD:command with name uartSendASCII already exists!
    Info:MAIN:Time 205, idle 705460/s, free 89752, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
    Info:TuyaMCU:TuyaMCU_ProcessIncoming[ver=3]: processing command 0 (Hearbeat) with 8 bytes
    Info:MAIN:Time 206, idle 704642/s, free 89752, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 207, idle 704497/s, free 89752, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 208, idle 703959/s, free 81144, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 3/38
    Error:CMD:command with name uartSendHex already exists!
    Error:CMD:command with name uartSendASCII already exists!
    Info:MAIN:Time 209, idle 700744/s, free 89752, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:TuyaMCU:TUYAMCU received: 55 AA 03 00 00 01 01 04 
  • p.kaczmarek2
    Moderator Smart Home
    Thanks, I pushed a fix to it now. Developer debug commands for UART were tried to be registered with each UART init.
  • bogran
    Level 6  
    p.kaczmarek2 wrote:

    Can you check if it works now? Is there anything else that we might need to add?


    Yeah, I don't know why I use "Power Status", guess it was just old habit.
    But as always - you're quick, accurate and superb, i.e it worked :please:
    Thanx!
  • p.kaczmarek2
    Moderator Smart Home
    Dark Man wrote:

    Great, great job, but can you somehow make it so that when you hold the button (OnHold), when it reaches 100% brightness, the brightness again starts from zero or starts to go down, and at zero it goes up again.

    Good point, will you check?
    https://github.com/openshwprojects/OpenBK7231...mmit/8bb86176c8e603bb6fa5e73784aff366d8750c00

    Dark Man wrote:

    The second thing:
    With 5 PWM channels set in the GUI, the configuration for HA generated in the GUI reflects one light source (good!) and not 5 separate entities, while for the CW bulb it generates only 2 entities (for each channel separately). Could you (preferably) add such a configuration in the GUI (maybe even with a switch or as one entity or each separately :) ) or at least specify what the configuration for a CW bulb would look like?

    I will forward to @iprak.
    But overall it's... I guess you just take the configuration (Yaml our example) for RGBCW and remove the rgb themes...
  • Karol966
    Level 31  
    I would like to ask for your understanding for the questions I will ask but I would like to make sure that I don't read the whole huge thread for nothing (in my case),

    1) If I already have some smart-something (two sonoffs, some Tuya rgb lamps) with ready-made ewelink/tuya smart applications, what can be controlled from the phone level after changing the firmware both in the case of https://github.com/arendst/Tasmota or https://github.com/openshwprojects? Am I looking correctly: https://play.google.com/store/apps/details?id=io.homeassistant.companion.android&hl=pl&gl=US

    2) If I would like to build my own device to be connected to the HA (e.g. 8 relay outputs, 8 digital inputs + several temperature sensors and maybe a power measurement at the same time - such a switchgear combine) there are probably ready-made ones (maybe not all in one, but starting from out/in) what would you recommend? Any git link? Ideally, the projects should already be for platformIO. I have the ESP8266/ESP32 modules for testing in stock.
    I am currently designing an energy meter at work so I will be able to use it in my next project, but there is also a ready-made version available without the project: https://github.com/openenergymonitor
    If I understand correctly, the use of e.g. tasmota according to this guide https://www.elektroda.pl/rtvforum/topic3760371.html#20329687 limits the construction of the device to the selected function from the list.

    3) I used to make a GSM device that sent data to the server using HTTP POST/GET, I still don't know what works because the server was operated by a colleague, but the data went to the database and from the database to the website. How are devices controlled in popular smart-home devices?
  • p.kaczmarek2
    Moderator Smart Home
    Karol966 wrote:

    1) If I already have some smart-something (two sonoffs, some Tuya rgb lamps) with ready-made ewelink/tuya smart applications, what can be controlled from the phone level after changing the firmware both in the case of https://github.com/arendst/Tasmota or https://github.com/openshwprojects? Am I searching correctly: https://play.google.com/store/apps/details?id=io.homeassistant.companion.android&hl=pl&gl=US

    If you put Home Assistant on an old PC/laptop/Raspberry then you can control Tasmota and OpenBeken devices through Home Assistant.

    If you do not want to put Home Assistant on the server, you can control them through their WWW panels (by IP address) or possibly by the Tasmota Control application which directly controls the devices via HTTP via IP (without the main server, without HA)










    Karol966 wrote:

    2) If I would like to build my own device to be connected to the HA (e.g. 8 relay outputs, 8 digital inputs + several temperature sensors and maybe a power measurement at the same time - such a switchgear combine) there are probably ready-made ones (maybe not all in one, but starting from out/in) what would you recommend?
    (...)
    If I understand correctly, the use of e.g. tasmota according to this guide https://www.elektroda.pl/rtvforum/topic3760371.html#20329687 limits the construction of the device to the selected function from the list.

    Tasmota on ESP (as well as OpenBeken on other platforms) are fully configurable, they can handle a lot, and if you really want to write something DIY yourself, you can put something together from ready-made libraries on platformIO for ESP. I don't know the ready-made, but the device libraries themselves are largely ready-made. I don't know OpenEnergyMonitor, so I won't rate it, maybe there is something better. It's hard for me to give more advice at the moment.



    Karol966 wrote:

    3) I used to make a GSM device that sent data to the server using HTTP POST/GET, I still don't know what works because the server was operated by a colleague, but the data went to the database and from the database to the website. How are devices controlled in popular smart-home devices?

    First of all, MQTT. This is what Home Assistant uses.
    Tasmota Control (Android app) uses Tasmota HTTP:
    https://tasmota.github.io/docs/Commands/
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    OpenBeken also supports this protocol.
    An IoT device can also send GET requests to other devices itself. I'm not sure how it was in Tasmot, but in OpenBeken you can script the sensor so that the measurement result is sent in GET to the PHP server, and this server can save the result to the database.
  • Karol966
    Level 31  
    Great, thanks for the answer, it cleared up a bit for me :)
    p.kaczmarek2 wrote:
    If you don't want to put Home Assistant on the server
    - I want to put up an HA server in the near future, I have new Rpi3B lying around, although I preferred to spend them on building a smart TV (on an old TV with HDMI) and use Orange pi zero for the HA server, so I'm trying to start with the latter according to https://www. home-assistant.io/blog/2017/05/13/home-assistant-on-orange-pi-zero/ but for good morning, logs under my feet - I start the installed balenaEtche and there is a white, empty window. Win7 64b, installed/run as administrator.

    p.kaczmarek2 wrote:
    First of all, MQTT
    - the point is that you need to find an intermediary / broker to have access to our HA from outside the network, yes?
    I will also follow this topic carefully: https://randomnerdtutorials.com/esp32-cloud-mqtt-broker-sim800l/
    I generally have a lot of reading ahead of me.
  • bogran
    Level 6  
    I'm now trying to get the metering to work. I've read e.g Tuya LSPA9 smart socket but it's not too clear to me what actually needs to be done. Previously I've just calibrated according to Tasmota, and setting Power, Voltage and Current. Is that not enough?
  • p.kaczmarek2
    Moderator Smart Home
    In the past you had to manually store IRef, etc, etc in autoexec.bat but it is no longer needed.

    Just use VoltageSet, Currentset, PowerSet and calibration data will be automatically saved.
  • iprak
    Level 5  
    p.kaczmarek2 wrote:
    Dark Man wrote:
    while for the CW bulb it generates only 2 entities (for each channel separately).


    Could you share the mqtt info from HA integration under `Device info` and also the device pin setup itself?
  • bogran
    Level 6  
    p.kaczmarek2 wrote:
    In the past you had to manually store IRef, etc, etc in autoexec.bat but it is no longer needed.
    Just use VoltageSet, Currentset, PowerSet and calibration data will be automatically saved.


    I tried to set but I got Error:CMD:cmd VoltageSet NOT found (args 230). Reading previous posts I guess I have to set the driver, but the docs says "...BL0942, BL0937 power metering chips".
    How do I know which one to set?
  • p.kaczmarek2
    Moderator Smart Home
    If your device is BL0937 version, then just set BL0937 pins in the pins config.

    If your device is BL0942, then type "startDriver BL0942" in short startup command, save and reboot.

    Or.... if you are asking which one you have?

    Then, well, LSPA9 comes is many versions, including BL0942 version and a BL0937 version....
    so maybe.... first start with "startDriver BL0942", reboot, check if measurements are making any sense, does anything show up (without calibration yet), test with 60W bulb, and if still nothing, then try BL0937 approach...

    I assume you don't want to open your device case to check if its 0942 od 0937
  • tryfos79
    Level 1  
    p.kaczmarek2 wrote:
    @ferguson88 I didn't know about LSPA on the W600 beforehand. This is useful information. BL0937 is not compiled there. I can add them to the build and try to run them, can you help with testing if needed?

    I'll try to fix the things you mentioned. I need to find where my W600 dev board is...

    I will also ask @iprak what time he has.


    @ferguson88 @iprak that plug is most probably the notorious Girier 16A JR-PM01, which indeed has the W600 chip (TW-02 V2.0). This is also mentioned here at the end: https://templates.blakadder.com/girier_JR-PM01.html

    I have the same plugs and have been trying for ages to cut the cloud. I haven't opened them but they are reported as "ThingsTurn" in the router, which is self-explanatory ( https://w600.chip.haus/ scroll down to ThingsTurn technology). Some other interesting info here: https://fccid.io/2ASQV-TW-02/User-Manual/User-manual-4211029.pdf
    I regretted the moment I bought them, thinking they had a normal ESP chip.
    There seems to exist a newer(?) version of the same plug with a different Beken chip now (C2BS), as reported here https://www.elektroda.com/rtvforum/topic3937910.html .
    In the past the plug should have had a normal ESP82xx chip too, since it had been reported that tuya-convert used to work (never managed to succeed).
    This is one of the toughest plug cases to open, so I haven't found the courage to try it yet, in order to flash OpenBk. But if BL0937 is not compiled yet, there is no point in risking to break the device by opening it yet, if I lose power readings.
    Tuya-cloudcutter does not support W600, nor of course tuya-convert.
    So no solution after 2-2.5 years with these plugs.
    At this point I think the best solution for full local control+full operation with power readings is to replace the chip with an ESP one. Which is the most compatible ESP with the W600? I mean without having to add resistors etc...
  • iprak
    Level 5  
    Quote:
    BL0937 is not compiled there.
    [/quote]
    I recently pushed a PR for basic driver integration in W600 which includes BL0937. Currently doing more testing on BL0937.
  • bogran
    Level 6  
    p.kaczmarek2 wrote:

    Or.... if you are asking which one you have?

    Then, well, LSPA9 comes is many versions, including BL0942 version and a BL0937 version....
    so maybe.... first start with "startDriver BL0942", reboot, check if measurements are making any sense, does anything show up (without calibration yet), test with 60W bulb, and if still nothing, then try BL0937 approach...


    Yes, that was exactly what I was asking, actually :D .
    942 just gave some ERRORs but 937 worked, so the calibration is set.

    Now I just have to grab the values with the APIs. With Tasmota I could just go with
    http://<host>cm?cmnd=status%208

    I know you mentioned there's no 1 to 1 mapping, but most values in the json returned with
    http://<host>cm?cmnd

    shows wrong stats. E.g. the date & time is wrong, even though I've set NTP, but the index page shows correct date, time, metering etc.
    What's the correct/best way to read the values? MQTT? I'd rather just do http api, if it's possible. Otherwise just parsing the index page might be an alternative as well.

    Added after 4 [hours] 11 [minutes]:

    Just noticed that the data is actually there, but the returned JSON is not properly formatted
    http://<host>/cm?cmnd=status%208
    SyntaxError: JSON.parse: unexpected keyword at line 1 column 167 of the JSON data
    
    Raw Data:
    {"StatusSNS":{"ENERGY":{"Power": 1.428571,"ApparentPower": 0,"ReactivePower": 0,"Factor":0.000000,"Voltage":225.689102,"Current_div100":383.333343,"ConsumptionTotal":nan,"ConsumptionLastHour":0.000000}}}

    nan should probably be returned as null?
  • p.kaczmarek2
    Moderator Smart Home
    Some of the values might be placeholders for testing.
    I will update them for you to show correct values.
    "Current_div100" fixed, NaN should fixed.

    I also updated time formatting in SNS and similar sections, can you check if it's correct now? I will also update it a bit more later.
  • bogran
    Level 6  
    Yes, looks much better. There's only a comma missing just before ENERGY:
    {"StatusSNS":{"Time":"2022-12-17T15:46:12""ENERGY":{"Power": 0.000000,"ApparentPower": 0,"ReactivePower": 0,"Factor":0.000000,"Voltage":226.830215,"Current":383.333343,"ConsumptionTotal":0.000000,"ConsumptionLastHour":0.000000}}}
  • Dark Man
    Level 12  
    p.kaczmarek2 wrote:
    Dark Man wrote:
    Great, great job, but can you somehow make it so that when you hold the button (OnHold), when it reaches 100% brightness, the brightness again starts from zero or starts to go down, and at zero it goes up again.

    Good point, will you check?
    https://github.com/openshwprojects/OpenBK7231...mmit/8bb86176c8e603bb6fa5e73784aff366d8750c00

    It works great - my son (8 years old) is happy and I'm happy, because he used to use some strong dummy wall lamp suspended from the bottom of the bunk bed and often left it on, so now I can turn it off automatically at night and when I'm away from home :)
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant

    I tested it for a while and sometimes it happened that the doubleclick function was activated while holding the button, but I think it's probably the fault of the button itself rather than the program.
  • Karol966
    Level 31  
    Dark Man wrote:
    he often left it on so now I can turn it off automatically at night and when I'm away from home

    It's worth adding a schedule. Personally, I did this with the subwoofer (why should a large transformer work all the time if it is used maybe once a week) Every day at midnight it turns off, it is rarely needed after this hour.

    P.S. It might come in handy soon after midnight, just this once ;)
  • Dark Man
    Level 12  
    Karol966 wrote:
    Dark Man wrote:
    he often left it on so now I can turn it off automatically at night and when I'm away from home

    It's worth adding a schedule.

    The schedule is such a simple antediluvian solution to many other factors :P
    For me, the shutdown is done by Node-red in Home Assistant, e.g. after arming the alarm (we left the house) or after my wife and I go to sleep (both phones will be plugged in for charging after a certain hour ? )
  • p.kaczmarek2
    Moderator Smart Home
    Our new English video guide is up! Special thanks for my assistant for video processing help and the audio recording. Please watch it at:



    and like and subscribe, the next video is almost ready now.
    PS: In the next video, we will flash a LED strip and furthermore we will also add an IR receiver to that (recovered from old TV/VHS scrap board) and maybe even some buttons.
  • p.kaczmarek2
    Moderator Smart Home
    Our teardowns/device templates list has been updated with tutorial videos from Elektroda.com YT channel! Please visit our page here:
    https://openbekeniot.github.io/webapp/devicesList.html
  • omelchuk890
    Level 10  
    Happy Christmas!
    Hello everyone.
    I use modules to manage loads from different manufacturers, updating them with this firmware. I don't use any lighting devices with built-in modules. Therefore, for me, so far these are just wireless relays, nothing more than.
    However, I would like to add local adjustment in some places using a simple DS18B20 or DHT22 or....
    At the moment I have not found any mention of any plans to support such sensors.
    I would like to know if there are any ideas/ prospects in this direction?
    Is there any road map that you follow?