Custom firmware ESPHome-Xiaomi_bslamp2

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

Version 2023.4.0 released

I just released version 2023.4.0 of the firmware component. The main reason being compile errors when using a recent version of ESPHome (either errors about a riscv32 toolchain package not being available, or errors about esp_mac.h missing).

If you have these compile errors, then the new release should fix them.

2 Likes

Good day anyone upgraded to esphome 2023.8.1? if yes any issues?
thank you

Yes I updated the lamp to ESPHome 2023.8.1 and it still works like a charme :slight_smile:

1 Like

@mmakaay thanks for this solution

i read somewhere there was a solution to have the power button lit when the lamp is off. i cant seem to find that code now.

All the LEDs in the front control panel can be controlled individually. I use that on my lamp in combination with a mwave presence sensor to turn on the power button LED when movement is detected. So doing something like always having that LED on is certainly possible.

I don’t have code ready to go for this, but I’ll take a look at what I can find or write for this.

I found the support issue that handled the power-led-always-on request. Maybe you saw that one?

I did yes.

What i would like when the lamp is off. i noticed with factory firmware that the power button wasnt illuminated. thought this wasnt great.

What you can try (I can’t test it myself right now), is to copy the code from this URL to your config in full:

https://raw.githubusercontent.com/mmakaay/esphome-xiaomi_bslamp2/dev/packages/behavior_default.yaml

In the packages: section, remove or comment out the reference to that config package: packages/behavior_default.yaml
If you wouldn’t comment this out, there would be duplicate definitions resulting in errors.

Now you have the default behavior configuration in your device config and can change the update_front_panel script. For example:

script:
  - id: update_front_panel
    mode: restart
    then:
      - front_panel.turn_off_leds: ALL
      - front_panel.turn_on_leds: [ POWER ]
      
      # In rgb or white light mode, turn on the front panel illumination,
      # and show the current brightness level.
      - if:
          condition:
            or:
              - text_sensor.state:
                  id: my_light_mode
                  state: rgb
              - text_sensor.state:
                  id: my_light_mode
                  state: white
          then:
            - front_panel.turn_on_leds: [ COLOR ]
            - front_panel.set_level: !lambda return id(current_brightness);
      - front_panel.update_leds:

So the script will always enable the power button, no matter the light mode or brightness.

It might just work :slight_smile:

1 Like

Thank you! I had esphome installed on my HA instance but i ran into compile issues for some reason. I compile via OSX now and upload the file via OTA.

esphome xiaomi-light2.yaml compile

esphome upload xiaomi-light2.yaml --device 192.168.88.16
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

# ------------------------------------------------------------------------
# Behavior: default
#
# * Presets that resemble the original Xiaomi firmware
#   (one group of RGB colors, one group of white light colors)
# * Tapping the power button, toggles the light
# * Holding the power button, turns on night light mode
# * Tapping the color button, activates the next preset
# * Holding the color button, activates the next preset group
# * Touching the slider sets the brightness level and turns on the lamp
# * When the light is on, the front panel illumination is on
# * When the night light is on, only the power button is illuminated
# ------------------------------------------------------------------------

# A global variable to keep track of the brightness level. This one is
# used by the update_front_panel script to represent the brightness level
# using the front panel illumination.
#
# This variable is used instead of querying the light component directly,
# because that brightness level may vary during a light transition. The
# behavior that I want: when you touch the front panel slider at 75%, then
# the illumination rises directly to that level, while the light might do
# a smooth transition.
globals:
  - id: current_brightness
    type: float
    initial_value: "0.0"

# This script updates the front panel illumination.
script:
  - id: update_front_panel
    mode: restart
    then:
      - front_panel.turn_off_leds: ALL
      - front_panel.turn_on_leds: [ POWER ]

      # In rgb or white light mode, turn on the front panel illumination,
      # and show the current brightness level.
      - if:
          condition:
            or:
              - text_sensor.state:
                  id: my_light_mode
                  state: rgb
              - text_sensor.state:
                  id: my_light_mode
                  state: white
          then:
            - front_panel.turn_on_leds: [ COLOR ]
            - front_panel.set_level: !lambda return id(current_brightness);
      # In night light mode, turn off the front panel illumination, except
      # for the power button.
      # - if:
      #     condition:
      #       - text_sensor.state:
      #           id: my_light_mode
      #           state: night
      #     then:
      #       - front_panel.turn_on_leds: [ POWER ]
      - front_panel.update_leds:

@mmakaay YAY! worked!

Thank you sir

Very nice :grin:, you’re most welcome.