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.
Important notes
- 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. If you have a different model you may need to apply some changes to match the logic of your model.
- It seems that the ambient color mode right now cannot be used to acutally toggle 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. To fix this I added some simple rules that reapply the current color or temperature setting whenever the color mode is changed. In addition to that you need to change the profile of the color mode link to “follow”.
These however are binding issues and don’t seem to be related to the widget itself.
Howto
- 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.
- Create a string item that will represent the ambient color as RGB value (required to show the ambient color light in the widget)
- 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.
- 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.
- 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. I recommend to disable this behaviour and use openHAB rules if you want to couple the lights together. I use a rule to toggle the ambient ON together with the main lamp but I don’t want it to be toggled OFF.
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.7
- fixed: when ambient light is in CCT mode the widget shows white light on top of the lamp
Version 0.6
- initial release