Control Yeelight RGB and White in Homekit (suggestion)

Hi guys!
I wanted to share with you a workaround that I’ve been working on to control my Yeelight Bedside Lamp 2, both RGB colors and white temperature, on my Apple Devices using homekit.
Since the original entity will only let me control RGB colors and brightness on homekit entity, I created a “fake light” using light template that replicates the brightness and color temperature from the Bedside Lamp original entity.
Here’s the code I added on configuration.yaml:

light:
  - platform: template # white light fake entity
    lights:
      yeelight_bedside_white: # name of the fake entity to control white
        value_template: "{{ is_state('light.yeelight_bedside' , 'on') }}" #get status from original entity
        level_template: "{{ state_attr('light.yeelight_bedside', 'brightness')|int }}" #get status from original entity
        temperature_template: "{{ state_attr('light.yeelight_bedside', 'color_temp')|int }}" #get status from original entity
        turn_on:
          - service: light.turn_on
            data_template:
              entity_id: light.yeelight_bedside
              color_temp: 500 # every time I turn the Bedside Lamp using fake entity, it will turn on as 'warm white'
        turn_off: 
          - service: light.turn_off
            data_template:
              entity_id: light.yeelight_suite_bedside_ana
        set_level:
          - service: light.turn_on
            data_template:
              entity_id: light.yeelight_suite_bedside_ana
              brightness: "{{ brightness }}"
        set_temperature:
          - service: light.turn_on
            data_template:
              entity_id: light.yeelight_suite_bedside_ana
              color_temp: "{{ color_temp }}"

This way, I have “2 lights” on my homekit for the same device.

IMG_0161

I’m not sure if it applies to other Yeelight and Alexa or Google, since the only yeelight device I have is this Bedside Lamp 2 and I only use Siri on my iPhone for now.

Could you elaborate on how to define the colors you want to show? For example, I’d like to have only one option of white, yellow and maybe a few colours just to fill out the spaces. :smiley:

I’m supposing you want to change the preset color on your homekit, right?
You have to tap twice on the color you want to change and then edit the preset on your apple device.
Hope that answers your question!

Yes, of course. But my problem with that is, first that I’d need to do it manually for every light and the color wheel is not super precise, but most import I can’t get the right white I want, the completely white color I get with the Yeelight app (“brightness”: 255, “color_temp”: 153) :frowning:

Maybe you could try to set those parameters on the “turn_on” section…

(...)
turn_on:
  - service: light.turn_on
    data_template:
      entity_id: PUT YOUR LIGHT ENTITY HERE
      color_temp: 153
      brightness: 255
(...)

I don’t know if it will get you where you wanted, but maybe you’ll be one step closer…