Blockly Skripte für Grüne Blaue Gelbe Rote Leuchtszenen
Tipp: Im Codefenster rechts auf "Copy" klicken.

Chris
Editor
Grüner Puls mit rotem Aufblitzen
Level1
R1
G1
B1
Transition1
Level2
R2
G2
B2
Transition2
Intervall
Green
Level1
80
R1
67
G1
177
B1
126
Transition1
25
Red
Level2
50
R2
254
G2
53
B2
30
Transition2
1
SCRIPT
javascript.0.Eigene_Datenpunkte.HUE.GreenPulseWithRedFlashSW
any
EQ
state.val
TRUE
hue.0.Philips_hue.INFO.command
TRUE
100
ms
FALSE
{"on":true,"level":
Level1
,"r":
R1
,"g":
G1
,"b":
B1
,"transitiontime":
Transition1
}
hue.1.Philips_hue.INFO.command
TRUE
4000
ms
FALSE
{"on":true,"level":
Level2
,"r":
R2
,"g":
G2
,"b":
B2
,"transitiontime":
Transition2
}
Intervall
Intervall
4000
ms
hue.0.Philips_hue.INFO.command
TRUE
100
ms
FALSE
{"on":true,"level":
Level1
,"r":
R1
,"g":
G1
,"b":
B1
,"transitiontime":
Transition1
}
hue.1.Philips_hue.INFO.command
TRUE
4000
ms
FALSE
{"on":true,"level":
Level2
,"r":
R2
,"g":
G2
,"b":
B2
,"transitiontime":
Transition2
}
EQ
state.val
FALSE
Intervall
hue.0.Philips_hue.INFO.command
TRUE
50
ms
FALSE
{"on":false,"transitiontime":3}
hue.0.Philips_hue.INFO.command
TRUE
2500
ms
FALSE
{"on":false,"transitiontime":3}
hue.0.Philips_hue.INFO.command
TRUE
4500
ms
FALSE
{"on":false,"transitiontime":3}
Sanftes gelbes Aufleuchten
Level
R
G
B
Transition1
Transition2
Intervall
Farben definieren
Level
65
R
255
G
255
B
0
Transition1
35
Ausleuchten definieren
Transition2
7
Flash Script
javascript.0.Eigene_Datenpunkte.HUE.LightYellowFlashSW
any
EQ
state.val
TRUE
hue.0.Philips_hue.INFO.command
TRUE
300
ms
FALSE
{"on":true,"level":
Level
,"r":
R
,"g":
G
,"b":
B
,"transitiontime":
Transition1
}
hue.0.Philips_hue.INFO.command
TRUE
4000
ms
FALSE
{"on":false,"transitiontime":
Transition2
}
Intervall
Intervall
8000
ms
hue.0.Philips_hue.INFO.command
TRUE
300
ms
FALSE
{"on":true,"level":
Level
,"r":
R
,"g":
G
,"b":
B
,"transitiontime":
Transition1
}
hue.0.Philips_hue.INFO.command
TRUE
4000
ms
FALSE
{"on":false,"transitiontime":
Transition2
}
EQ
state.val
FALSE
Intervall
hue.0.Philips_hue.INFO.command
TRUE
50
ms
FALSE
{"on":false,"transitiontime":0
238
221
130
Orange zu rotem Aufleuchten
Level1
R1
G1
B1
Transition1
Level2
R2
G2
B2
Transition2
Intervall
Orange
Level1
100
R1
255
G1
127
B1
36
Transition1
15
Red
Level2
100
R2
254
G2
53
B2
30
Transition2
15
SCRIPT
javascript.0.Eigene_Datenpunkte.HUE.Orange_zu_Rot_SW
any
EQ
state.val
TRUE
hue.0.Philips_hue.INFO.command
TRUE
300
ms
FALSE
{"on":true,"level":
Level1
,"r":
R1
,"g":
G1
,"b":
B1
,"transitiontime":
Transition1
}
hue.0.Philips_hue.INFO.command
TRUE
2000
ms
FALSE
{"on":false,"transitiontime":3}
hue.1.Philips_hue.INFO.command
TRUE
2300
ms
FALSE
{"on":true,"level":
Level2
,"r":
R2
,"g":
G2
,"b":
B2
,"transitiontime":
Transition2
}
hue.1.Philips_hue.INFO.command
TRUE
4000
ms
FALSE
{"on":false,"transitiontime":3}
Intervall
Intervall
4000
ms
hue.0.Philips_hue.INFO.command
TRUE
300
ms
FALSE
{"on":true,"level":
Level1
,"r":
R1
,"g":
G1
,"b":
B1
,"transitiontime":
Transition1
}
hue.0.Philips_hue.INFO.command
TRUE
2000
ms
FALSE
{"on":false,"transitiontime":3}
hue.1.Philips_hue.INFO.command
TRUE
2300
ms
FALSE
{"on":true,"level":
Level2
,"r":
R2
,"g":
G2
,"b":
B2
,"transitiontime":
Transition2
}
hue.1.Philips_hue.INFO.command
TRUE
4000
ms
FALSE
{"on":false,"transitiontime":3}
EQ
state.val
FALSE
Intervall
hue.0.Philips_hue.INFO.command
TRUE
50
ms
FALSE
{"on":false,"transitiontime":3}
var HueApi = require("node-hue-api").HueApi;
// Replace IP and username!!! IP=Bridge IP/Username=aus dem hue controller kopieren!!!
var host = "192.168.10.24",
username = "ytTzQ4FgD2QNqXRW5jpgnHMA-GcLshxXmr-oiSuT",
api = new HueApi(host, username);
var groups_ = [],
lights_ = [],
objects_ = [];
// Log JSON results
var displayResults = function(result) {
console.log('Reponse: '+JSON.stringify(result, null, 2));
};
// Parse Light Group 0 (All Lights)
var parseGroup0 = function(result) {
if (!result.lights){return} // Empty group
var id = result.id,
lights = result.lights,
name = "All Lights";
console.debug('group: '+name+', lights: '+lights);
groups_[lights] = name;
};
// Parse Light Groups
var parseGroups = function(result) {
for (var i = 0; i < result.length; i++) {
if (!result[i].lights){continue} // Empty group
var id = result[i].id,
lights = result[i].lights,
name = result[i].name;
console.debug('group: '+name+', lights: '+lights);
groups_[lights] = name;
}
};
// Parse Lights
var parseLights = function(result) {
for (var i = 0; i < result.length; i++) {
var id = result[i].id,
name = result[i].name;
console.debug('light: '+name+', id: '+id);
lights_[id] = name;
}
};
// Create States in ioBroker
var createStates = function(result) {
// Resync button
createState('PhilipsHue.Scenes.Resync', false, {role: "button", name: 'Resync Philips Hue Groups, Lights and Scenes'});
for (var i = 0; i < result.length; i++) {
if (!result[i].appdata.data){continue} // skip internal szenes
var id = result[i].id,
lights = result[i].lights,
name = result[i].name.replace(/"/g,''),
pathname = name.replace(/ /g,'_');
// Get light names
var light_names = [];
for (var j = 0; j < lights.length; j++) {
var light_name = lights_[lights[j]];
light_names.push(light_name);
}
// Room, group or lights linked with scene
var group = 'Group: '+groups_[lights] || 'Lights: '+light_names.join(", ");
// Create States and skip duplicates
if (!objects_[lights+pathname]){
console.debug('scene: '+name+', '+group);
createState('PhilipsHue.Scenes.'+pathname+'.'+id, false, {role: "button", name: 'Scene: '+name+' ('+group+')'});
objects_[lights+pathname] = true;
}
}
};
// Delete States
function deleteStates(){
console.log('Deleting current objects for scenes...');
objects_ = [];
$('javascript.0.PhilipsHue.Scenes.*').each(function (id) {
deleteState(id);
});
}
// Fetch data from Hue API
function init(){
api.getGroup(0, function(err, group0) {
if (err) throw err;
console.log('Processing group 0...');
//displayResults(group0);
parseGroup0(group0);
});
api.groups(function(err, groups) {
if (err) throw err;
console.log('Processing ' + groups.length + ' groups...');
//displayResults(groups);
parseGroups(groups);
});
api.lights(function(err, lights) {
if (err) throw err;
console.log('Processing ' + lights.lights.length + ' lights...');
//displayResults(lights);
parseLights(lights.lights);
});
api.scenes(function(err, scenes) {
if (err) throw err;
console.log('Processing ' + scenes.length + ' scenes...');
//displayResults(scenes);
createStates(scenes);
});
}
// Init on start
init();
// Activate scene
on({id: /^javascript\.0\.PhilipsHue.Scenes\./, val: true}, function (obj) {
if (obj.id == 'javascript.0.PhilipsHue.Scenes.Resync'){return}
sceneId = obj.id.split('.').pop();
console.log('Activating '+obj.name);
api.activateScene(sceneId, function(err, result) {
if (err) throw err;
displayResults(result);
});
setState(obj.id, false);
});
// Resync
on({id: 'javascript.0.PhilipsHue.Scenes.Resync', val: true}, function (obj) {
console.log('Resync triggered...');
groups_ = [];
lights_ = [];
deleteStates();
init();
});
schedule("0 3 * * *", function () {
console.log('Resync triggered...');
groups_ = [];
lights_ = [];
deleteStates();
init();
});