Custom firmware ESPHome-Xiaomi_bslamp2

Yes, this firmware is only for the Bedside Lamp 2. The way in which the LEDs are controlled and the handling of the touch panel on the front are highly specific for this lamp.

Version 2021.9.0 released

At the time of writing, ESPHome 2021.9.0 is in beta (version 2021.9.0b1). While testing this beta, I found that a compilation error came up in ESPHome. This release fixes that error.

Warning: there were some changes done in ESPHome related to networking, that seem to cause some connection issues between ESPHome and Home Assistant. So I would not recommend upgrading ESPHome to the 2021.9.0b1 beta release for production devices.

This release can also be used with ESPHome 2021.8.0 and up.

To make use of this release, you can use the following in your YAML configuration:

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

Version 2021.9.1 released

Note: This release requires ESPHome 2021.8.0 and Home Assistant 2021.8.0 or newer.

Changed

  • Fixed a memory leak, causing the lamp to disconnect occasionally when doing a lot of
    color transformations (e.g. when running the Random light effect).

To make use of this release, you can use the following in your YAML configuration:

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

Good day, thank you again for producing and sharing this component.
I tried updating to your latest, but Im getting the following error:

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

your core.yaml file is pointing to this url, which it cant resolve.

thank you. this is now fixed.
But now i get the following error when I validate:

  Password support is not implemented yet for ESP-IDF.
  password: mypassword [source /config/bruno_lamp.yaml:61]

which refers to the ota password

I implemented this for esp-idf OTA, and this was included yesterday in ESPHome 2021.10.0b6. So if you upgrade to that beta version, then this error should be fixed.

1 Like

Thank you for your prompt reply.

I’ve proceeded as instructed and OTA worked perfectly.

1 Like

Support for ESPHome 2021.10.0 has been released

I did release a 2021.10.0b1 beta version of the lamp firmware. This version is compatible with the recent ESPHome 2021.10.0 version.

I wrote a guide on upgrading the existing configuration to a new one. Starting over is the easiest probably, but when you have a lot of customizations that you want to keep intact, then you could follow the steps from the guide to do the upgrade.

See: upgrading_to_2021.10.0.md on GitHub

When no issues come up, I will soon move the Bedside Lamp 2 project to its final 2021.10.0 release.

1 Like

Version 2021.10.0 released

Following the 2021.10.0b1 beta version, now the final stable release is done. There are no big changes between the beta and this stable release. There were mainly a few documentation improvemens.

The release details can be found on GitHub.

Hi,
I was about to update the version using brand new example.yaml as you suggested but failed. I don’t know why…
imagen

# --------------------------------------------------------------------------
# Substitutions
#
# These are substitutions as used by the configuration packages from below.
# You can uncomment and update the ones that you want to modify.
# --------------------------------------------------------------------------

substitutions:
  #name: bedside-lamp
  #friendly_name: Bedside Lamp
  #light_name: ${friendly_name} RGBWW Light
  #light_mode_text_sensor_name: ${friendly_name} Light Mode
  #default_transition_length: 800ms

# --------------------------------------------------------------------------
# Load configuration packages
#
# These provide a convenient way to compose your device configuration from
# some functional building blocks. Pick and mix the blocks that you need.
#
# For customization you can override options in your config or you can
# copy the contents of these packages directly in your config file as
# an example for your own customizations.
#
# Available packages are:
# - core.yaml                : core components & hardware setup
# - behavior_default.yaml    : default device behavior
# - ota_feedback.yaml        : enable visual feedback during OTA updates
# - activate_preset_svc.yaml : 'activate_preset' service for Home Assistant
# --------------------------------------------------------------------------

packages:
  bslamp2:
    url: https://github.com/mmakaay/esphome-xiaomi_bslamp2
    ref: release/2021.10.0
    files:
      - packages/core.yaml
      - packages/behavior_default.yaml
      - packages/ota_feedback.yaml
      - packages/activate_preset_svc.yaml
    refresh: 0s

# --------------------------------------------------------------------------
# Use your own preferences for these components.
# --------------------------------------------------------------------------

wifi:
  ssid: !secret ssid_wifi
  password: !secret pass_wifi

api:
  password: !secret api_xiaomi_bslamp2

ota:
  password: !secret pass_ota_xiaomi_bslamp2

The only change I did was to change “ref: dev” by “ref: release/2021.10.0” and obviously confirm secrets are ok.
Any idea why the update is failing?

BTW many many thanks on your amazing work done for this project!

You have to uncomment “name” and “friendly_name” in the substitutions block

@jsuanet is correct. This is an error that ESPHome currently raises when you have substitutions: in the configuration file, without any actual key/value pairs onder it.
I updated the example.yaml to not have every option commented out. That fixes things for now.

I will take a look at the ESPHome code for a real fix, because this crash is a bit of a bug. When I’ve got a fix for that in ESPHome, I will move my example.yaml back to having all options commented out again.

Thank you!
It worked :slight_smile:

Thanks for this project! I managed to flash the custom firmware without any issues.

However I want to use the lamp with an MQTT broker (outside of HA), does this still work?

I added an mqtt section in the yaml config and got this error with esphome compile:

Failed config

mqtt: [source example.yaml:58]
  
  This feature is only available with frameworks ['arduino'].
  broker: mqtt.home
json: None
  {}
async_tcp: None
  {}

Looks like mqtt has not yet been ported to esp-idf, the framework for which support was recently added to ESPHome.

This means that MQTT cannot be used for now.
I don’t know if somebody is already working on implementing the feature.

Looks like mqtt has not yet been ported to esp-idf, the framework for which support was recently added to ESPHome.

Ah thanks for the info! I just recompiled with the older 2021.9.1 firmware tag and I can now see MQTT messages.
Do you know the publish syntax to command the light (with a standard MQTT client, not HA) ?
I tried something like:

bedside-lamp/light/bedside_lamp_rgbww_light/command 
{"effect":"None","color_mode":"color_temp","state":"ON","brightness":17,"color":{},"color_temp":153}

But the light doesn’t seem to pick up this topic.

I admit I am a complete newbie with esphome/MQTT :slight_smile:

Update:
I just re-read the esphome MQTT doc and I’m not sure if I need to set up the commands myself in the yaml config? Something like this maybe:

mqtt:
  broker: 10.0.0.5
  on_json_message:
    topic: bedside-lamp/light/bedside_lamp_rgbww_light/command
    then:
      - ...some commands and logic here depending on json message...

Do you have a quick example for a single command?

Thanks!

I never used it myself, but I did test it once and then I grabbed the MQTT traffic in MQTT Explorer.
Started it up and found that it remembered the messages from the test :smiley:

What I see i those messages, is that you don’t write to /command, but to /state, so maybe give that a try? The rest of the message looks good to me.

What I see i those messages, is that you don’t write to /command, but to /state, so maybe give that a try? The rest of the message looks good to me.

Actually /command works fine :slight_smile: My first test wasn’t working because of a copy/paste error (brightness value out of range). The error message was actually reported in the queue but I missed it in MQTT explorer.

Thanks again for this cool hack!

Ah wonderful, good to know!
Enjoy the fun! :smiley:

Updated from 2021.8.1 (I believe) to 2021.10.0 a couple of weeks ago and have had the light lose wifi twice, about a week apart each time. The light itself still works fine but wifi is dead. Obviously also upgraded ESPHome at the same time, so it could be that. Never had this issue before, anyone else notice this?

Edit:
After the first time, upgraded to ESPHome to 2021.10.3.

Looks like it first happened about five days ago.

# --------------------------------------------------------------------------
# Substitutions
#
# These are substitutions as used by the configuration packages from below.
# You can uncomment and update the ones that you want to modify.
# --------------------------------------------------------------------------

substitutions:
  name: matts-bedside-lamp
  friendly_name: Matts Bedside Lamp
  light_name: ${friendly_name} RGBWW Light
  light_mode_text_sensor_name: ${friendly_name} Light Mode
  default_transition_length: 800ms

# --------------------------------------------------------------------------
# Load configuration packages
#
# These provide a convenient way to compose your device configuration from
# some functional building blocks. Pick and mix the blocks that you need.
#
# For customization you can override options in your config or you can
# copy the contents of these packages directly in your config file as
# an example for your own customizations.
#
# Available packages are:
# - core.yaml                : core components & hardware setup
# - behavior_default.yaml    : default device behavior
# - ota_feedback.yaml        : enable visual feedback during OTA updates
# - activate_preset_svc.yaml : 'activate_preset' service for Home Assistant
# --------------------------------------------------------------------------

packages:
  bslamp2:
    url: https://github.com/mmakaay/esphome-xiaomi_bslamp2
    ref: dev
    files:
      - packages/core.yaml
      - packages/behavior_default.yaml
      - packages/ota_feedback.yaml
      - packages/activate_preset_svc.yaml
    refresh: 0s

# --------------------------------------------------------------------------
# Use your own preferences for these components.
# --------------------------------------------------------------------------

wifi:
  ssid: "ubinot" # hidden SSID 
  password: !secret wifi_password
  fast_connect: true  # reqired for hidden SSID
  use_address: 192.168.6.60

  # Enable fallback hotspot (for captive portal) in case wifi connection fails
  ap:
    ssid: "ESPHome $friendly_name"
    password: !secret ap_password

mdns:
  disabled: true

api:
  password: !secret api_password

ota:
  password: !secret ota_password

time:
  - platform: homeassistant
    id: homeassistant_time
  
sensor:
  - platform: uptime
    name: "${friendly_name} Uptime Sensor"