Skip to content
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 38 additions & 88 deletions MiLight.html
Original file line number Diff line number Diff line change
@@ -1,120 +1,70 @@
<script type="text/javascript">
RED.nodes.registerType('MiLightRGB',{
category: 'output',
color: '#a6bbcf',
RED.nodes.registerType('MiLight',{
category: 'lights',
color: '#FF6600',
defaults: {
name: {value:"MiLight RGB"},
name: {value:"MiLight"},
bulbtype: {value:"white"},
zone: {value:1,oneditsave:function(){this.zone=parseInt(this.zone)}},
ip: {value:"255.255.255.255"},
broadcast: {value:true}
},
inputs:1,
outputs:0,
icon: "file.png",
icon: "light.png",
label: function() {
return this.name||"MiLight RGB";
}
});
RED.nodes.registerType('MiLightWhite',{
category: 'output',
color: '#a6bbcf',
defaults: {
name: {value:"MiLight White"},
zone: {value:1,oneditsave:function(){this.zone=parseInt(this.zone)}},
ip: {value:"255.255.255.255"},
broadcast: {value:true}

},
inputs:1,
outputs:0,
icon: "file.png",
label: function() {
return this.name||"MiLight White";
}
});
RED.nodes.registerType('MiLightPower',{
category: 'output',
color: '#a6bbcf',
defaults: {
name: {value:"MiLight Power"},
zone: {value:1,oneditsave:function(){this.zone=parseInt(this.zone)}},
ip: {value:"255.255.255.255"},
broadcast: {value:true}

},
inputs:1,
outputs:0,
icon: "file.png",
label: function() {
return this.name||"MiLight Power";
return this.name||"MiLight";
}
});
</script>

<script type="text/x-red" data-template-name="MiLightRGB">
<script type="text/x-red" data-template-name="MiLight">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-zone"><i class="icon-tag"></i>Default Zone</label>
<input type="text" id="node-input-zone" placeholder="1">
</div>
<div class="form-row">
<label for="node-input-ip"><i class="icon-tag"></i>IP Address</label>
<input type="text" id="node-input-ip" placeholder="255.255.255.255">
</div>
<div class="form-row">
<label for="node-input-broadcast"><i class="icon-tag"></i>Broadcast</label>
<input type="checkbox" id="node-input-broadcast" placeholder="false">
<label for="node-input-bulbtype"> Bulb Type</label>
<select id="node-input-bulbtype">
<option value="white" selected="selected">White</option>
<option value="rgbw">Color</option>
</select>
</div>
</script>

<script type="text/x-red" data-help-name="MiLightRGB">
<p>Sets a MiLight globe to the RGB (#000000) value specified in msg.payload</p>
</script>

<script type="text/x-red" data-template-name="MiLightPower">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-zone"><i class="icon-tag"></i>Default Zone</label>
<label for="node-input-zone">Default Zone</label>
<input type="text" id="node-input-zone" placeholder="1">
</div>
<div class="form-row">
<label for="node-input-ip"><i class="icon-tag"></i>IP Address</label>
<label for="node-input-ip">IP Address</label>
<input type="text" id="node-input-ip" placeholder="255.255.255.255">
</div>
<div class="form-row">
<label for="node-input-broadcast"><i class="icon-tag"></i>Broadcast</label>
<label for="node-input-broadcast">Broadcast</label>
<input type="checkbox" id="node-input-broadcast" placeholder="false">
</div>
</script>

<script type="text/x-red" data-help-name="MiLightPower">
<p>Sets a MiLight power status to either on/off based on msg.payload (expects "on" or "off" only). "On" will return to last used configuration</p>
</script>
<script type="text/x-red" data-template-name="MiLightWhite">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-zone"><i class="icon-tag"></i>Default Zone</label>
<input type="text" id="node-input-zone" placeholder="1">
</div>
<div class="form-row">
<label for="node-input-ip"><i class="icon-tag"></i>IP Address</label>
<input type="text" id="node-input-ip" placeholder="255.255.255.255">
</div>
<div class="form-row">
<label for="node-input-broadcast"><i class="icon-tag"></i>Broadcast</label>
<input type="checkbox" id="node-input-broadcast" placeholder="false">
</div>
</script>
<script type="text/x-red" data-help-name="MiLight">
<p>To control the bulb pass the command in to the msg.payload:</p>
<ul>
<li>'on' - Turns the bulb on (white and color)</li>
<li>'off' - Turns the bulb off (white and color)</li>
<li>'white' - Sets a color bulb to white (color bulb only)</li>
<li>'disco' - Cycles a bulb through all the colors (color bulb only)</li>
<li>(a number not a string range 0 - 255) - Sets the hue of the bulb (color bulb only)</li>
<li>(a number not a string range 0 - 100) - Sets the brightness of the bulb (color bulb only)</li>
<li>'bright_up' - Increase the brightness of the bulb (white bulb only)</li>
<li>'bright_down' - Decrease the brightness of the bulb (white bulb only)</li>
<li>'cooler' - Make the bulb cooler (white bulb only)</li>
<li>'warmer' - Make the bulb warmer (white bulb only)</li>
<li>'bright_max' - Make the bulb brightness maximum (white bulb only)</li>
<li>'night' - Turn the night mode (white bulb only)</li>
</ul>
<p>Important: for setting the brightness and color of the color bulb, <b>msg.command</b> needs to be set as following</p>
<ul>
<li>'brightness' - Set brightness</li>
<li>'color' - Set color</li>
</ul>

<script type="text/x-red" data-help-name="MiLightWhite">
<p>Sets a MiLight globe to white to a brightness value specified in msg.payload (1-100)</p>
</script>
</script>
142 changes: 85 additions & 57 deletions MiLight.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,88 @@
module.exports = function(RED) {
function MiLightPower(config) {
RED.nodes.createNode(this,config);
var node = this;
var MiLight = require('milight');
var milight = new MiLight({
host: config.ip,
broadcast: config.broadcast
});
var zone = config.zone;
this.on('input', function(msg) {
if (msg.payload == "off") milight.zone(zone).off();
if (msg.payload == "on") milight.zone(zone).on();
});
};
RED.nodes.registerType("MiLightPower",MiLightPower);

function MiLightRGB(config) {
RED.nodes.createNode(this,config);
var node = this;
var MiLight = require('milight');

var milight = new MiLight({
host: config.ip,
broadcast: config.broadcast
});
var zone = config.zone;


this.on('input', function(msg) {
if (typeof msg.payload == "string") {
milight.zone(zone).rgb(msg.payload);
} else {
milight.zone(zone).rgb(msg.payload.rgb || "#FFFFFF");
milight.zone(zone).brightness(msg.payload.brightness) || 100;
}
});
};
RED.nodes.registerType("MiLightRGB",MiLightRGB);

function MiLightWhite(config) {
RED.nodes.createNode(this,config);
var node = this;
var MiLight = require('milight');

var milight = new MiLight({
host: config.ip,
broadcast: config.broadcast
});
var zone = config.zone;

var Milight = require('node-milight-promise').MilightController;
var whiteCommands = require('node-milight-promise').commands;
var rgbwCommands = require('node-milight-promise').commands2;

module.exports = function (RED) {
function node(config) {

RED.nodes.createNode(this, config);
var node = this;

this.on('input', function (msg) {

this.on('input', function(msg) {
milight.zone(zone).white(msg.payload);
});
};
RED.nodes.registerType("MiLightWhite",MiLightWhite);
var light = new Milight({
ip: config.ip,
delayBetweenCommands: config.bulbtype === 'rgbw' ? 50 : 100,
commandRepeat: config.bulbtype === 'rgbw' ? 2 : 1
}),
zone = config.zone,
bulb = config.bulbtype;

//i know this is private but its the only way i could get it to work
light._broadcastMode = config.broadcast;
var command = msg.command;

if (bulb === 'rgbw') {
switch (msg.payload) {
case 'off':
light.sendCommands(rgbwCommands[bulb].off(zone));
break;
case 'on':
light.sendCommands(rgbwCommands[bulb].on(zone));
break;
case 'disco':
light.sendCommands(rgbwCommands.rgbw.on(zone));
for (var x = 0; x < 256; x += 5) {
light.sendCommands(rgbwCommands.rgbw.hue(x));
light.pause(100);
}
break;
case 'white':
light.sendCommands(rgbwCommands.rgbw.on(zone), rgbwCommands.rgbw.brightness(100), rgbwCommands.rgbw.whiteMode(zone));
break;
default:
if (!isNaN(msg.payload)) {
if (command === 'brightness')
light.sendCommands(rgbwCommands.rgbw.brightness(msg.payload));
else if (command === 'color')
light.sendCommands(rgbwCommands.rgbw.hue(msg.payload));
}
break;
}
} else {
switch (msg.payload) {
case 'off':
light.sendCommands(whiteCommands[bulb].off(zone));
break;
case 'on':
light.sendCommands(whiteCommands[bulb].on(zone));
break;
case 'bright_up':
light.sendCommands(whiteCommands[bulb].brightUp(zone));
break;
case 'bright_down':
light.sendCommands(whiteCommands[bulb].brightDown(zone));
break;
case 'cooler':
light.sendCommands(whiteCommands[bulb].cooler(zone));
break;
case 'warmer':
light.sendCommands(whiteCommands[bulb].warmer(zone));
break;
case 'bright_max':
light.sendCommands(whiteCommands[bulb].maxBright(zone));
break;
case 'night':
light.sendCommands(whiteCommands[bulb].nightMode(zone));
break;
}
}

light.close().then(function () {

});
});
}

}
RED.nodes.registerType("MiLight", node);
};
35 changes: 26 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
# node-red-contrib-milight
A Node Red wrapper for https://github.com/oeuillot/node-milight.git
Currently presents 3 Nodes

* Milight RGB (set RGB colors)
* Milight White (set white mode brightness)
* Milight Power (on/off control)
## To Do
Create a single Node which encompasses all functionality
A Node Red nodes to control White and Color Milight LED bulbs and OEM equivalents such as Rocket LED, Limitless LED Applamp, Easybulb, s'luce, iLight, iBulb, and Kreuzer.

## Known Issues
## Install

* MiLightRGB has brightness controls, however causes an odd flicker when changing
```npm i node-red-contrib-milight```

## Example Flow

[{"id":"703feba3.f74ba4","type":"MiLight","z":"cedb2490.c23188","name":"White Milight Bulb","bulbtype":"white","zone":1,"ip":"192.168.0.21","broadcast":true,"x":602.5,"y":175,"wires":[]},{"id":"ea754d8b.c0a0a","type":"MiLight","z":"cedb2490.c23188","name":"Color Milight Bulb","bulbtype":"white","zone":1,"ip":"192.168.0.21","broadcast":true,"x":625.5,"y":488,"wires":[]},{"id":"9aa84473.6753f8","type":"inject","z":"cedb2490.c23188","name":"Off","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"x":148.5,"y":432,"wires":[["ea754d8b.c0a0a"]]},{"id":"ee46f786.9dfcd8","type":"inject","z":"cedb2490.c23188","name":"On","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"x":152.5,"y":485,"wires":[["ea754d8b.c0a0a"]]},{"id":"994c5f75.f75a5","type":"inject","z":"cedb2490.c23188","name":"white","topic":"","payload":"white","payloadType":"str","repeat":"","crontab":"","once":false,"x":149.5,"y":539,"wires":[["ea754d8b.c0a0a"]]},{"id":"f6ea5afe.d758b8","type":"inject","z":"cedb2490.c23188","name":"Brightness","topic":"","payload":"10","payloadType":"num","repeat":"","crontab":"","once":false,"x":145.5,"y":610,"wires":[["44621f47.abc8f"]]},{"id":"44621f47.abc8f","type":"function","z":"cedb2490.c23188","name":"","func":"msg.command = 'brightness';\nreturn msg;","outputs":1,"noerr":0,"x":320.5,"y":610,"wires":[["ea754d8b.c0a0a"]]},{"id":"d2630aff.f36b38","type":"inject","z":"cedb2490.c23188","name":"Color","topic":"","payload":"20","payloadType":"num","repeat":"","crontab":"","once":false,"x":138.5,"y":668,"wires":[["1341915.7fd236f"]]},{"id":"1341915.7fd236f","type":"function","z":"cedb2490.c23188","name":"","func":"msg.command = 'color';\nreturn msg;","outputs":1,"noerr":0,"x":319.5,"y":669,"wires":[["ea754d8b.c0a0a"]]},{"id":"8ea9e947.32c7c8","type":"inject","z":"cedb2490.c23188","name":"On","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"x":141.5,"y":36,"wires":[["703feba3.f74ba4"]]},{"id":"9d1a4225.3a926","type":"inject","z":"cedb2490.c23188","name":"Off","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"x":141,"y":78,"wires":[["703feba3.f74ba4"]]},{"id":"ddc3d3e9.af25","type":"inject","z":"cedb2490.c23188","name":"Warmer","topic":"","payload":"warmer","payloadType":"str","repeat":"","crontab":"","once":false,"x":144.5,"y":128,"wires":[["703feba3.f74ba4"]]},{"id":"6d5e9f9d.72a17","type":"inject","z":"cedb2490.c23188","name":"Cooler","topic":"","payload":"cooler","payloadType":"str","repeat":"","crontab":"","once":false,"x":146,"y":176,"wires":[["703feba3.f74ba4"]]},{"id":"9ef7721c.7ae64","type":"inject","z":"cedb2490.c23188","name":"Bright Up","topic":"","payload":"bright_up","payloadType":"str","repeat":"","crontab":"","once":false,"x":157.5,"y":224,"wires":[["703feba3.f74ba4"]]},{"id":"88a65d6.31e7ba","type":"inject","z":"cedb2490.c23188","name":"Bright Down","topic":"","payload":"bright_down","payloadType":"str","repeat":"","crontab":"","once":false,"x":166.5,"y":271,"wires":[["703feba3.f74ba4"]]},{"id":"701d5fcc.86432","type":"inject","z":"cedb2490.c23188","name":"Bright Max","topic":"","payload":"bright_max","payloadType":"str","repeat":"","crontab":"","once":false,"x":158.5,"y":314,"wires":[["703feba3.f74ba4"]]},{"id":"e103214f.25c99","type":"inject","z":"cedb2490.c23188","name":"Night","topic":"","payload":"night","payloadType":"str","repeat":"","crontab":"","once":false,"x":152.5,"y":357,"wires":[["703feba3.f74ba4"]]}]


To control the bulb pass the command in to the msg.payload:

- 'on' - Turns the bulb on (white and color)
- 'off' - Turns the bulb off (white and color)
- 'white' - Sets a color bulb to white (color bulb only)
- 'disco' - Cycles a bulb through all the colors (color bulb only)
- (a number not a string range 0 - 255) - Sets the hue of the bulb (color bulb only)
- (a number not a string range 0 - 100) - Sets the brightness of the bulb (color bulb only)
- 'bright_up' - Increase the brightness of the bulb (white bulb only)
- 'bright_down' - Decrease the brightness of the bulb (white bulb only)
- 'cooler' - Make the bulb cooler (white bulb only)
- 'warmer' - Make the bulb warmer (white bulb only)
- 'bright_max' - Make the bulb brightness maximum (white bulb only)
- 'night' - Turn the night mode (white bulb only)

Important: for setting the brightness and color of the color bulb, msg.command needs to be set as following:

- 'brightness' - Set brightness
- 'color' - Set color

Loading