cap:colorable - coloring of lights

Capability used for lights that can be colored.

if(thing.matches('type:light', 'cap:colorable')) {
        console.log('Current color', await thing.color());

        // Set the color
        await thing.color('red');


color([color[, duration]])

Get the current color or change the color of the light.

  • color – Optional color to set. The color can be specified in many formats, hex values such as #00ff00, color names such as red and blue, and color temperatures such as 4000K or overcast.
  • duration (Duration) – Optional duration to perform change in brightness over. Supported when the light has the fading-capability.

Promise that resolves to the current or set color.


// Get the current color
const currentColor = await thing.color();

// Change color
const newColor = await thing.color('4000K');

// Change color over 2 seconds
await thing.color('#00ffff', '2s');



Color has changed. Payload will be the new color.

thing.on('colorChanged', color => console.log('Color is now', color));

Protected methods


Update the current color of the light. Should be called whenever a change in color occurs for the light. If the color set has changed this will emit the color event.

  • color – The color of the light.

const { color } = require('abstract-things/values');
this.updateColor(color.rgb(255, 0, 170));
changeColor(color, options)

Abstract. Change the color of the light. Implementation should support the following:

  • color should be converted to something supported by the light.
  • options.duration should be respected if the light supports fading.
  • color – The new color of the light. The colorspace of the light can be be anything, but is most commonly temperatures or rgb-values.
  • options – Options for changing the color. The only option available is duration which indicates amount of time the change should occur over.

Promise if change is asynchronous.

Implementing capability

Implementations should call updateColor whenever the color of the light changes. changeColor needs to be implemented and will be called whenever a color change is requested. color:temperature and color:full should be implemented to indicate the type of color supported.

const { Light, Colorable, ColorFull } = require('abstract-things/lights');
const { color } = require('abstract-things/values');

class Example extends Light.with(Colorable, ColorFull) {

        initCallback() {
                return super.initCallback()
                        .then(() => this.updateColor(color.rgb(0, 0, 0));

        changeColor(color, options) {
                // Convert color to RGB colorspace
                const rgb = color.rgb;

                return setColorSomehow(rgb, options.duration);