Widget for yeelight pendant lamps

yeelight_widget

This is a rather specific widget for yeelight lamps with an additional ambient light on the top. Since these lamps offer a huge variety of controls it was pretty challenging to combine all those into one tiny widget and there exist still some issues (see section below). I hope there are other users out there who can help out to fix these remaining issues.

Known Issues

  • My Yeelight model is a yeelink.light.ceiling10. Despite the miio binding documentation claims that the ambient color mode maps like this: “1”=“CT mode”,“2”=“RGB mode” it seems that actually RGB mode is mapped to 1 and CT mode is mapped to 2. The widget currently implements these “inverted” mode mappings.
  • It seems that the ambient color mode right now cannot be used to acutally control the color mode. The light does not change and the widget will toggle back to the previous color mode unless you quickly use the temperature or color wheel controls.
  • If the ambient light is set to CCT mode the colour will still be shown in the widget

Maybe someone can validate these issues, this may be a binding issue.

Howto

  1. Download via marketplace or paste widet code in dev tools (see Ressources section below). Please note that the Footer text is hard coded (“Licht an” → On, “Licht aus” → Off) so please adapt to your localization. I might add some localization properties in future versions to make updates easier for you.
  2. Create a string item that will represent the ambient color as RGB value (required to show the ambient color light in the widget)
  3. Create a rule that is triggered when the ambient color item is changed and create an ECMA Code action and paste the code from section Code for the RGB Rule below. Make sure to change the name of the item in the code to match the name of the item created in step 2.
  4. Add widget to a page and configure the items. I think this is pretty straight forward when you have all the relevant channels mapped to items (Ambient Color RGB should point to the item created in step 2.). Please note that the shutdown timer is not supported by the lamp itself and thus needs to be created manually via a rule. You may use the rule posted below in section Shutdown Timer Rule, trigger this rule on every change of the timer item (dining_lamp_timer in the example code). It is not super sophisticated, please adapt to your needs.
  5. Note that by default for the yellight pendant lamps the ambient light will be switched on and off together with the main toggle. This behaviour can be changed in the official yeelight app.

Feel free to post any questions on how to use but please see the Known Issues before that!

Code for the RGB Rule

var color = new HSBType(new DecimalType(Math.round(newState.hue)), new PercentType(100), new PercentType(100))
var rgbString = Math.round(color.red * 2,55) + "," + Math.round(color.green * 2,55) + "," + Math.round(color.blue * 2,55);
events.postUpdate("dining_lamp_ambient_color_rgb", rgbString);

Shutdown Timer Rule

var ScriptExecution = (this.ScriptExecution === undefined) ? Java.type("org.openhab.core.model.script.actions.ScriptExecution") : this.ScriptExecution;
var ZonedDateTime = (this.ZonedDateTime === undefined) ? Java.type("java.time.ZonedDateTime") : this.ZonedDateTime;

if (this.decreaseOneMinute != undefined) {
  this.decreaseOneMinute.cancel();
  this.decreaseOneMinute = undefined;
}

if (newState == 0) {
  events.sendCommand('dining_lamp_ambient', OFF);
  events.sendCommand('dining_lamp_main', OFF);
} else if (newState > 0) {
  var currentTime = ZonedDateTime.now();
  var targetTime = currentTime.plusMinutes(1);
  this.decreaseOneMinute = ScriptExecution.createTimerWithArgument(targetTime, newState, function(minutes) {
    events.postUpdate('dining_lamp_timer', minutes - 1);
  });
}

Changelog

Version 0.6

  • initial release

Resources

https://gist.githubusercontent.com/DrRSatzteil/52a6feff119f2daf3f4726ab93e1166a/raw/a651b68f99dc8aabd63f38ff060bacf6752a3821/yeelight_pendant_v6.yaml

2 Likes

Hi @marcel_verpaalen

could you please have a look at the known issues section above? I just checked the sources and I see the following in the yeelink.light.ceiling4.json file:

                        {
							"value": "2",
							"label": "CT mode"
						},
						{
							"value": "1",
							"label": "RGB mode"
						},

To be honest I don’t know the binding code well enough to know exactly what this file does but shouldn’t CT mode be set to 1 and RGB to 2? This is the way other lamps behave and what the binding documentation says as well.

Also Ambient Color Mode is configured like this:

			{
				"property": "bg_lmode",
				"friendlyName": "Ambient Color Mode",
				"channel": "ambientColorMode",
				"channelType": "ambientColorMode",
				"type": "Number",
				"refresh": true,
				"actions": []
			},

Shouldn’t there be any actions? In fact the color mode channel of the downlight has some actions but it does not support color light at all. Only the ambient lighting supports CT and RGB modes.

Again I don’t know exactly how the binding works but this seems to match my observations as described in the “Known Issues”. Thanks for your help!

I’ll double check.
I vaguely remember similar issue on other yeelights. Could also be the discrepancy/strangeness between the yeelight spec and the reality.

but also

Oh I see there’s room for interpretation in the specs :sweat_smile:

Please let me know if I can assist you in any way! Thanks!