Achtung:
Das Skript ist wirklich sehr individuell und Alpha-Status.
Im Javascript Adapter muss das Modul "@q42philips/hue-color-converter" eingetragen werden.
Man muss die IP ändern und ich habe eine Hue Szene angeben, welche beim Deaktivieren des Ambilights gestartet wird (durch mein Hue Szenen Skript).
Dann muss jede Hue Lampe mit einer Ambilight LED "verknüpft" werden im Mittelteil des Skripts…
Die LEDs kann man sich hier auflisten lassen: http://<ip_vom_tv>:1925/1/ambilight/processed
An dem Objekten kann man das Verhalten anpassen.
! ````
// Replace IP, scene and configure lights!!!
var host = '192.168.x.x',
stop_hue_scene = 'javascript.0.PhilipsHue.Scenes.TV.xxx';
! var http = require('http'),
converter = require('@q42philips/hue-color-converter'),
timeout;
! createState('PhilipsHue.Ambilight.Active', false, {type: "boolean", name: 'Activate Philips Hue Ambilight'});
createState('PhilipsHue.Ambilight.Level', 25, {type: "number", name: 'Dim Level for Ambilight',"max": 100,"min": 0,"unit": "%"});
createState('PhilipsHue.Ambilight.TransitionTime', 20, {type: "number", name: 'Smoothness for changing colors',"unit": "x 100 ms"});
createState('PhilipsHue.Ambilight.Interval', 500, {type: "number", name: 'Interval for syncing Hue Lights with Philips TV',"unit": "ms","min": 200});
! var level = getState('PhilipsHue.Ambilight.Level').val || 25,
transitiontime = getState('PhilipsHue.Ambilight.TransitionTime').val || 20,
interval = getState('PhilipsHue.Ambilight.Interval').val || 500;
! function startAmbilight(){
timeout = setInterval (function(){
var url = 'http://'+host+':1925/1/ambilight/processed';
http.get(url, function(res){
var json = '';
res.on('data', function(chunk){
json += chunk;
});
res.on('end', function(){
if (res.statusCode === 200) {
try {
var data = JSON.parse(json);
// CONFIGURE HERE --------------------------------------------------------------
// Couch_links (LCT010) = layer1 - left - 2
var r1 = data.layer1.left[2].r;
var g1 = data.layer1.left[2].g;
var b1 = data.layer1.left[2].b;
var xy1 = converter.calculateXY(r1, g1, b1, 'LCT010');
var command1 = '{"transitiontime":'+transitiontime+',"xy":['+xy1+'],"level":'+level+'}';
setState('hue.0.Hue_Bridge.Couch_links.command', command1);
// Couch_rechts (LCT010) = layer1 - right - 1
var r2 = data.layer1.right[1].r;
var g2 = data.layer1.right[1].g;
var b2 = data.layer1.right[1].b;
var xy2 = converter.calculateXY(r2, g2, b2, 'LCT010');
var command2 = '{"transitiontime":'+transitiontime+',"xy":['+xy2+'],"level":'+level+'}';
setState('hue.0.Hue_Bridge.Couch_rechts.command', command2);
// Wohnwand (LST002) = layer1 - right - 0
var r3 = data.layer1.right[0].r;
var g3 = data.layer1.right[0].g;
var b3 = data.layer1.right[0].b;
var xy3 = converter.calculateXY(r3, g3, b3, 'LST002');
var command3 = '{"transitiontime":'+transitiontime+',"xy":['+xy3+'],"level":'+level+'}';
setState('hue.0.Hue_Bridge.Wohnwand.command', command3);
// CONFIGURE HERE --------------------------------------------------------------
} catch (e) {
console.error('Error parsing JSON!');
}
} else {
console.error('Status: ', res.statusCode);
}
});
}).on('error', function (err) {
console.error('Error: ', err);
stopAmbilight(timeout);
});
}, interval);
return timeout;
}
! function stopAmbilight(timeout){
clearInterval(timeout);
setState(stop_hue_scene, true);
}
! if(getState("javascript.0.PhilipsHue.Ambilight.Active").val === true) {
console.log('Starting Ambilight...');
timeout = startAmbilight();
}
! on({id: "javascript.0.PhilipsHue.Ambilight.Active", val: true}, function (obj) {
console.log('Starting Ambilight...');
timeout = startAmbilight();
});
! on({id: "javascript.0.PhilipsHue.Ambilight.Active", val: false}, function (obj) {
console.log('Stopping Ambilight...');
stopAmbilight(timeout);
});
! on({id: "javascript.0.PhilipsHue.Ambilight.Level", change: "ne"}, function (obj) {
level = obj.state.val;
});
! on({id: "javascript.0.PhilipsHue.Ambilight.TransitionTime", change: "ne"}, function (obj) {
transitiontime = obj.state.val;
});
! on({id: "javascript.0.PhilipsHue.Ambilight.Interval", change: "ne"}, function (obj) {
interval = obj.state.val;
});
! ````</ip_vom_tv>