Skip to content

Instantly share code, notes, and snippets.

@pauly7300
Created December 21, 2018 05:21
Show Gist options
  • Save pauly7300/dc6041b7432a70a3145a7d132c49ce5a to your computer and use it in GitHub Desktop.
Save pauly7300/dc6041b7432a70a3145a7d132c49ce5a to your computer and use it in GitHub Desktop.
alexa local light parser
if (typeof msg.on !== 'undefined') {
var cmd = (msg.on ? "on" : "off");
var brightness = -1;
// logic for brightness
if (msg.on) {
if (msg.bri > 0) {
brightness = msg.bri;
var t = 0;
t = Math.floor(brightness * 2.55);
if (t == 254) { t = 255; }
brightness = t;
}
}
var out = {};
out.state = cmd;
if (brightness > 0) {
out.brightness = String(brightness);
}
var msg = {};
msg.payload = out;
return [msg,null];
} else {
return [null,null];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment