mmakaay / esphome-xiaomi_bslamp2 Goto Github PK
View Code? Open in Web Editor NEWESPHome integration for the Xiaomi Mijia Bedside Lamp v2.
License: Other
ESPHome integration for the Xiaomi Mijia Bedside Lamp v2.
License: Other
Describe the bug
A clear and concise description of what the bug is.
I'm getting an error with importing the component on validating the esphome firmware.
ERROR Unable to import component xiaomi_bslamp2.light:
Traceback (most recent call last):
File "/esphome/esphome/loader.py", line 162, in _lookup_module
module = importlib.import_module(f"esphome.components.{domain}")
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/config/esphome/.esphome/external_components/d1d49d2c/components/xiaomi_bslamp2/__init__.py", line 6, in <module>
from esphome.components.i2c import I2CComponent, I2CDevice
ImportError: cannot import name 'I2CComponent' from 'esphome.components.i2c' (/esphome/esphome/components/i2c/__init__.py)
ERROR Unable to import component xiaomi_bslamp2.text_sensor:
Traceback (most recent call last):
File "/esphome/esphome/loader.py", line 162, in _lookup_module
module = importlib.import_module(f"esphome.components.{domain}")
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/config/esphome/.esphome/external_components/d1d49d2c/components/xiaomi_bslamp2/__init__.py", line 6, in <module>
from esphome.components.i2c import I2CComponent, I2CDevice
ImportError: cannot import name 'I2CComponent' from 'esphome.components.i2c' (/esphome/esphome/components/i2c/__init__.py)
ERROR Unable to import component xiaomi_bslamp2.output:
Traceback (most recent call last):
File "/esphome/esphome/loader.py", line 162, in _lookup_module
module = importlib.import_module(f"esphome.components.{domain}")
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/config/esphome/.esphome/external_components/d1d49d2c/components/xiaomi_bslamp2/__init__.py", line 6, in <module>
from esphome.components.i2c import I2CComponent, I2CDevice
ImportError: cannot import name 'I2CComponent' from 'esphome.components.i2c' (/esphome/esphome/components/i2c/__init__.py)
ERROR Unable to import component xiaomi_bslamp2.binary_sensor:
Traceback (most recent call last):
File "/esphome/esphome/loader.py", line 162, in _lookup_module
module = importlib.import_module(f"esphome.components.{domain}")
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/config/esphome/.esphome/external_components/d1d49d2c/components/xiaomi_bslamp2/__init__.py", line 6, in <module>
from esphome.components.i2c import I2CComponent, I2CDevice
ImportError: cannot import name 'I2CComponent' from 'esphome.components.i2c' (/esphome/esphome/components/i2c/__init__.py)
ERROR Unable to import component xiaomi_bslamp2.binary_sensor:
Traceback (most recent call last):
File "/esphome/esphome/loader.py", line 162, in _lookup_module
module = importlib.import_module(f"esphome.components.{domain}")
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/config/esphome/.esphome/external_components/d1d49d2c/components/xiaomi_bslamp2/__init__.py", line 6, in <module>
from esphome.components.i2c import I2CComponent, I2CDevice
ImportError: cannot import name 'I2CComponent' from 'esphome.components.i2c' (/esphome/esphome/components/i2c/__init__.py)
ERROR Unable to import component xiaomi_bslamp2.sensor:
Traceback (most recent call last):
File "/esphome/esphome/loader.py", line 162, in _lookup_module
module = importlib.import_module(f"esphome.components.{domain}")
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/config/esphome/.esphome/external_components/d1d49d2c/components/xiaomi_bslamp2/__init__.py", line 6, in <module>
from esphome.components.i2c import I2CComponent, I2CDevice
ImportError: cannot import name 'I2CComponent' from 'esphome.components.i2c' (/esphome/esphome/components/i2c/__init__.py)
Failed config
Here is my .yaml file:
substitutions:
name: bedside-lamp
friendly_name: Bedside Lamp
transition_length: 500ms
# Component identifiers.
prefix: bedside_lamp
id_light: ${prefix}
id_light_mode: ${prefix}_light_mode
id_power_button: ${prefix}_power_button
id_color_button: ${prefix}_color_button
id_slider_level: ${prefix}_slider_level
id_front_panel_illumination: ${prefix}_front_panel_illumination
# --------------------------------------------------------------------------
# Use your own preferences for these components.
# --------------------------------------------------------------------------
wifi:
ssid: "xxxx"
password: "xxxxx"
# Enable fallback hotspot (for captive portal) in case wifi connection fails
ap:
ssid: "ESPHome $friendly_name"
password: "Password-For-Connecting-To-Captive-Portal"
captive_portal:
api:
# Disable the reboot timeout. By default, the lamp reboots after 15
# minutes without any client connections (e.g. when home assistant is off
# line, or when the WiFi is broken). Reboots are annoying though, because
# the RGBWW LEDs will turn off during the reboot, causing the light to
# flicker.
reboot_timeout: 0s
ota:
password: "123456"
# The log level can be raised when needed for debugging the firmware. For
# production, a low log level is recommended. Mainly because high volume log
# output might interfere with the API/WiFi connection stability. So when
# raising the log level, beware that you might see dropped connections from
# Home Assistant and the network log viewer.
logger:
level: WARN
# --------------------------------------------------------------------------
# Configuration specific for the Xiaomi Mijia Bedside Lamp 2.
# This is just an example. You can of course modify it for your own needs.
# --------------------------------------------------------------------------
# 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
refresh: 60s
# A special platform package is used for enabling unicore and disabling the
# efuse mac crc check. These two changes are required for the ESP32-WROOM-32D
# chip that is used in the lamp.
esphome:
name: ${name}
platform: ESP32
board: esp32doit-devkit-v1
platformio_options:
platform: [email protected]
platform_packages: |-
framework-arduinoespressif32 @ https://github.com/mmakaay/arduino-esp32-unicore-no-mac-crc#v1.0.6
# This component controls the LED lights of the lamp.
light:
- platform: xiaomi_bslamp2
id: ${id_light}
name: ${friendly_name} RGBWW Light
default_transition_length: ${transition_length}
# When the brightness is changed, then update the level indicator
# on the front panel accordingly. In night light mode, turn off
# the front panel illumination.
on_brightness:
- if:
condition:
text_sensor.state:
id: ${id_light_mode}
state: night
then:
- output.set_level:
id: ${id_front_panel_illumination}
level: 0
else:
- output.set_level:
id: ${id_front_panel_illumination}
level: !lambda return x;
# You can use any effects that you like. These are just examples.
effects:
- random:
name: "Slow Random"
transition_length: 30s
update_interval: 30s
- random:
name: "Fast Random"
transition_length: 3s
update_interval: 3s
# You can define one or more groups of presets. These presets can
# be activated using various "preset.activate" action options.
# The presets can for example be used to mimic the behavior of the
# original firmware (tapping the color button = go to next preset,
# holding the color button = switch between RGB and white light mode).
# These bindings have been setup below, using the binary_sensor for
# the color button.
presets:
rgb:
red: { red: 100%, green: 0%, blue: 0% }
green: { red: 0%, green: 100%, blue: 0% }
blue: { red: 0%, green: 0%, blue: 100% }
yellow: { red: 100%, green: 100%, blue: 0% }
purple: { red: 100%, green: 0%, blue: 100% }
randomize: { effect: Fast Random }
white:
cold: { color_temperature: 153 mireds }
chilly: { color_temperature: 275 mireds }
luke: { color_temperature: 400 mireds }
warm: { color_temperature: 588 mireds }
# This text sensor propagates the currently active light mode.
# The possible light modes are: "off", "rgb", "white" and "night".
# By setting the name, the text_sensor will show up as an entity
# for the lamp in Home Assistant.
text_sensor:
- platform: xiaomi_bslamp2
name: ${friendly_name} Light Mode
id: ${id_light_mode}
# This float output controls the front panel illumination + level indicator.
# Value 0.0 turns off the illumination. Other values (up to 1.0) turn on
# the illumination and set the level indicator to the requested level.
output:
- platform: xiaomi_bslamp2
id: ${id_front_panel_illumination}
# Binary sensors can be created for handling front panel touch / release
# events. To specify what part of the front panel to look at, the "for"
# parameter can be set to: "POWER_BUTTON", "COLOR_BUTTON" or "SLIDER".
binary_sensor:
# When tapping the power button, toggle the light.
# When holding the power button, turn on night light mode.
- platform: xiaomi_bslamp2
id: ${id_power_button}
for: POWER_BUTTON
on_multi_click:
- timing:
- ON for at most 0.8s
then:
- light.toggle: ${id_light}
- timing:
- ON for at least 0.8s
then:
- light.turn_on:
id: ${id_light}
brightness: 1%
# When tapping the color button, acivate the next preset.
# When holding the color button, activate the next preset group.
- platform: xiaomi_bslamp2
id: ${id_color_button}
for: COLOR_BUTTON
on_multi_click:
- timing:
- ON for at most 0.6s
then:
- preset.activate:
next: preset
- timing:
- ON for at least 0.6s
then:
- preset.activate:
next: group
# This sensor component publishes touch events for the front panel slider.
# The published value represents the level at which the slider was touched.
# By default, values range from 0.01 to 1.00 (in 20 steps). This range can
# be modified using the "range_from" and "range_to" parameters.
sensor:
# When the slider is touched, update the brightness.
# Brightness 0.01 initiates the light night mode, which has already
# been handled above (by holding the power button). Therefore, brightness
# starts from 0.02 here, to not trigger night mode using the slider.
- platform: xiaomi_bslamp2
id: ${id_slider_level}
range_from: 0.02
on_value:
then:
- light.turn_on:
id: ${id_light}
brightness: !lambda return x;
```
I'm using ESPHome v2021.10.3
Describe the bug
Hello,
So when I try to flash the firmware I get "Unexpected error: ESP Chip Auto-Detection failed: Failed to connect to Espressif device: No serial data received." error.
To Reproduce
Steps to reproduce the behavior:
Additional context
If I connect the lamp without entering flashing mode I can see the lamp logs like "looking for WiFi", "Turn on and off actions", etc, so I believe it is not a problem related with the serial connector/drivers/etc
Also on the ESPHome device YAML I only added the example provided with different SSID access and related
Hiya
It's not maybe an"issue" but i don't know exactly how to recreate previous behaviour.
Issue description:
On previous config, after power outage, lamp was returning to it's previous state. (on, color, light)
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I would like to keep state which lamp was before power disconnection.
Please advise.
Kind regards.
Kind regards.
Hi guy,
Sorry still some questions before entering in this new World.
After flashing ESPHome firmware, how can we directly control the lamp?
Which application?
And would it be possible to integrate the lamp in Google Home without HA?
Thanks again for your answer.
Is your feature request related to a problem? Please describe.
When using the original firmware for the Bedside Lamp 2, one can configure two sets of preset light colors: one for RGB light, and one for white color-temperature-based light. Using the color button, one can switch between these two sets (long press) and between the presets within such set (short press).
It would be awesome provide easy to use support for this.
Describe the solution you'd like
presets
configuration option for the light.Services are exposed to allow switching to a specific set, the next set, a specific preset or the next preset.
With these in place, we have a very flexible manner to re-implement the original behavior, as well as new behaviors.
Describe alternatives you've considered
I've looked for some sort of scenes support within the ESPHome context, but haven't found it.
Even if scene support does exist, we still need a data structure for handling the "sets of presets" setup.
We could let a preset reference a scene in such case though, to reuse its functionality.
Another way that one could handle things, is by not making the lamp smarter, but by offloading the scene knowledge to Home Assistant. The lamp configuration could fire some events in response to touch events for the color button, and Home Assistant could pick up on these by setting the scene for the lamp.
This is a good alternative, but I think that it might become a bit cumbersome to implement a behavior that looks like the original behavior in such way.
Describe the bug
When I turn on the night mode on the lamp, it turns on the green backlight
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I expect to see a red backlight
There is a second similar lamp, it shows red light as it should be. Firmware is the same. bedside-lamp2-1.txt
as if there is no red at minimum brightness.
How can you fix the problem?
Describe the bug
I'm unable to flash ESPHome firmware onto my xiaomi_bslamp2 using ESPHome 1.20.4 on hassio. See attached files for my config and the flash log. These errors look to be of interest:
src/esphome/components/xiaomi_bslamp2/light/color_rgb_light.h:255:11: error: 'class esphome::light::LightColorValues' has no member named 'get_color_mode'
src/esphome/components/xiaomi_bslamp2/light/color_rgb_light.h:255:38: error: 'esphome::light::ColorMode' has not been declared
src/esphome/components/xiaomi_bslamp2/light/light_output.h:31:12: error: 'class esphome::light::LightTraits' has no member named 'set_supported_color_modes'
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The device to successfully flash.
Additional context
Using a Raspberry Pi 4, Home Assistant 2021.8.4, ESPHome 1.20.4 via supervisor.
xiaomi_bslamp2_esphome1.20.4_config_yaml_8August2021.txt
xiaomi_bslamp2_esphome1.20.4_flashlog_8August2021.txt
hassio_config.txt
Is your feature request related to a problem? Please describe.
I have a raspberrypi and no TTL adapter. I'm also on iobroker instead of home-assistant.
I'm not very familiar with serial flashing firmwares.
I think there are a lot of people out there with the same requirements than me.
Is there any chance to modify the tutorial how to flash with rpi + female-to-male-wires? I also need support for compiling the firmware or is it also possible to simply flash tasmota?
Describe the solution you'd like
Open the lamp, connect the rpi directly via female-to-male-wires with the lamp, flash.
Describe alternatives you've considered
Buying a FTDI adapter which will never be used again.
I have a separate repository that holds the information that I gathered during reverse engineering the Bedside Lamp 2.
I would like the relevant information to be included in the component repository.
First thanks a lot for this firmware, it gave new life to a garbage object after Xiaomi decided to remove lan functionality!
The firmware is working great, but I'd like to edit it to have just the power button illumination always on. I struggled a bit in the configuration, but I guess I'm missing something isolating the sole power button.
Can you please give a hint to accomplish this functionality?
How to emplement candle effect using only white cold and warm led?
Is your feature request related to a problem? Please describe.
When I use the lamp for something like a disco light or make it work in conjuction with ambilight for my tv, the lamp status is both published and saved. I do not want this to be done.
I also want the disco_on action to be executed right away, and not at the next loop() for the light component. This way, the action could be used from within components that grab the loop for a long time. The most clear example of this would be the OTA upgrade loop. I would like to provide some progress feedback using the lamp's colors. However, using the available tooling, this is not possible, because the OTA code blocks all other code during the upgrade.
Describe the solution you'd like
An action "disco_on" that takes light settings as its input and pushes the state change directly to the LEDs, without storing or publishing the new state.
An action "disco_off" that restores the light settings as they are currently stored in the RTC memory.
Greetings, I was hoping maybe there could be a support for Yeelight LED Smart LAMP D2 - YLCT01YL.
The board looks
similar to the one here, yet simpler.
It's micro processor is ESP-WROOM-32D
(esp32).
I attached a few photos as well.
It has two touch controls whose controller is ChipON KF8TS2716.
I haven't even turned it on. I hope somebody could guide me before I return it
!
The branding for this lamp is a bit of a mess on the internet, since it's offered both as "Xiaomi Mijia Bedside Lamp 2" and "Yeelight Bedside Lamp 2". When I bought mind, the name "Xiaomi" was nowhere to be found in the ordering process.
Yeelight appears to be the production company, whereas Xiaomi Mijia might be the actual intended brand for the device.
The device firmware identifies as "yeelink.light.bslamp2" BTW, just to make things
One pro of keeping "Xiaomi", would be that it fits nicely next to other xiaomi components that are already in ESPHome. These are all named like "xiaomi_". So when renaming the component, I would probably go for "xiaomi_bslamp2".
Any thoughts on this?
just took the example.yaml and supplied a secrets.yaml
when I do a
esphome config example.yaml
I get
INFO Updating https://github.com/mmakaay/esphome-xiaomi_bslamp2@dev
ERROR Unexpected exception while reading configuration:
Traceback (most recent call last):
File "/usr/bin/esphome", line 33, in <module>
sys.exit(load_entry_point('esphome==2021.10.2', 'console_scripts', 'esphome')())
File "/usr/lib/python3.9/site-packages/esphome/__main__.py", line 815, in main
return run_esphome(sys.argv)
File "/usr/lib/python3.9/site-packages/esphome/__main__.py", line 793, in run_esphome
config = read_config(dict(args.substitution) if args.substitution else {})
File "/usr/lib/python3.9/site-packages/esphome/config.py", line 974, in read_config
res = load_config(command_line_substitutions)
File "/usr/lib/python3.9/site-packages/esphome/config.py", line 829, in load_config
return _load_config(command_line_substitutions)
File "/usr/lib/python3.9/site-packages/esphome/config.py", line 817, in _load_config
result = validate_config(config, command_line_substitutions)
File "/usr/lib/python3.9/site-packages/esphome/config.py", line 674, in validate_config
result[CONF_SUBSTITUTIONS] = {
TypeError: 'NoneType' object is not a mapping
not sure who is to blame. However I successfully compiled a new project created with esphome wizard
to confirm my installation is working in principle. Any idea what to check or try? Thanks for this awesome project!
Describe the bug
Won't compile with ESPHOME 1.19.1
To Reproduce
Steps to reproduce the behavior:
Upgrade ESPHOME from last version to 1.19.1
Try to install the freshly compiled firmware
Expected behavior
Compiles fine and uploads like it did before
Additional context
LOGFILE from ESPHOME compile:
INFO Reading configuration /config/esphome/yeelight.yaml...
INFO Generating C++ source...
/config/esphome/.esphome/external_components/d1d49d2c/components/xiaomi_bslamp2/__init__.py:68: RuntimeWarning: coroutine 'gpio_pin_expression' was never awaited
yield from cg.gpio_pin_expression({ "number": number, "mode": mode });
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
File "/usr/local/bin/esphome", line 33, in <module>
sys.exit(load_entry_point('esphome', 'console_scripts', 'esphome')())
File "/opt/esphome/esphome/__main__.py", line 738, in main
return run_esphome(sys.argv)
File "/opt/esphome/esphome/__main__.py", line 725, in run_esphome
rc = POST_CONFIG_ACTIONS[args.command](args, config)
File "/opt/esphome/esphome/__main__.py", line 332, in command_run
exit_code = write_cpp(config)
File "/opt/esphome/esphome/__main__.py", line 144, in write_cpp
generate_cpp_contents(config)
File "/opt/esphome/esphome/__main__.py", line 156, in generate_cpp_contents
CORE.flush_tasks()
File "/opt/esphome/esphome/core/__init__.py", line 596, in flush_tasks
self.event_loop.flush_tasks()
File "/opt/esphome/esphome/coroutine.py", line 245, in flush_tasks
next(task.iterator)
File "/opt/esphome/esphome/__main__.py", line 136, in wrapped
await coro(conf)
File "/opt/esphome/esphome/coroutine.py", line 79, in coro
ret = yield from _flatten_generator(gen)
File "/opt/esphome/esphome/coroutine.py", line 134, in _flatten_generator
to_send = yield from _flatten_generator(val)
File "/opt/esphome/esphome/coroutine.py", line 117, in _flatten_generator
val = gen.send(to_send)
File "/opt/esphome/esphome/coroutine.py", line 79, in coro
ret = yield from _flatten_generator(gen)
File "/opt/esphome/esphome/coroutine.py", line 134, in _flatten_generator
to_send = yield from _flatten_generator(val)
File "/opt/esphome/esphome/coroutine.py", line 117, in _flatten_generator
val = gen.send(to_send)
File "/opt/esphome/esphome/coroutine.py", line 79, in coro
ret = yield from _flatten_generator(gen)
File "/opt/esphome/esphome/coroutine.py", line 134, in _flatten_generator
to_send = yield from _flatten_generator(val)
File "/opt/esphome/esphome/coroutine.py", line 117, in _flatten_generator
val = gen.send(to_send)
File "/opt/esphome/esphome/coroutine.py", line 79, in coro
ret = yield from _flatten_generator(gen)
File "/opt/esphome/esphome/coroutine.py", line 117, in _flatten_generator
val = gen.send(to_send)
File "/config/esphome/.esphome/external_components/d1d49d2c/components/xiaomi_bslamp2/__init__.py", line 68, in make_gpio
yield from cg.gpio_pin_expression({ "number": number, "mode": mode });
TypeError: cannot 'yield from' a coroutine object in a non-coroutine generator
Yesterday evening I started my two hourly adventure of flashing my bslamp2's.
I'm quite happy with the results, so great job on this custom firmware! It offers me a lot of customizability which I yet have to discover how everything works.
Describe the bug
The only thing that bothers me slightly is when you are using colortemp mode and you turn the lamp on it will first flash lightblue for half a second and even longer when you hold the brightness adjuster.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
When you turn on your lamp in colortemp mode you expect it to go into the last color straight away, if that's not possible then just make a small delay where the lamp turns on a little bit later.
I tried today to compile firmware using example.yaml on this github. It returned an error using the ESPHome dashboard:
[refresh] is an invalid option for [source]. Did you mean [ref]?
refresh: 60s [source /home/maarten/config/example.yaml:118]
I'm not an expert in Esphome, but changing the indentation of refresh: 60s
seems to have solved the problem and I have successfully flashed my bslamp2.
external_components:
- source:
type: git
url: https://github.com/mmakaay/esphome-xiaomi_bslamp2
ref: main
refresh: 60s
As I'm not sure this is the correct solution I leave it here as a bug.
I compiled the firmware to my needs and managed to flash it, but it doesn't boot.
The device won't boot. I tried a blank ESPhome instance, also a Tasmota32 binary. Could flash both of them, but the device does not boot any of the firmwares.
Do you have any idea, where the problem could be?
Updated ESPHome to latest version and requested to updated lamps firmware. I did, the update seems sucessful looking to the OTA Feedback (green at the end) and then I get these errors:
RAM: [= ] 9.9% (used 32328 bytes from 327680 bytes)
Flash: [==== ] 44.7% (used 819817 bytes from 1835008 bytes)
Building .pioenvs/bedsidelampdiana/firmware.bin
========================= [SUCCESS] Took 13.34 seconds =========================
INFO Successfully compiled program.
INFO Connecting to 192.168.3.231
INFO Uploading /config/.esphome/build/bedsidelampdiana/.pioenvs/bedsidelampdiana/firmware.bin (819952 bytes)
Uploading: [============================================================] 100% Done...
INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from 192.168.3.231 using esphome API
Traceback (most recent call last):
File "/usr/local/bin/esphome", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.9/dist-packages/esphome/main.py", line 823, in main
return run_esphome(sys.argv)
File "/usr/local/lib/python3.9/dist-packages/esphome/main.py", line 810, in run_esphome
rc = POST_CONFIG_ACTIONS[args.command](args, config)
File "/usr/local/lib/python3.9/dist-packages/esphome/main.py", line 391, in command_run
return show_logs(config, args, port)
File "/usr/local/lib/python3.9/dist-packages/esphome/main.py", line 282, in show_logs
return run_logs(config, port)
File "/usr/local/lib/python3.9/dist-packages/esphome/components/api/client.py", line 72, in run_logs
asyncio.run(async_run_logs(config, address))
File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/usr/local/lib/python3.9/dist-packages/esphome/components/api/client.py", line 24, in async_run_logs
zc = zeroconf.Zeroconf()
File "/usr/local/lib/python3.9/dist-packages/zeroconf/_core.py", line 447, in init
listen_socket, respond_sockets = create_sockets(interfaces, unicast, ip_version, apple_p2p=apple_p2p)
File "/usr/local/lib/python3.9/dist-packages/zeroconf/_utils/net.py", line 373, in create_sockets
if add_multicast_member(cast(socket.socket, listen_socket), i):
File "/usr/local/lib/python3.9/dist-packages/zeroconf/_utils/net.py", line 288, in add_multicast_member
listen_socket.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, _value)
OSError: [Errno 105] No buffer space available
Is your feature request related to a problem? Please describe.
Even though the component code was written in such way to minimize the code required in the yaml configuration, the full setup can still be quite big. This is okay for users who want to tweak their lamp's configuration to their needs. However, it might be a bit overwhelming for users that simply want the lamp's firmware to behave light the original Xiaomi firmware.
Describe the solution you'd like
It might be useful to have a default configuration available that can be included through the packages system. I haven't looked into the details of it, but from what I have seen it might be the way to go.
Describe alternatives you've considered
It is also possible to make use of include statements, but IMO include statements are a better fit for local organization of the yaml configuration files.
You moved recently from
esp32:
board: esp32doit-devkit-v1
framework:
type: arduino
platform_version: 3.3.2
version: https://github.com/mmakaay/arduino-esp32-unicore-no-mac-crc#v1.0.6
version_hint: 1.0.6
to
esp32:
board: esp32doit-devkit-v1
framework:
type: esp-idf
sdkconfig_options:
CONFIG_FREERTOS_UNICORE: y
advanced:
ignore_efuse_mac_crc: true
Could you explain the benefits? It is safe and well tested?
The current implementation of my component had to jump some hoops to get access to the light transformer, in order to implement the color transformations correctly for the Bedside Lamp 2.
There's now a change in the ESPHome light code that might let me implement things a lot cleaner.
See: esphome/esphome#2124
So, let's see if I can remove some hoops!
Is your feature request related to a problem? Please describe.
It currently is only possible to detect single-touch events using the binary_sensor implementation. The front panel event system provides enough information to handle multi-touch events as well. It would be really nice to expose these.
The original firmware uses a multi-touch option too. Holding the power and color buttons for a while will reset the device. The original device being able to detect multi-touch events is another good reason to implement this ;-)
Describe the solution you'd like
Currently, the part
property can be used to define what part of the front panel to react to.
I propose adding a parts
property that does the same thing, but that accepts multiple part names.
This would look like:
binary_sensor:
- platform: xiaomi_bslamp2
parts:
- power button
- color_button
This is not really a bug but a question about syntax and doing the correct coding.
I am using this code snippet for my bedside lamp, which is working great. This code snippet can activate the night light by long pressing the power button:
[...]
then:
- light.turn_on:
id: my_light
brightness: 1%
red: 100%
green: 0%
blue: 0%
[...]
How can I use this to get a warm white version of the night light instead of a red one?
white:
luke: { color_temperature: 400 mireds }
The next release of ESPHome has a lot of modifications that break compilation for this component.
Some structural changes have to be done to make the component compatible with these modifications.
I'm already working on code that is compatible with the currenv ESPHome dev version, which will be the 2021.10.0 release at some point.
I currently make use of the RTC state store to restore state. This method works, but is not very clean code-wise, because I need to redefine a struct in my code for decoding the RTC data.
I ran into the LightCall::from_light_color_values()
method, which might make things a lot cleaner.
With the current_values
of the light output, I can store the active state.
With code like this, I can restore the state:
auto call = the_light.make_call();
call.from_light_color_values(id(global_var));
call.perform();
The ESP32-WROOM-32D that is in the lamp does support BLE.
It would be a cool feature to make that work for presence detection.
I already tried to implement this, but have failed so far.
One issue was that the platform package repo that we use did not yet contain the correct library files. That was fixed.
A bigger problem, unsolved as of yet, is that the ble_32_tracker
module makes the device very unstable. The device performs a lot of spontaneous reboots. The console logs show that this is because the device loop is taking up too much time (according to the WDT).
Possibly, this is an issue for this specific chip, given that this is a single core chip and not a dual core one.
Changes are likely to be done in the loop()
function of the ble_32_tracker
module.
So this time not a bug, also not really a feature request. Just a question if something is possible.
Would it be possible to light the power LED when an entity in HA has a certain state? Also would it be possible to long press the power button when it has this state to change an entity in HA?
I have a cool idea with the lamp, but not sure if it is possible to pull off.
Thanks!
Hi Guys,
Would it be possible to share a firmware.bin file already complied with default configuration?
I don't have esphome environment to do that. And I don't have linux machin to install.
Thanks in advance for your support
Hiya
After update to 2021.10.0 (and later) I'm getting error.
Obviously old config returned plenty of errors after update of ESPhome
So I have removed old code and copied new config from your Github and on the begining of compiling I'm getting below:
INFO Reading configuration /config/esphome/bedside-lamp.yaml...
INFO Updating https://github.com/mmakaay/esphome-xiaomi_bslamp2@dev
INFO Generating C++ source...
INFO Compiling app...
Processing bedside-lamp (board: esp32doit-devkit-v1; framework: espidf; platform: espressif32 @ 3.3.2)
Tool Manager: Installing platformio/toolchain-xtensa32 @ ~2.80400.0
Error: Could not find the package with 'platformio/toolchain-xtensa32 @ ~2.80400.0' requirements for your system 'linux_aarch64'
Is this something with ESPhome itself or can I correct it somehow?
I'm using "old" config file where I have just pasted new config.
Please advise.
Best regards.
Tried updating to latest release, but it fails
The core.yaml file is pointing to this url, which it cant resolve.
`
Failed config
external_components: [source /config/.esphome/packages/c1741637/packages/core.yaml:31]
[source /config/.esphome/packages/c1741637/packages/core.yaml:31]
unable to access 'https://mmakaay/esphome-xiaomi_bslamp2/': Could not resolve host: mmakaay.
source: [source /config/.esphome/packages/c1741637/packages/core.yaml:32]
type: git
url: https://mmakaay/esphome-xiaomi_bslamp2
ref: dev
refresh: 60s`
Describe the bug
When changing RGB color settings, while night light mode is active, transitions don't look good.
On many of the transitions, the light level shows a significant drop.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Either a smooth transition, or an instant transition when smooth transitioning is not possible at these light levels.
The ESPHome team is working on a great option to work with components that are hosted on GitHub.
This makes it very easy to use third party components, without all the hassle of downloading the code, and manually moving it to the correct directories on the build system. For example the Bedside Lamp 2 code could be included in the build by adding something like this to the yaml config:
external_components:
- source:
type: git
url: https://github.com/mmakaay/esphome-xiaomi_bslamp2
ref: 1.0.0-RC1
To make this work, the repository needs to be structured in a standard way.
Because of the big jump in usability, I will happily make my repo compatible with the requirements.
The change is not very complicated:
components/xiaomi_bslamp2
I will do this, before going to a first stable release of the code.
Update the flashing documentation to correctly desribe the flashing process when using esptool.py from the command line.
I currently have disco mode for the main LEDs and a separate front_panel.update_leds
call for the front panel LEDs, but possibly the use of component.update
is more standard? If it is, I will update the code to make use of it, instead of my own constructs.
Is your feature request related to a problem? Please describe.
I am a noob when it comes to ESPHome and everything related to it, but i really wanted to get my Bedside Lamp 2 out of the cloud and I found this project. After the Xiaomi fiasco with turning off LAN control for Yeelight lights this project was born and I am fallowing it from the time dev offered some firmware on Yeelight forums.
To cut it short it was very hard for me to find a starting config that can do everything the lamp does by default. Example config is only a starting blank template with some options. So basically i found a conf on the internet that failed badly and corrected that step by step with update to v2021.10 doc.
After a lot of trial and error and help from two guys in esphome discord (one of them being the dev itself that did this awesome project) I got it working.
The learning curve was steep.
Describe the solution you'd like
I believe for people convenience it would be best to have a recommended config with all the things that lamp can do explained, something that will be added upon when necessary (new releases)
It would be useful to know whether or not the night light mode is activated. While playing with the yaml configs, I found that I had to use this construction to detect night light mode (to turn off the front panel illumination when light mode was active):
light:
- platform: yeelight_bs2
on_brightness:
then:
- output.set_level:
level: !lambda if (x < 0.012f) return 0; else return x;
Having to use the magic number 0.012f
in there is not okay.
Hi Maurice,
first, thanks for your awesome work. Worked very good :)
I got a other Xiaomi device (from their subcompany smartmi) that is more horrible as the bedside lamp.
https://www.indiegogo.com/projects/smartmi-p1-purifier-cleaner-freshen-air-in-10-mins/
It has also an ESP32 so it should be possible to "free" it like you did i with the bedside lamp.
My problem is, i cant do it alone cause of missing knowledge.
I got all tools that are needed (flashers, cables, ttls and courage :) )
Are you willing to give me some support to this ? Project could be published over your github page. Not interested in earning praises for this one....just love to tinker with it ;)
Greets from Germany
Some terms have changed, while developing the code. Here are some proposals for final naming:
Device / lamp => lamp
light in the context of the lamp's main function => simply "light"
light in the context of the front panel => front panel illumination
the front panel slider illumination, used to represent the device brightness => level indicator
Button events like (double) touch / press / tap / click => tap / double tap
Color temperature-based light => white light (as one of the light modes: "rgb light", "white light" and "night light")
This is also required in preparation for consistent documentation.
If you find additional inconsistencies or have better suggestions, please let me know.
To make it possible to use configuration packages more easily, it would be good if the presets were moved to their own platform. Then the default light behavior could be combined with customized presets.
Now quite a bit already had to change for ESPHome 2021.10.0 in the config, I might as well try to do the separation before the release, so I won't have to bother the users multiple times with substantial config changes.
Hello I'm having problem with flashing bedside lamp -
I have copied config file - (i don't need to change anything) I have pasted it to esphome in HA. Later I managed to compile firmware (after error correction) - I have downloaded firmware and esphome-flasher - I connected adapter and im getting "Unexpected error: ESP Chip Auto-Detection failed: Failed to connect to Espressif device: Timed out waiting for packet header "
pins connection - rx-tx , tx-rx, gnd-gnd, gnd-gpio
its same story when i'm trying to update through server - (rasppi). i have tried different drivers and still nothing read that connecting gpio-gnd is not everything - you also need to press reset button? but where is reset button? my adapter doesn't have one - just holes with rts , cts.
I also tried different drivers but no sucess.
Plese advise.
Hi @mmakaay
Tanks for the incredible work you've done here!
One humble question. I use node-red to send mqtt command to my lamp. Is it possible to include the transition_length per request?
Example to set transition length to 4 seconds:
msg.payload = {"state":"ON","color": {"r": rgb.r, "g": rgb.g, "b": rgb.b}, "brightness": 255, "transition_length": 4000};
Thanks!
While I did find some race conditions in AsyncTCP and wrote a fix that worked wonders for the Bedside Lamp 2 and a few other devices, it looks like not all devices benefit from that change. Therefore it seems best to rollback those changes, and find a different solution for the disconnects.
In fact, I already looked into this and I was able to come up with a simpler, and as it seems; even more effective, fix.
Related documentation and a pull request for a new feature in ESPHome can be found at:
If this pull request gets merged, the fix for the client connection stability will be very easy.
In fact, the code that is required, is already in the repository.
See [this commit](7f718a6.
This ticket is mainly for tracking the upstream pull request.
Hi
I flashed your firmware on bedside lamp, but buttons and slider don't work. Is it okay for now?
When you are going to upgrade to the latest home-assistant, the Bedside Lamp 2 will not work correctly anymore. I just found out that the control panel becomes like this:
So no option to choose RGB or Color Temperature settings, only on/off and effect.
This is likely because of the improved color mode support in the latest versions, so I will work on getting that implemented correctly for the lamp firmware.
Is your feature request related to a problem? Please describe.
I can compile a firmware in which I've used preset.activate
with non-existing template group names or template names.
The firmware will complain at runtime about the errors via the logging. That is not optimal, since users will not continuously be watching the logs. When a user runs into a non-operational preset.activate
action, the verdict is likely that the code is broken.
Describe the solution you'd like
At compile time, check if the arguments for preset.activate
are valid. If not, provide a clear error message describing the issue.
Is your feature request related to a problem? Please describe.
Documentation is currently fragmented over source code, example.yaml, various forums and even a bit of Discord. There should be documentation in one place, so users of the code can find what they need to use the firmware.
Describe the solution you'd like
Write documentation using markdown files in te repository.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.