Help with yeelight lamp

I installed a yeelight lamp in the bedroom. ( Yeelight YLXD01YL)

min_mireds: 153
max_mireds: 370
effect_list:
  - Slow Temp
  - Stop
brightness: 13
color_temp: 301
flowing: false
night_light: true
friendly_name: Bedroom Ceiling Light
supported_features: 47

The light will be usually turned off. When someone turns it on I would like to have different brightness depending on the time.
So I am trying the following automation.

# Bedroom Ceiling Light *********************************************************
- id: Bedroom Ceiling Light
  alias: Bedroom Ceiling Light
  trigger:
      - platform: state
        entity_id: light.bedroom_ceiling_light
        from: 'off'
        to: 'on'
  action:
      - choose:
          - conditions:
              - condition: time
                after: '23:00:00'
                before: '06:00:00'
            sequence:
              - service: light.turn_on
                entity_id: light.77626641ecfabc976395
                brightness: 10
                color_temp: 318
                night_light: true
      - service: light.turn_on
        entity_id: light.77626641ecfabc976395
        brightness: 166
        color_temp: 318

But I get in the Configuration validation

Invalid config for [automation]: [brightness] is an invalid option for [automation]. Check: automation->action->0->choose->0->sequence->0->brightness. (See /config/configuration.yaml, line 21). 

what am I doing wrong?

That’s because the additional parameters for the service call need to be in the data block. Take a look at the Actions page of the automation documentation here, especially the examples.

So for example this:

- service: light.turn_on
    entity_id: light.77626641ecfabc976395
    brightness: 10
    color_temp: 318
    night_light: true

Becomes this:

- service: light.turn_on
  entity_id: light.77626641ecfabc976395
  data:
    brightness: 10
    color_temp: 318
    night_light: true

I don’t know if you can set the night_light parameter like this, don’t own any yeelights.

You should also check the syntax for the choose action here as currently your automation is :
IF time after 23:00 and before 06:00 -> turn light on at low brightness, then turn on the light at high brightness.

But I assume you want
IF time after 23:00 and before 06:00 -> turn light on at low brightness
ELSE turn on light at hight brightness.

To get the ELSE part, you need to define a default action. Something like this (you may need to check indentation, can’t test right now):


  action:
    - choose:
      - conditions:
         - condition: time
           after: '23:00:00'
           before: '06:00:00'
        sequence:
          - service: light.turn_on
            entity_id: light.77626641ecfabc976395
            data:
              brightness: 10
              color_temp: 318
              night_light: true
      default:
        - service: light.turn_on
          entity_id: light.77626641ecfabc976395
          data:
            brightness: 166
            color_temp: 318

I have made several tries still get nothing.
now my code is the following but it is not working…

# Bedroom Ceiling Light *********************************************************
- id: Bedroom Ceiling Light
  alias: Bedroom Ceiling Light
  trigger:
      - platform: state
        entity_id: light.bedroom_ceiling_light
        to: 'on'
  action:
      - choose:
          - conditions:
              - condition: time
                after: '23:00:00'
                before: '06:00:00'
            sequence:
              - service: yeelight.set_mode
                entity_id: light.bedroom_ceiling_light
                mode: 'moonlight'

        default:
      - service: light.turn_on
        data:
          entity_id: light.bedroom_ceiling_light
          brightness: 300
          color_temp: 318

In your sequence to set the light to “moonlight” you need to put mode: 'moonlight' in a data block as well. And the default service needs to be indented more. Try like this:

# Bedroom Ceiling Light *********************************************************
- id: Bedroom Ceiling Light
  alias: Bedroom Ceiling Light
  trigger:
      - platform: state
        entity_id: light.bedroom_ceiling_light
        to: 'on'
  action:
    - choose:
        - conditions:
            - condition: time
              after: '23:00:00'
              before: '06:00:00'
          sequence:
            - service: yeelight.set_mode
              entity_id: light.bedroom_ceiling_light
              data:
                mode: 'moonlight'
      default:
        - service: light.turn_on
          entity_id: light.bedroom_ceiling_light
          data:  
            brightness: 300
            color_temp: 318

i broke the code
this works

# Bedroom Ceiling Light *********************************************************
- id: Bedroom Ceiling Light
  alias: Bedroom Ceiling Light
  trigger:
      - platform: state
        entity_id: light.bedroom_ceiling_light
        to: 'on'
  action:
    - service: light.turn_on
      data:
          entity_id: light.bedroom_ceiling_light
          brightness: 300
          color_temp: 318

this doesn’t

# Bedroom Ceiling Light *********************************************************
- id: Bedroom Ceiling Light
  alias: Bedroom Ceiling Light
  trigger:
      - platform: state
        entity_id: light.bedroom_ceiling_light
        to: 'on'
  action:
    - service: yeelight.set_mode
      entity_id: light.bedroom_ceiling_light
      data:
        mode: 'moonlight'

Does it work through Developer Tools -> Services?
Might be that the entity_id must also be in the data block, but I think it shouldn’t matter, but it’s worth a try.

It doesn’t work as expected BUT
the yeelight integration has 2 entities
1 for the light that I am using
and the binary_sensor.bedroom_ceiling_light_nightlight
The lamp has also a remote control (which I use lately for the moonlight option)
I was playing with it and when the moonlight light was on the above binary sensor turned on.
But I am not sure how I can handle it through HA.
yeelight

Do you mean the automation or under Developer Tools → Services?

The binary sensor just shows if the nightlight is activated or not, it’s read only, so you can’t change it directly.

Yes. if I ask for moonlight id does reduce the light but not as low as the original moonlight. Even when I set brightness to 1 it is much brighter than moonlight option.

I guess that I could not do anything else then.

after test and trial the moonlight is working!
… with the following logic

# Bedroom Ceiling Light *********************************************************
- id: Bedroom Ceiling Light moon
  alias: Bedroom Ceiling Light moon
  trigger:
      - platform: state
        entity_id: light.bedroom_ceiling_light
        to: 'on'
  action:
    - service: yeelight.set_mode
      entity_id: light.bedroom_ceiling_light
      data:
        mode: moonlight
    - service: light.turn_on
      entity_id: light.bedroom_ceiling_light
      data:
        brightness: 3

Now I have to put together the code depending on time

1 Like

Ok great, that means that the remote probably also sends 2 commands, one to turn the light to moonlight and a second to decrease the brightness, as you did in your automation.

Give it a try with the time based automations and come back with your code if you don’t succeed. Just as a tip, sometimes it’s easier to create 2 separate automations to handle different scenarios.

usually I do create 2 automations but for this one I couldn’t find it’s logic.
Now I am rethinking about it could I just ask the automation to turn on the moonlight mode after 23:00 until 06:00 otherwise to keep the original light.

I noticed something that obviously has to do with the particular lamp (and one more yeelight I have)
Since those lamps are switched off HA keeps looking (until the are on again) for them. This wouldn’t happen until the mew integration (before 0.115 version)
Now I have the following in my config

Logger: homeassistant.config_entries
Source: config_entries.py:239
First occurred: 7:33:08 PM (111 occurrences)
Last logged: 8:18:15 PM

Config entry for yeelight not ready yet. Retrying in 5 seconds
Config entry for yeelight not ready yet. Retrying in 10 seconds
Config entry for yeelight not ready yet. Retrying in 20 seconds
Config entry for yeelight not ready yet. Retrying in 40 seconds
Config entry for yeelight not ready yet. Retrying in 80 seconds

Do you know if there is a way to bypass this?

No, sorry.

1 Like