Custom firmware ESPHome-Xiaomi_bslamp2

That looks like the disconnect behaviour in the underlying AsyncTCP library. I ran into that too (somewhere high up in this huge thread :yum:) and have since come up with a fix.

The fix will likely be automatically included in ESPHome 1.18.0 (the next release).

If you want to try the fix before that: I wrote up some info in the related pull request: Better fix for "ack timeout 4" client disconnects. by mmakaay · Pull Request #5 · OttoWinter/AsyncTCP · GitHub

1 Like

Actually, I have tried this workaround already, but did not " edit libs/AsyncTCP/library.json and change the version line from "1.2.1" to "1.1.1""

It’s not mentioned here, maybe you could just add that step to have it complete:

esphome-xiaomi_bslamp2/doc/known_issues.md at 1b09849842f803decacbdf203ca648dcbc88a188 · mmakaay/esphome-xiaomi_bslamp2 · GitHub

But now with also changing the version within the libs/AsyncTCP/library.json that did the trick for me and the log book entries disappeared.

Thanks again for your quick help!

1 Like

Initially, the version change was not needed, but with the code advancing, things changed.
I will take a look at those docs.

Thanks for confirming the fix!

Hello !

First of all : a BIG thank you for your incredible work. I bought my lamp at around the time you started this project (it was a happy coincidence) and now that I got it, it works like a charm.

I managed to flash without a serial adapter but using a spare ESP8266 I had. The key is to ground the “EN” pin, and then connect RX-RX and TX-TX without crossing. It then worked with ESPflash (but not with esptool, I couldn’t make a backup of the original firmware).

I was wondering : is the inside of the lamp made of one unique big LED or multiples leds ? If it’s multiple leds I thought a candle/fire effect would be nice, with different tones of red and oranges alternating. Even with one unique led it could be nice if done correctly. Is it something you could maybe implement ?

Thanks again :slight_smile:

There is multiple LED’s inside the lamp but they are not individually addressable and therefore can’t be individually controlled. There is already multiple effects made for this lamp and you can make pretty much whatever effect that you like. Can’t wait to see what craziness that will spawn from this! :grin:

Are you sure they are not individually addressable ? Maybe someone can find a hacky way ?
Is there a guide to get more light effect on homeassistant than slow random and fast random ? I wonder what kind of other effects there are.
Personally I set up this and it works great : https://community.home-assistant.io/t/wake-up-light-alarm-with-sunrise-effect/

I’m pretty sure of this. You shouldn’t look at this lamp as a Yeelight lamp anymore after flashing mmakaay’s FW, so forget about the Yeelight integration. Have a look at ESPHome and customise all you want!

Yes, I’m very sure too. The LEDs are not individually addressable.
This circuit is not something like a WS2812, rolled up in the lamp (that was actually one of the possible crude hacks I had in mind, in case I wouldn’t be able to replace the firmware with something working).

I have been thinking about adding a LED strip in the inner cone of the lamp, and drive that from a free pin (there are a number of those), specifically for something like a flame or a rotating flashing light. That would be quite a stand-alone hack though, which would even represent itself as a separate light in Home Assistant. Not a change to the lamp’s firmware.

Thanks for the wake up light post, @nmb02x5pk7if
My Bedside Lamp in the bedroom is mainly meant as a wake up light.
I will try your the blueprint for mine. My current implementation is a very crude hack, that deserves some improvement.

Yes! ESPHome 1.18.0 is out, with some changes that will make it possible to use the lamp component from a vanilla YAML config file. No more downloading and installing of code is needed.

I will update the repository structure to support this and bring out the final V1.0.0 release of the code for the firmware.

Version 1.0.0 released!

Recently, ESPHome v1.18.0 was released. It contains a few features that I was waiting for before declaring the Xiaomi Bedside Lamp 2 code stable. So now the time has come to publish the stable v1.0.0 release.

See the CHANGELOG.md in the repo for a full list of changes.

Migration info for existing users

Patched AsyncTCP-esphome against API disconnect issues

If you have been using the patched version of AsyncTCP-esphome to get rid of disconnect issues, combined with lib_extra_dirs in your platformio_options, then you can delete the patched version and remove the lib_extra_dirs from your YAML config. The required changes for AsyncTCP-esphome are now included automatically by ESPHome.

Downloaded component code

If you have been using the component code by downloading it to custom_components/xiaomi_bslamp2 up to now, then you can delete that directory, and instead add the following to your YAML config:

# Retrieve the code for the xiaomi_bslamp2 platform from GitHub.
external_components:
  - source:
      type: git
      url: https://github.com/mmakaay/esphome-xiaomi_bslamp2
      ref: main

If you want to keep using a cloned repo instead (e.g. for developing on the code), then you can for example create a directory <CONFIG_DIR>/src and clone the repository there. Then you can add the following to your YAML to point the build at it:

external_components:
  - source:
      type: local
      path: src/xiaomi_bslamp2/components
6 Likes

@mmakaay I am currently trying to disassemble my bedside lamp v1. But i am not able to remove the control board (with the important chips) which was in your last picture. It seems like it is glued to the bottom. I tried many tools and also a hair dryer without success. Do you have any idea?

Ehm, that lookx a lot like not a Bedside Lamp 2.
Is it a version 1 by any chance?

Yes it is a v1, i also wrote that in my post :smile: Also see the mention of my post which links to an older post of you.

Ah yes, sorry, on my phone here and a bit distracted by the television :grinning_face_with_smiling_eyes:

If you want to go into hacking this lamp, I think a new thread would be appropriate, sind this thread is about the V2, which is quite a different beast.

I looked at buying a v1 myself, to see what I could make of it, but I have no direct use for it myself and found it a bit too expensive for hacking purposes aline. So I don’t think I can help you any further with this one.

The bslamp v1 has a Mediatek ARM MT7697N chip, so unfortunately ESPHome won’t work on it.

That’s a shame :unamused:

Hello.
Python 3.9.5
ESPHome 1.18.0

C:\Users\sevif\Desktop\project>esphome example.yaml compile
←[32mINFO Reading configuration example.yaml...←[0m
←[31mERROR Unexpected exception while reading configuration:←[0m
Traceback (most recent call last):
  File "c:\users\sevif\appdata\local\programs\python\python39-32\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\sevif\appdata\local\programs\python\python39-32\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\sevif\AppData\Local\Programs\Python\Python39-32\Scripts\esphome.exe\__main__.py", line 7, in <module>
  File "c:\users\sevif\appdata\local\programs\python\python39-32\lib\site-packages\esphome\__main__.py", line 642, in main
    return run_esphome(sys.argv)
  File "c:\users\sevif\appdata\local\programs\python\python39-32\lib\site-packages\esphome\__main__.py", line 620, in run_esphome
    config = read_config(dict(args.substitution) if args.substitution else {})
  File "c:\users\sevif\appdata\local\programs\python\python39-32\lib\site-packages\esphome\config.py", line 797, in read_config
    res = load_config(command_line_substitutions)
  File "c:\users\sevif\appdata\local\programs\python\python39-32\lib\site-packages\esphome\config.py", line 642, in load_config
    return _load_config(command_line_substitutions)
  File "c:\users\sevif\appdata\local\programs\python\python39-32\lib\site-packages\esphome\config.py", line 630, in _load_config
    result = validate_config(config, command_line_substitutions)
  File "c:\users\sevif\appdata\local\programs\python\python39-32\lib\site-packages\esphome\config.py", line 337, in validate_config
    do_external_components_pass(config)
  File "c:\users\sevif\appdata\local\programs\python\python39-32\lib\site-packages\esphome\components\external_components\__init__.py", line 197, in do_external_components_pass
    _process_single_config(c)
  File "c:\users\sevif\appdata\local\programs\python\python39-32\lib\site-packages\esphome\components\external_components\__init__.py", line 131, in _process_single_config
    ret = subprocess.run(cmd, capture_output=True, check=False)
  File "c:\users\sevif\appdata\local\programs\python\python39-32\lib\subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "c:\users\sevif\appdata\local\programs\python\python39-32\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "c:\users\sevif\appdata\local\programs\python\python39-32\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] system cannot find file specified

I see that you are compiling under windows.
I installed ESPHome 1.18.0, with python 3.8.5 (I don’t think this version really matters) and I was able to compile the example.yaml as bundled in the repository.

Based on the error messages that I see, it looks like things go wrong at the point where the external component with the code for the lamp is being retrieved from github. The error message might suggest that the git application is not available on your system.

So, can you confirm that if you run git on the command line, that this program cannot be found?
If not, then please download and install git from the git download page.

You’re right. Git was not installed. Thanks, it worked.

1 Like

Released v1.1.0-RC1

See the release page on GitHub

Due to some internal changes in the ESPHome code, the Bedside Lamp 2 code did not compile anymore. This release updates the code to be compatible with ESPHome v1.19.0 (which is from now on also the minimal version of ESPHome that can be used to compile the firmware).

Here is the full changelog:

  • Made it possible to use lambdas with the preset.activate automation. This makes it possible to link the action to an api service, which exposes the preset functionality to Home Assistant. The example.yaml has been updated with an example for this.
  • Fixed a rounding error in the slider sensor component. When using custom “range from” / “range to” settings, the maximum value could exceed the “range to” value due to rounding errors. Thanks to Jos for the heads up!
  • Made the codebase compatible with ESPHome v1.19.0 (PR #1657: Introduce new async-def coroutine syntax) Thanks to @Kaibob2 for giving me a heads up that my code was not compiling anymore!

When no problems are reported with this release candidate, I will promote this version as the v1.1.0 stable later this week.

2 Likes