konsumer / tplink-lightbulb

Control TP-Link smart lightbulbs from nodejs
MIT License
191 stars 32 forks source link

Mode disco / slow fade ambiance #30

Closed AnthonyBSDE closed 5 years ago

AnthonyBSDE commented 5 years ago

Hello guys !

Thanks konsumer for your code, it's funny !

I make a simple disco mode with that :

const TPLSmartDevice = require("tplink-lightbulb");
new function () {
    var self = this;

    this.lamp = [ // list all of your lamp
        "192.168.1.5",
        "192.168.1.30"
    ];

    this.maxTimeFade = 100; // set to 10000 for slow mode.
    this.minTimeFade = 50; // set to 5000 for slow mode.

    this.init = function() {

        for(var i in this.lamp) {
            var light = new TPLSmartDevice(this.lamp[i]);
            this.setLightColor(light);          
        }   

    };

    this.setLightColor = function(light) {
        var randomHue = parseInt(Math.random() * 360),
            randomSaturation =parseInt(Math.random() * 100),
            randomBrightness = parseInt(Math.random() * 100),
            calcNextTimeFade = parseInt(Math.floor(Math.random() * this.maxTimeFade) + this.minTimeFade);

        console.log('Set light color : ', randomHue, randomSaturation, randomBrightness);
        light.power(true, calcNextTimeFade, {
            color_temp: 0, 
            mode: "normal",
            hue: randomHue,  // 0 to 360
            saturation: randomSaturation, // 0 to 100
            brightness: randomBrightness
        });

        setTimeout(function() {
            self.setLightColor(light);
        }, calcNextTimeFade + 50);
    };

}().init();

Sorry for my english, i'm french.

konsumer commented 5 years ago

Cool! I put it in the wiki.

Thanks!