node-red-contrib-smartnora
Version:
Google Smart Home integration via Smart Nora https://smart-nora.eu/
206 lines (204 loc) • 8.61 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('noraf-thermostat', {
category: 'nora',
color: 'rgb(235, 227, 141)',
icon: 'assistant.png',
defaults: {
devicename: {
value: 'Thermostat',
required: true,
},
roomhint: {
value: ''
},
name: {
value: ''
},
modes: {
value: 'off',
},
unit: {
value: 'C',
validate: function (v) { return v === 'C' || v === 'F'; },
},
rangeMin: {
value: '',
validate: function (v) { return !v || RED.validators.number()(v) },
},
rangeMax: {
value: '',
validate: function (v) { return !v || RED.validators.number()(v) },
},
topic: {
value: ''
},
passthru: {
value: false,
},
commandOnly: {
value: false,
},
queryOnly: {
value: false,
},
bufferRangeCelsius: {
value: 2,
validate: function (v) {
return !v || RED.validators.number()(v) && v >= 0.5 && v <= 20;
},
},
nora: {
type: 'noraf-config',
required: true
},
twofactor: {
value: 'off',
},
twofactorpin: {
value: ''
},
filter: {
value: false,
},
},
inputs: 1,
outputs: 1,
paletteLabel: 'thermostat',
label: function () {
return this.name || this.devicename || 'thermostat';
},
oneditprepare: function () {
var availableModes = ['off', 'heat', 'cool', 'heatcool', 'on', 'auto', 'fan-only', 'purifier', 'eco', 'dry'];
var row;
var modes = this.modes.split(',');
availableModes.forEach(function (mode, index) {
var rowIndex = Math.floor(index / 3);
if (index % 3 === 0) {
$('#modes-container').append(
'<div class="mode-row" mode-row-index="' + rowIndex + '"></div>'
);
}
$('[mode-row-index=' + rowIndex + ']').append(
'<div class="mode-item">' +
'<input type="checkbox" ' +
(modes.indexOf(mode) >= 0 ? 'checked ' : '') +
(mode === 'off' ? 'disabled ' : '') +
'class="thermostat-mode" data-mode="' + mode + '" id="mode-' + mode + '">' +
'<label for="mode-' + mode + '">' + mode + '</label>' +
'</div>'
);
});
if ((this.unit || 'C') === 'C') {
$('#unit-celsius').prop('checked', true);
} else {
$('#unit-fahrenheit').prop('checked', true);
}
$('#node-input-twofactor').change(function () {
if ($(this).val() === 'pin') {
$('#node-twofactor-pin').show();
} else {
$('#node-twofactor-pin').hide();
}
});
},
oneditsave: function () {
var modes = [];
$('.thermostat-mode:checked').each(function () {
modes.push($(this).attr('data-mode'));
});
this.modes = modes.join(',');
this.unit = $('#unit-celsius').prop('checked') ? 'C' : 'F';
},
});
</script>
<script type="text/x-red" data-template-name="noraf-thermostat">
<style>
.mode-row {
display: flex;
flex-direction:row;
}
.mode-item {
display:flex;
flex-direction:row;
}
#modes-container {
display:flex;
flex-direction:column;
}
</style>
<div class="form-row">
<label for="node-input-nora"><i class="fa fa-table"></i> Config</label>
<input type="text" id="node-input-nora">
</div>
<div class="form-row">
<label for="node-input-devicename"><i class="fa fa-i-cursor"></i> Thermostat</label>
<input type="text" id="node-input-devicename">
</div>
<div class="form-row">
<label style="width:auto" for="node-input-passthru"><i class="fa fa-arrow-right"></i> If <code>msg</code> arrives on input, pass through to output: </label>
<input type="checkbox" id="node-input-passthru" style="display:inline-block; width:auto; vertical-align:top;">
</div>
<div class="form-row">
<label style="width:auto" for="node-input-filter"><i class="fa fa-filter"></i> Ignore input messages that don't match the <code>topic</code> value: </label>
<input type="checkbox" id="node-input-filter" style="display:inline-block; width:auto; vertical-align:top;">
</div>
<div class="form-row">
<label style="width:auto"><i class="fa fa-thermometer-half"></i> Temperature Unit: </label>
<input style="width:auto;margin:0" id="unit-celsius" type="radio" name="unit" value="C"><label style="width:40px" for="unit-celsius"> C</label>
<input style="width:auto;margin:0" id="unit-fahrenheit" type="radio" name="unit" value="F"><label style="width:40px" for="unit-fahrenheit"> F</label>
</div>
<div class="form-row d-flex flex-column">
<label for="node-input-devicename" style="width: 100%">Temperature Range (Celsius)</label>
<br>
<label for="node-input-rangeMin" style="text-align:right"><i class="fa fa-thermometer-empty"></i> Min</label>
<input style="margin-bottom:5px" type="text" id="node-input-rangeMin" placeholder="10">
<br>
<label for="node-input-rangeMax" style="text-align:right"><i class="fa fa-thermometer-full"></i> Max</label>
<input type="text" id="node-input-rangeMax" placeholder="32">
</div>
<div class="form-row d-flex flex-column">
<label style="width:100%"><i class="fa fa-cog"></i> Supported modes</label>
<div id="modes-container"></div>
</div>
<div class="form-row">
<label for="node-input-bufferRangeCelsius" style="width:auto"><i class="fa fa-random"></i> Buffer range celsius</label>
<input type="text" id="node-input-bufferRangeCelsius" style="width:20%">
</div>
<div class="form-row">
<label style="width:auto" for="node-input-commandOnly"><i class="fa fa-exchange"></i> Command only: </label>
<input type="checkbox" id="node-input-commandOnly" style="display:inline-block; width:auto; vertical-align:top;">
</div>
<div class="form-row">
<label style="width:auto" for="node-input-queryOnly"><i class="fa fa-question"></i> Query only (sensor): </label>
<input type="checkbox" id="node-input-queryOnly" style="display:inline-block; width:auto; vertical-align:top;">
</div>
<div class="form-row">
<label for="node-input-roomhint"><i class="fa fa-i-cursor"></i> Room Hint</label>
<input type="text" id="node-input-roomhint">
</div>
<div class="form-row">
<label for="node-input-twofactor"><i class="fa fa-question-sign"></i> Two Factor</label>
<select id="node-input-twofactor">
<option value="off">None</option>
<option value="ack">Acknowledge</option>
<option value="pin">Pin</option>
</select>
</div>
<div id="node-twofactor-pin" class="form-row">
<label for="node-input-twofactorpin"><i class="fa fa-code"></i> Pin</label>
<input type="text" id="node-input-twofactorpin">
</div>
<div class="form-row">
<label for="node-input-topic" style="padding-left:25px; margin-right:-25px">Topic</label>
<input type="text" id="node-input-topic">
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name">
</div>
</script>
<script type="text/x-red" data-help-name="noraf-thermostat">
<p>
<a href="https://github.com/andrei-tatar/node-red-contrib-smartnora/blob/master/doc/nodes/thermostat/README.md">https://github.com/andrei-tatar/node-red-contrib-smartnora/blob/master/doc/nodes/thermostat/README.md</a>
</p>
</script>