Custom firmware ESPHome-Xiaomi_bslamp2

Hey, you would need to enter your new home network settings in the yaml file → build → flash again

Yes, @jonah1024 is right. New wifi settings would require a flash operation, since SSID+password are part of the compiled firmware.
When the new SSID+password are the same, then the lamp can be included in the new setup right away, since it should connect to the new network.

Thank you quick response both of you, much appreciated! I’ll flash them then early tomorrow morning.

Hello!
Tell me please!
I don’t use Home Assistant, but I use node-red and want to control my bslamp2.
If I install this firmware, I can connect the lamp to the node-red?
Thank you!

Hi there!

I’m not sure since I’m not using Node-red. You’re better off asking the Node-red community, or the author of this firmware @mmakaay. :blush:

One way would be to use MQTT, but I don’t have top of mind if ESP-IDF already provides MQTT functionality. If it does, then this would be a feasible route for integration (if you’re up for interpreting and constructing the MQTT messages).

Yes, I use zigbee2mqtt via Eclipse Mosquitto.
Probably could connect and WiFi device with mqtt…

Here is something about ESP-IDF and node-red:

Thanks for the great project Maurice Makaay. I have my lamp now working woth ESPHome GREAT!

Here my question:
I have the basic example.yaml working… but now I want to add more effect (or just make my own effects like a kind of wake up effect). How can I do that? I am new in esphome and I tried some code out but so far without success… :frowning:

Is there an easy way to add more effects or should I create them on nodered?

Thanks in advance for the help

In HA I just see 2 effects
effects

This is my actual code:

# --------------------------------------------------------------------------
# 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
  transition_length: 500ms

  #light_name: ${friendly_name} RGBWW Light
  #light_mode_text_sensor_name: ${friendly_name} Light Mode
  #default_transition_length: 800ms

  # 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
# --------------------------------------------------------------------------
# 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
     # - packages/light.yaml
    refresh: 0s


# 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
    
# --------------------------------------------------------------------------
# Use your own preferences for these components.
# --------------------------------------------------------------------------

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

api:
  password: apipassword
  
ota:
#  password: !secret ota_password

For effects, the lamp firmware supports everything that ESPHome supports.
So you can take a look at: Light Component — ESPHome

There is no standard wake-up light effect and writing an effect from scratch is not that easy I’m afraid. There is one special effect, the “Lambda Effect”, which lets you specify in YAML code what the effect should look like. That is the best option to implement wake-up as an effect IMO.

You can also make use of Node-Red or another external controller indeed. That’s how I did my first wake-up light. Currently I don’t have it, because I changed a lot in the meanwhile, but I’m planning to get a wake-up light back in my bedroom. I will definitely implement the logic for that in Home Assistant, which makes it more of a wake-up sequence. It will target not only the bedside lamp, but a few lamps in the bedroom.

Note that you can use transition times when changing from one color/brightness to the other, so that helps a lot with implementations like this one in my experience. It basically becomes a small list of light settings and wait timers to get something going.

Stable release for ESPHome 2022.12.0+

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

Fixes: failing device when upgrading to ESPHome 2022.12.0

ESPHome 2022.12.0 upgraded the ESP-IDF framework to 4.4.2. Changes were required to make the bslamp2 firmware compatible with this version. Without these changes, the upgrade could render the device non-functional (a.k.a. “bricked”).

This release of the firmware fixes this issue, by explicitly reverting the used framework version to 4.3.2 (i.e. the previous version that was working correctly). This is a stop gap work-around at best. I am working on fully supporting the new framework version in my next release.

You already flashed your lamp and it ended up bricked? Then no worries!

Unfortunately, simply flashing the device with never firmware over a serial connection does not bring it back into working state. Things can be fixed though with a little flashing dance. Check out the instructions from the related GitHub issue report:
Fix recipe from issue #104

How to upgrade your device

The basic steps for upgrading are:

  1. Upgrade ESPHome to 2022.12.0 or later;
  2. Update your device configuration (see below);
  3. Compile and upload the new firmware.

If you have used the example.yaml to create your configuration, then update the configuration package ref: to point to release/2022.12.0.

packages:
  bslamp2:
    url: https://github.com/mmakaay/esphome-xiaomi_bslamp2
    ref: release/2022.12.0 <--- update this one
    files:
      ...
      ...

If you use a different configuration method, then make sure that the external_component: and esp32: sections match the ones from the example.yaml for this release.

1 Like

Hi!,

It is been super great to have this custom firmware for so long without no major issues. Thank you @mmakaay for making it possible.
I have a silly question. Would like to add code for uptime in the bedside lamp as I have for other esp8266 and esp32 chips.

# Uptime ESP Human Readable 
text_sensor:
  - platform: template
    name: Uptime bedside-lamp
    id: uptime_human
    icon: mdi:clock-start

sensor:
  - platform: uptime
    name: Uptime Sensor
    id: uptime_sensor
    update_interval: 60s
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (days ? String(days) + "d " : "") +
                (hours ? String(hours) + "h " : "") +
                (minutes ? String(minutes) + "m " : "") +
                (String(seconds) + "s")
              ).c_str();  

imagen

But it throws me an error with String not declared so unable to compile. I guess I have to initialize or let them know which board is using but your code does not contain it at the very begining.
Could you guide me on how to implement this check?

Thank you,

String() is not available, but you can make use of the to_string(...) function instead.
For example to_string(days)

1 Like

Thank you @mmakaay. As usual, your replies just make it work! :grinning:

1 Like

Good day. Has anyone already upgraded to latest esphome (12.8) i believe?
If yes any issues?
Thank you

Yes I did. Use of the API password is depreciated, this shows up as a warning in LOGS.
But, instructions are provided, easy to follow and implement :slight_smile:

can you provide a link to the instructions?

This is the link that is provided in de logging: Native API Component — ESPHome

Some more info here: ESPHome encryption key is invalid
Or here: API Encryption - where to update in Home Assistant?

Thank you very much
To confirm you replaced password for encryption key?

Yes, I’ve removed the api-password and added the encryption-key.

@mmakaay Thanks for this great work. Now I can control my lamp via iobroker.
I’m still trying to find all the right values in iobroker. For example the values of the color_temperature are really strange.
name ** mireds ** Iobroker value
cold ** 153 ** 39015
chilly ** 275 ** 70125
luke ** 400 ** 102000
warm ** 588 ** 149940
Maybe you or some others can help me to understand this conversion.
Thanks Doug