[SOLVED] Yeelight Ceiling light modes/rules with miio

Hi All,

I have 3 yeelight ceiling. Now with miio, I can turn it on/off and birghtness, but I cant edit the “mode”
(active_mode 0: daylight mode / 1: moonlight mode (ceiling light only))
For example, when you use the official app, you can use the “moon” mode. (Very very low light, with the brightness slider, I cant set it…)
Anybody tried to reproduce it with openHAB?

You can try the following by sending to the command channel. (Advanced, hence you need to use show more to see it)

set_scene ["nightlight", 10]

… I use the custom scene channel for that…
Switching between moon and normal is a bit tricky though, also controlling the brigthness in moon mode.
moon mode brigthness is reported by the lamp on “nl_br” which is the channel nightlight_brigthness.
but by sending a command to nl_br the lamp does not do anything.
Also strangely, I have to send nightlight",100 (only one quote) to the custom scene channel to get the lamp to do it.

So this is what I came up with:
items:

Number   Ankleide_Yeelight_Brightness         "Brightness"      (Ankleide_Yeelight)   {channel="miio:generic:xxx:brightness"}
Number   Ankleide_Yeelight_ColorTemperature   "Color Temperature"(Ankleide_Yeelight)   {channel="miio:generic:xxx:colorTemperature"}
String   Ankleide_Yeelight_CustomScene            "Set Scene"             (Ankleide_Yeelight)  {channel="miio:generic:xxx:customScene"}
Number   Ankleide_Yeelight_NightlightBrightness   "Nightlight Brightness" (Ankleide_Yeelight)  {channel="miio:generic:xxx:nightlightBrightness"}
Switch   Ankleide_Yeelight_SwitchMoon              "Switch Moon mode"           (Ankleide_Yeelight)

rules:

rule "Toggle Moon mode"
when
  Item Ankleide_Yeelight_SwitchMoon received command
then
  if (Ankleide_Yeelight_SwitchMoon.state == OFF) {
    Ankleide_Yeelight_ColorTemperature.sendCommand(2700)
    // Give 30% brightness by default
    Ankleide_Yeelight_Brightness.sendCommand(30)
  } else {
    Ankleide_Yeelight_CustomScene.sendCommand("nightlight\",100")
  }
end

rule "Nightlight Brightness"
when
  Item Ankleide_Yeelight_NightlightBrightness received command
then
  if (Ankleide_Yeelight_SwitchMoon.state == ON) {
    var cmnd = receivedCommand
    if (cmnd < 1) {
      cmnd = 1
    }
    Ankleide_Yeelight_CustomScene.sendCommand("nightlight\"," + cmnd)
  }
end

rule "Nightlight Brightness Update Moonlight Switch"
when
  Item Ankleide_Yeelight_NightlightBrightness changed
then
  if (Ankleide_Yeelight_NightlightBrightness.state == 0) {
    Ankleide_Yeelight_SwitchMoon.postUpdate(OFF)
  } else {
    Ankleide_Yeelight_SwitchMoon.postUpdate(ON)
  }
end

Perhaps anybody has a nicer solution but for now it works fine for me.
I can enter/exit moon mode with the switch. Then I have two sliders, one for brightness when moon mode is off, one for brightness when moon mode is on. Also important to know is than either of the brightness channels does not accept a value of 0, so I account for that to be able to conveniently slide all the way down to get the lowest brightness.

Thanks a lot, It works.
For everybody else :), the method:
item_ActionsCommands.sendCommand(‘set_scene [“nightlight”, 10]’)

For me, first wasnt clear

BR,
O.

Can confirm, this works as described. Thank your for sharing!

As a beginner (it´s my first day) with multiple Yeelights, i am wondering why this switch toggles the nightmode on all my lights at once.

I copied the rules and the items, both lights (more to be connected) have their own channels and item names (YeelightLivingroom_SwitchMoon / YeelightEntrance_SwitchMoon), so my understanding is that each switch should only toggle the corresponding light - not every yeelight.

The rules have different names, but are in the same file. Some help and / or insights would be appreciated!

UPDATE:
I messed up the Naming of Items, there is a difference between Yeelight_Livingroom_Power and YeelightLivingroom_Power.

Hello,@dimlao.

Your “Ankleide_Yeelight_CustomScene.sendCommand(“nightlight”,100”)" is actually part of the following command:

"set_scene [\"nightlight\",100]"

send to command channel.

Here’s another example:
Items:

Switch Some_Switch "Some Switch"
String MyCeiling_Scene "My Ceiling Scene" {channel="miio:generic:07XXX1B:customScene"}
String MyCeiling_Command "My Ceiling Command" {channel="miio:generic:07XXX1B:command"}

Rules:

rule "test 1"
when
         Some_Switch received command
then
         if (Some_Switch.state == ON) {
                  MyCeiling_Scene.sendCommand("nightlight\",100")
         } else {
                  MyCeiling_Scene.sendCommand("ct\",5400,100")
         }
end

You can do exactly the same using the command channel:
Rules:

rule "test 2"
when
         Some_Switch received command
then
         if (Some_Switch.state == ON) {
                  MyCeiling_Command.sendCommand("set_scene [\"nightlight\",100]")
         } else {
                  MyCeiling_Command.sendCommand("set_scene [\"ct\",5400,100]")
         }
end

The “miio:generic:07XXX1B:command” channel is not detected automaticly by Mi IO, so you have to add it manually, similarly to the scene channel.
The “5400” value is a color temperature for the ct scene. “100” is brightness in %.
Obviously you have much more options to controll your lamp via command channel, according to the Yellight Inter Operation Spec.

You can learn current states of your lamp by doing:

MyCeiling_Command.sendCommand("get_prop [\"power\",\"bright\",\"ct\",\"rgb\",\"color_mode\",\"active_mode\"]")

and then checking the log files.

You can find more clues how to figure it out on the other yeelight thread.

1 Like

May be this will be usefull. There is another way to turn on night light mode:

sendCommand(“set_power [“on”,“smooth”,500,5]”) on channel miio:generic::actions#commands

The point is in fourth parameter. It means “mode”. That’s what described in Yeelight WiFi Light Inter-Operation Specification

Method: set_power
Usage: This method is used to switch on or off the smart LED (software
managed on/off).
Parameters: 3
“power” can only be “on” or “off”
“effect”: Refer to “set_ct_abx” method.
“duration”: Refer to “set_ct_abx” method.
“mode” (optional):
0: Normal turn on operation (default value)
1: Turn on and switch to CT mode.
2: Turn on and switch to RGB mode.
3: Turn on and switch to HSV mode.
4: Turn on and switch to color flow mode.
5: Turn on and switch to Night light mode. (Ceiling light only).

1 Like