Skip to content

Instantly share code, notes, and snippets.

@Garfonso
Last active November 7, 2020 23:17
Show Gist options
  • Save Garfonso/0a2968f088cb3b1a6f19860cc848545d to your computer and use it in GitHub Desktop.
Save Garfonso/0a2968f088cb3b1a6f19860cc848545d to your computer and use it in GitHub Desktop.
Control Asus Aura LEDs from ioBroker
//use aura-sdk to switch aura light with iobroker :-)
//based on this: https://github.com/DanielRamosAcosta/aura-sdk/blob/master/example/rainbow.js
//known issue: The aura-sdk is not very reliable. I did not find a way to solve this, sadly. Sometimes it just won't switch at all.
//needs 32bit. For windows:
// * install iobroker instance using installer.
// * note node.js version that get's installed (or look it up after install by running node --version in iobroker terminal)
// * download the same node.js version in 32Bit (x86) from here: https://nodejs.org/dist/ as zip file,
// * make sure you download the file containinig win-x86, for example: https://nodejs.org/dist/v10.17.0/node-v10.17.0-win-x86.zip
// * go to the ioBroker-instance folder and rename the nodejs subfolder do nodejs_64
// * create a new folder named nodejs -> extract the zip contents there
// * copy nodevars.bat from the old folder (now nodejs_64) to the new nodejs folder (this is important, else you broke the iobroker terminal!)
// * setup instance to your linkings (for example as slave in your multihost environment)
// * add a javascript instance (iob add javascript) (if not done already, might need admin, so run iob add admin before)
// * in the subfolder node_modules\iobroker.javascript run 'npm install --save aura-sdk' (for me this did not work from adapter config)
// * in javascript instance settings add npm package 'aura-sdk' to adapter config and select 'do not subscribe all states' in config, too.
// * copy this into the script editor as new script (make sure you run it for the right instance)
// * use the objects in javascript.*.aura to control your aura LEDs from ioBroker. :-)
const { AuraSDK, Controller } = require('aura-sdk');
let auraSDK;
let leds;
function initialize() {
auraSDK = new AuraSDK();
leds = Controller.joinControllers([
auraSDK.createMbController(),
auraSDK.createGPUController(),
auraSDK.createDramController()
]);
}
try {
initialize();
} catch (e) {
log("Error during initialization: " + e.stack);
}
function switchLeds(p) {
try {
for (const led of leds) {
led.setColorNow(`hsl(${p.hue}, ${p.saturation}%, ${p.brightness}%)`);
}
} catch (e) {
log("Error during switch: " + e.stack);
}
}
createState('aura.brightness', {type: 'number', read: true, write: true, min: 0, max: 100, unit: '%', role: 'level.brightness'});
createState('aura.state', {type: 'boolean', read: true, write: true, role: 'switch.light'});
createState('aura.hue', {type: 'number', read: true, write: true, min: 0, max: 360, role: 'level.color.hue'});
createState('aura.saturation', {type: 'number', read: true, write: true, min: 0, max: 100, unit: '%', role: 'color.satturation'});
const idPrefix = 'javascript.' + instance + '.aura.';
const brightnessState = idPrefix + 'brightness';
const onOffState = idPrefix + 'state';
const hueState = idPrefix + 'hue';
const satState = idPrefix + 'saturation';
let oldStates = {
brightness: 0,
saturation: 0,
hue: 0
};
getState(brightnessState, (err, state) => oldStates.brightness = state ? state.val : 50);
getState(hueState, (err, state) => oldStates.hue = state ? state.val : 0);
getState(satState, (err, state) => oldStates.saturation = state ? state.val : 100);
//brightness:
on({id: brightnessState, ack: false }, (e) => {
oldStates.brightness = e.state.val;
switchLeds(oldStates);
setState(onOffState, oldStates.brightness > 0, true);
setState(brightnessState, e.state.val, true);
});
//on off -> translate to brightness. on = 50, because 100 is pure white and ignores color.
on({id: onOffState, ack: false }, (e) => {
setState(brightnessState, e.state.val ? 50 : 0, false); //set brithness state.
setState(onOffState, false, true);
});
//hue:
on({id: hueState, ack: false }, (e) => {
let hue = e.state.val;
//normalize:
while (hue < 0) {
hue += 360;
}
while (hue >= 360) {
hue -= 360;
}
log(`Setting hue ${hue}`);
oldStates.hue = hue;
switchLeds(oldStates);
setState(hueState, hue, true);
});
//saturation:
on({id: satState, ack: false }, (e) => {
oldStates.saturation = e.state.val;
switchLeds(oldStates);
setState(satState, e.state.val, true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment