Zigbee2MQTT - control Yeelight 650 Celling Light with Xiaomi wireless button

Tags: #<Tag:0x00007f326d4096a0> #<Tag:0x00007f326d4095d8> #<Tag:0x00007f326d4094e8> #<Tag:0x00007f326d409420> #<Tag:0x00007f326d409330>

Introduction

I have a Yeelight 650 celling light in my bedroom. To control it I use two Xiaomi wireless buttons, one for me and another for my wife. After a while I found out that I mainly really use only a few functions of my Yeelight 650:

  • Toggle light (turn it on or off) - this is most often scenario
  • Change mode (main light or night light). Most of the time I use it in nightlight mode, but sometimes I need bright light, so I switch it to daylight mode for some time and then back.
  • I want ambilight (color) to turn on or off together with main light.
  • I also have RGB Led strip that I want to turn on/off.

Before switching to this blueprint I had:

  • Two different automations to control ambilight together with main or night light
  • Five different automations for toggle the light, change mode or toggle RBG LED strip.
  • Five almost the same automations for second Xiaomi button.

After switching to this blueprint I have the blueprint itself and only two automations that use it (one per button). My configuration became much simpler and shorter. Number of automations reduced by 10 while having the same functionality.

Why don’t use others blueprints? Yes, sure, there are many other similar (and in many cases more universal) blueprints already posted here. But none of them let me do what I want with simplest code possible.

Tested devices

This blueprint was tested with:
  • Yeelight 650 Galaxy Ceiling light with ambilight (model YLXD02YL)

  • Xiaomi Wireless Button WXKG01LM running with over Zigbee2MQTT

Import blueprint from here

Documentation

Required inputs

There are four required inputs:

trigger_entity

trigger_entity is the Xiaomi button sensor entity. When integrated with Zigbee2MQTT it can be in one of the following states:

  • single on single click
  • double on double click
  • hold on hold

mainlight_entity

mainlight_entity is Yeelight main (day) light entity. Will be toggled with single click if mode_entity is false. Double click will toggle Yeelight between mainlight_entity and nightlight_entity

nightlight_entity

nightlight_entity is Yeelight night light entity. Will be toggled with single click if mode_entity is true. Double click will toggle Yeelight between mainlight_entity and nightlight_entity

mode_entity

mode_entity - Yeelight nightlight boolean sensor entity holding current mode (day/night mode)

Optional inputs

Ambilight entity

Ambilight entity can be used for controlling ambilight (toggle it on/of at the same time with main/night light).

hold_action

Use `hold_action` to specify action when button is being hold for few seconds. In my case I trigger LED RGB stip using the following code:
hold_action:
  service: script.led_strip_toggle

Enabling entity

Use Enabling entity to make the automation to trigger based on entity’s state (see below)

Enabling entity state

The automation will trigger only if Enabling entity is present and it is in specified state.

Example automation

The automation below will publish MQTT message for all motion sensor detected motions

    - id: "control_light_button"
      alias: "Control Yeelight 650 ceiling light with Xiaomi button"
      description: "Control Yeelight 650 by Xiaomi button"
      use_blueprint:
        path: yuri-vashchenko/button_light_control.yaml
        input:
          trigger_entity: sensor.button_action
          mainlight_entity: light.yeelight_650
          nightlight_entity: light.yeelight_650_nightlight
          mode_entity: binary_sensor.yeelight_650_nightlight
          ambilight_entity: light.yeelight_650_ambilight
          enabling_entity: switch.control_mode
          hold_action:
            service: script.led_strip_toggle```