Controlling Bluetooth Lights with Puck.js

This video shows you how to control most types of Bluetooth lightbulb using Puck.js.

The actual code used is:

function setLight(isOn) {
  var gatt;
  NRF.connect("98:7b:f3:61:1c:22").then(function(g) {
    //         ^^^^^^^^^^^^^^^^^  your light's address here
    gatt = g;
    return gatt.getPrimaryService("33160fb9-5b27-4e70-b0f8-ff411e3ae078");
  }).then(function(service) {
    return service.getCharacteristic("217887f8-0af2-4002-9c05-24c9ecf71600");
  }).then(function(characteristic) {
    return characteristic.writeValue(isOn ? 1 : 0);
  }).then(function() {
    gatt.disconnect();
    console.log("Done!");
  });
}

var on = false;
setWatch(function() {
  on = !on;
  setLight(on);
}, BTN, { repeat:true, edge:"rising", debounce:50 });

But you'll have to change the address to that of your lightbulb!

This code will work with Awox Smartlight C9 and W13 bulbs. For other bulbs you may need to use the steps shown in the video to work out which characteristics were used.

Extras

For the Awox Smartlight W13 you can also change:

  • Brightness by writing a value from 0 to 127 to characteristic d8da934c-3d8f-4bdf-9230-f61295b69570 on service fff6fe25-469d-42bc-9179-b3a093f19032
  • Colour temperature by writing a value from 0 to 127 to characteristic 5b430c99-cb06-4c66-be2c-b538acfd1961 on service fff6fe25-469d-42bc-9179-b3a093f19032

Buying

You can buy the lights I used here from eBay:

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.