Skip to content

Commit

Permalink
HmIP-MP3P color control (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Feb 15, 2019
1 parent 0588146 commit b039b37
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 9 deletions.
15 changes: 14 additions & 1 deletion nodes/ccu-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,20 @@ module.exports = function (RED) {
const devices = config.metadata.devices[req.query.iface];
if (devices) {
Object.keys(devices).forEach(addr => {
if (['SIGNAL_CHIME', 'SIGNAL_LED', 'ALARM_SWITCH_VIRTUAL_RECEIVER'].includes(devices[addr].TYPE)) {
if ([
'SIGNAL_CHIME',
'SIGNAL_LED',
'ALARM_SWITCH_VIRTUAL_RECEIVER'
].includes(devices[addr].TYPE)) {
obj[addr] = {
name: config.channelNames[addr],
type: devices[addr].TYPE
};
}
if (devices[addr].PARENT_TYPE === 'HmIP-MP3P' && [
'ACOUSTIC_SIGNAL_VIRTUAL_RECEIVER',
'DIMMER_VIRTUAL_RECEIVER'
].includes(devices[addr].TYPE)) {
obj[addr] = {
name: config.channelNames[addr],
type: devices[addr].TYPE
Expand Down
148 changes: 140 additions & 8 deletions nodes/ccu-signal.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,36 @@
'Weiss lang': 114
};

const ccuDimmerColors = {
Aus: 0,
Blau: 1,
Grün: 2,
Türkis: 3,
Rot: 4,
Violett: 5,
Gelb: 6,
Weiss: 7
};

const ccuOnTime = {
'100ms': 0,
'200ms': 1,
'300ms': 2,
'400ms': 3,
'500ms': 4,
'700ms': 5,
'1s': 6,
'2s': 7,
'3s': 8,
'5s': 9,
'7s': 10,
'10s': 11,
'20s': 12,
'40s': 13,
'60s': 14,
'Permanent': 15,
};

RED.nodes.registerType('ccu-signal', {

category: 'ccu',
Expand All @@ -39,7 +69,14 @@
led: {value: ''},
acoustic_alarm_selection: {value: 'DISABLE_ACOUSTIC_SIGNAL'},
duration_unit: {value: 'S'},
duration_value: {value: 3},
duration_value: {value: 0},
ramp_time_unit: {value: 'S'},
ramp_time_value: {value: 0},
repetitions: {value: 0},
dimmer_level: {value: 100},
dimmer_list: {value: []},
sound_list: {value: []},
acoustic_level: {value: 50},
optical_alarm_selection: {value: 'DISABLE_OPTICAL_SIGNAL'},
ccuConfig: {value: 'localhost', type: 'ccu-connection', required: true}
},
Expand Down Expand Up @@ -206,6 +243,29 @@
$('<option value="' + ccuSignalColors[name] + '"' + (ccuSignalColors[name] === parseInt(data.cmd, 10) ? ' selected' : '') +
'>' + name + '</option>').appendTo(select);
});

}
});

$('#node-input-dimmer-container').css('min-height', '300px').css('min-width', '450px').editableList({
sortable: true,
removable: true,
addItem: (container, i, data) => {
if ($('#node-input-dimmer-container').editableList('length') > 12) {
$('#node-input-dimmer-container').editableList('removeItem', data);
return false;
}

const select = $('<select class="number color" style="width: calc(50% - 8px);" value="' + data.color + '"/>').appendTo(container);
Object.keys(ccuDimmerColors).forEach(name => {
$('<option value="' + ccuDimmerColors[name] + '"' + (ccuDimmerColors[name] === parseInt(data.color, 10) ? ' selected' : '') +
'>' + name + '</option>').appendTo(select);
});
const ontime = $(`<select class="number ontime" style="width: calc(50% - 8px); margin-left: 6px;" value="${data.ontime}"></select>`).appendTo(container);
Object.keys(ccuOnTime).forEach(name => {
$('<option value="' + ccuOnTime[name] + '"' + (ccuOnTime[name] === parseInt(data.ontime, 10) ? ' selected' : '') +
'>' + name + '</option>').appendTo(ontime);
});
}
});

Expand All @@ -229,6 +289,10 @@
});
} else if (this.channelType === 'ALARM_SWITCH_VIRTUAL_RECEIVER') {
// ...
} else if (this.channelType === 'DIMMER_VIRTUAL_RECEIVER') {
this.dimmer_list.forEach(item => {
$('#node-input-dimmer-container').editableList('addItem', item);
});
} else {
console.error('unknown channelType', this.channelType);
}
Expand All @@ -255,6 +319,15 @@
this.led = led.join(',');
break;
}
case 'DIMMER_VIRTUAL_RECEIVER': {
const dimmer_list = [];
$('#node-input-dimmer-container').editableList('items').each(function () {
dimmer_list.push({color: $(this).find('select.color').val(), ontime: $(this).find('select.ontime').val()});
});
console.log(dimmer_list);
this.dimmer_list = dimmer_list;
break;
}
case 'KEY':
break;

Expand All @@ -264,11 +337,20 @@
this.icon1 = $('#node-input-icon1').val();
this.icon2 = $('#node-input-icon2').val();
this.icon3 = $('#node-input-icon3').val();

this.repetitions = parseInt(this.repetitions, 10);
}
});
</script>

<script type="text/x-red" data-template-name="ccu-signal">


<div class="form-row">
<label for="node-input-name"><i class="icon-globe"></i> Name</label>
<input type="text" id="node-input-name">
</div>

<div class="form-row">
<label for="node-input-ccuConfig"><i class="icon-globe"></i> CCU</label>
<input type="text" id="node-input-ccuConfig">
Expand All @@ -287,7 +369,8 @@
<option value="SIGNAL_CHIME">SIGNAL_CHIME (HM-OU-*)</option>
<option value="SIGNAL_LED">SIGNAL_LED (HM-OU-*)</option>
<option value="ALARM_SWITCH_VIRTUAL_RECEIVER">ALARM (HmIP-ASIR)</option>

<option value="ACOUSTIC_SIGNAL_VIRTUAL_RECEIVER">ACOUSTIC_SIGNAL (HmIP-MP3P)</option>
<option value="DIMMER_VIRTUAL_RECEIVER">DIMMER (HmIP-MP3P)</option>
</select>
</div>

Expand All @@ -311,6 +394,15 @@
<ol id="node-input-led-container"></ol>
</div>

<div class="form-row SUBMIT DIMMER_VIRTUAL_RECEIVER">
<label for="node-input-dimmer"><i class="icon-envelope"></i> LED</label>
<ol id="node-input-dimmer-container"></ol>
</div>

<div class="form-row SUBMIT ACOUSTIC_SIGNAL_VIRTUAL_RECEIVER">
<label for="node-input-acoustic"><i class="icon-envelope"></i> Sounds</label>
<ol id="node-input-dimmer-acoustic"></ol>
</div>

<div class="form-row SUBMIT ALARM_SWITCH_VIRTUAL_RECEIVER">
<label for="node-input-acoustic_alarm_selection"><i class=""></i> Akustisch</label>
Expand Down Expand Up @@ -350,7 +442,52 @@
</select>
</div>

<div class="form-row SUBMIT ALARM_SWITCH_VIRTUAL_RECEIVER">
<div class="form-row SUBMIT ACOUSTIC_SIGNAL_VIRTUAL_RECEIVER DIMMER_VIRTUAL_RECEIVER">
<label for="node-input-repetitions"><i class=""></i> Wiederholungen </label>
<select id="node-input-repetitions">
<option value="0">Keine</option>
<option value="1">1x</option>
<option value="2">2x</option>
<option value="3">3x</option>
<option value="4">4x</option>
<option value="5">5x</option>
<option value="6">6x</option>
<option value="7">7x</option>
<option value="8">8x</option>
<option value="9">9x</option>
<option value="10">10x</option>
<option value="11">11x</option>
<option value="12">12x</option>
<option value="13">13x</option>
<option value="14">14x</option>
<option value="15">Unendlich</option>
</select>

</div>

<div class="form-row SUBMIT ACOUSTIC_SIGNAL_VIRTUAL_RECEIVER ">
<label for="node-input-acoustic_level"><i class=""></i> Lautstärke </label>
<input id="node-input-acoustic_level" type="number" min="0" max="100">
</div>

<div class="form-row SUBMIT DIMMER_VIRTUAL_RECEIVER ">
<label for="node-input-dimmer_level"><i class=""></i> Helligkeit </label>
<input id="node-input-dimmer_level" type="number" min="0" max="100">
</div>


<div class="form-row SUBMIT ACOUSTIC_SIGNAL_VIRTUAL_RECEIVER DIMMER_VIRTUAL_RECEIVER">
<label for="node-input-ramp_time_unit"><i class=""></i> Rampenzeit </label>
<select id="node-input-ramp_time_unit" style="width: calc(35% - 5px)">
<option value="S">Sekunden</option>
<option value="M">Minuten</option>
<option value="H">Stunden</option>
</select>
<input id="node-input-ramp_time_value" type="number" style="width: 35%">
</div>


<div class="form-row SUBMIT ALARM_SWITCH_VIRTUAL_RECEIVER ACOUSTIC_SIGNAL_VIRTUAL_RECEIVER DIMMER_VIRTUAL_RECEIVER">
<label for="node-input-duration_unit"><i class=""></i> Dauer </label>
<select id="node-input-duration_unit" style="width: calc(35% - 5px)">
<option value="S">Sekunden</option>
Expand All @@ -361,11 +498,6 @@
</div>


<div class="form-row">
<label for="node-input-name"><i class="icon-globe"></i> Name</label>
<input type="text" id="node-input-name">
</div>


</script>

Expand Down
19 changes: 19 additions & 0 deletions nodes/ccu-signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = function (RED) {

this.on('input', () => {
let payload;
this.debug(config.channelType);
switch (config.channelType) {
case 'SIGNAL_CHIME':
payload = config.chime;
Expand All @@ -36,6 +37,24 @@ module.exports = function (RED) {
OPTICAL_ALARM_SELECTION: config.optical_alarm_selection
}]);
break;
case 'DIMMER_VIRTUAL_RECEIVER':
const params = {
LEVEL: config.dimmer_level / 100,
RAMP_TIME_UNIT: config.ramp_time_unit,
RAMP_TIME_VALUE: Number(config.ramp_time_value),
DURATION_UNIT: config.duration_unit,
DURATION_VALUE: parseInt(config.duration_value, 10) || 0,
REPETITIONS: Number(config.repetitions),
OUTPUT_SELECT_SIZE: config.dimmer_list.length
};
for (let index = 0; index < config.dimmer_list.length; index++) {
const item = config.dimmer_list[index] || {color: 0, ontime: 0};
params['COLOR_LIST_' + (index + 1)] = Number(item.color);
params['ON_TIME_LIST_' + (index + 1)] = Number(item.ontime);
}
this.debug(params);
this.ccu.methodCall(config.iface, 'putParamset', [config.channel, 'VALUES', params]);
break;
default:
console.error('channelType', config.channelType, 'unknown');
}
Expand Down

0 comments on commit b039b37

Please sign in to comment.