Custom firmware ESPHome-Xiaomi_bslamp2

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

@mmakaay
After reading this thread I bought the lamp last week and directly flashed ESPHome according to the great instructions on your Github pages.
The current version works for me without problems with ESPHome 1.19.4.
Thanks for the great work! This makes the lamp directly much more attractive.

1 Like

That is so sweet. Seeing people actually buying the lamp because of the ESPHome option. Thanks!

1 Like

A fun new development. Take a look at this front panel :smiley:
Found this while tinkering with the I2C interface of the front panel, to solve issue / feature request #38 on GitHub. I can turn on and off the individual LEDs of the brightness bar.

I’ll update the front panel HAL with the new knowledge, so we can use this from our YAML files.

1 Like

Released V1.1.0

Today, ESPHome v1.20.0 was released.
It contains a couple of changes that I was waiting for before declaring the v1.1.0 release stable.

The main changes for this release:

  • It is now possible to address the LEDs in the front panel of the device individually.
  • Implemented support for visual feedback during the OTA update process in the example.yaml file.
  • Made it possible to use lambdas with the preset.activate automation

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

Upgrading an existing lamp

When you want to upgrade, then make sure that you are running ESPHome v1.20.0 or later.
In the YAML configuration, it is best to use ref: v1.1.0 explicitly to make use of this release.

external_components:
  - source:
      type: git
      url: https://github.com/mmakaay/esphome-xiaomi_bslamp2
      ref: v1.1.0

You could also use ref: main, but when doing so, beware that ESPHome might be running
off an older version of the code, because external_components: doesn’t currently pull fresh
code from GitHub when starting a compile.

Demo

Here’s a quick demo video of something that I was able to do with the new codebase:

  • Not filling up the brightness bar, but only lighting up a sngle LED on the slider to indicate the active brightness
  • A little animation when turing off the lamp.

For some more information on this, check out GitHub issue #38 that triggered the development of the new feature.

3 Likes

Hello mmakaay.
I couldn’t make the button to glow.
Could not tell the newbie in more detail where to register. And the code in the documentation is not complete, not clear.
on _…:
then:
- front_panel.set_leds: POWER
Can I have the complete code?

Can you explain exactly how you want the front panel light to work? Or post your code so we can see what you did try yourself.
Currently I have no way of telling what you are trying to accomplish, so it’s not possible to give you some example code.

According to your article “leaving the power button on at night, so the user can easily find it in the dark” I want to make sure that the backlight on the button is constantly on. Can you do this?

  • platform: xiaomi_bslamp2
    id: my_bedside_lamp_power
    on_value:
    then:
    - front_panel.turn_on_leds: POWER
    This does not work, the code was laid down in yaml