My first complete bedroom-lights Homeyscript, with two KaKu duo-switches, a 2-lamp armature and a bed-light, having much fun (edit: Had forgotten to ‘break’ the switch-cases, more of a VB programmer, there you won’t need them):
let Bedlamp = '<unique Homey Bedlamp-hex code>';
let SlaapA = '<unique Homey SlaapA-hex code>';
let SlaapB = '<unique Homey SlaapB-hex code>';
var Lampx = await Homey.devices.getDevice({id:SlaapA});
var Lampy = await Homey.devices.getDevice({id:SlaapB});
var Lampz = await Homey.devices.getDevice({id:Bedlamp});
if (args[0].startsWith('B')) {
if (Lampz.capabilitiesObj.onoff.value) {
Cappy(1,'onoff', false); }
else {
switch (args[0]) {
case 'BedOp':
Cappy(1,'light_mode','temperature');
Cappy(1,'light_temperature',0.60);
Cappy(1,'light_saturation',0.56);
Cappy(1,'light_hue', 0.10);
Cappy(1,'dim', 0.80); break;
case 'BedNeer':
Cappy(1,'light_mode','color');
Cappy(1,'light_temperature',1.00);
Cappy(1,'light_saturation',1.00);
Cappy(1,'light_hue',0.10);
Cappy(1,'dim',0.30); break;
default:
Cappy(1,'onoff', false); } } }
if (args[0].startsWith('S')) {
if (Lampx.capabilitiesObj.onoff.value) {
Cappy(2,'onoff', false); }
else {
switch (args[0]) {
case 'SLOp':
Cappy(2,'light_mode','temperature');
Cappy(2,'light_temperature',0.60);
Cappy(2,'light_saturation',0.56);
Cappy(2,'light_hue', 0.10);
Cappy(2,'dim', 0.80); break;
case 'SLNeer':
Cappy(2,'light_mode','color');
Cappy(2,'light_temperature',1.00);
Cappy(2,'light_saturation',1.00);
Cappy(2,'light_hue',0.10);
Cappy(2,'dim',0.30); break;
default:
Cappy(2,'onoff', false); } } }
function Cappy(Type, Cmnd, Val) {
if (Type === 1){
Lampz.setCapabilityValue(Cmnd, Val); }
if (Type === 2){
Lampx.setCapabilityValue(Cmnd, Val);
Lampy.setCapabilityValue(Cmnd, Val); } }
The flow now looks like this: