node-red-contrib-smartnora
Version:
Google Smart Home integration via Smart Nora https://smart-nora.eu/
289 lines (287 loc) • 12.6 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('noraf-light', {
category: 'nora',
color: 'rgb(235, 227, 141)',
icon: 'assistant.png',
defaults: {
devicename: {
value: 'Light',
required: true,
},
lightcolor: {
value: false,
},
brightnesscontrol: {
value: true,
},
commandonlycolor: {
value: false,
},
turnonwhenbrightnesschanges: {
value: false,
},
passthru: {
value: false,
},
errorifstateunchaged: {
value: false,
},
statepayload: {
value: true,
},
brightnessoverride: {
value: '',
validate: function (v) {
return !v || RED.validators.number()(v);
},
},
roomhint: {
value: ''
},
name: {
value: ''
},
colortype: {
value: 'hsv',
},
nora: {
type: 'noraf-config',
required: true
},
topic: {
value: ''
},
onvalue: {
value: true,
required: true,
validate: (RED.validators.hasOwnProperty('typedInput') ? RED.validators.typedInput(
'onvalueType') : function (v) {
return true
})
},
onvalueType: {
value: 'bool'
},
offvalue: {
value: false,
required: true,
validate: (RED.validators.hasOwnProperty('typedInput') ? RED.validators.typedInput(
'offvalueType') : function (v) {
return true
})
},
offvalueType: {
value: 'bool'
},
temperaturemin: {
value: '2700',
validate: RED.validators.number(),
},
temperaturemax: {
value: '5500',
validate: RED.validators.number(),
},
twofactor: {
value: 'off',
},
twofactorpin: {
value: ''
},
filter: {
value: false,
},
},
inputs: 1,
outputs: 1,
paletteLabel: 'light',
label: function () {
return this.name || this.devicename || 'light';
},
oneditprepare: function () {
$('#node-input-twofactor').change(function () {
if ($(this).val() === 'pin') {
$('#node-twofactor-pin').show();
} else {
$('#node-twofactor-pin').hide();
}
});
const updateDiscretePayloadVisible = () => {
if ($('#node-input-brightnesscontrol').is(':checked') ||
$('#node-input-lightcolor').is(':checked')) {
$('#light-on').hide();
$('#light-off').hide();
$('#light-brightnesschangeon').show();
} else {
$('#light-on').show();
$('#light-off').show();
$('#light-brightnesschangeon').hide();
}
};
const updateTemperatureVisible = () => {
if ($('#node-input-colortype').val() === 'temperature' &&
$('#node-input-lightcolor').is(':checked')) {
$('#temp-min').show();
$('#temp-max').show();
} else {
$('#temp-min').hide();
$('#temp-max').hide();
}
};
$('#node-input-onvalue').typedInput({
default: 'str',
typeField: $("#node-input-onvalueType"),
types: ['str', 'num', 'bool', 'json', 'bin', 'date']
});
$('#node-input-offvalue').typedInput({
default: 'str',
typeField: $("#node-input-offvalueType"),
types: ['str', 'num', 'bool', 'json', 'bin', 'date']
});
$('#node-input-brightnesscontrol').change(function () {
if (this.checked) {
$('#light-full-state').show();
if ($('#node-input-statepayload').is(':checked')) {
$('#light-brightnessoverride').hide();
} else {
$('#light-brightnessoverride').show();
}
} else {
$('#light-full-state').hide();
$('#light-brightnessoverride').hide();
}
updateDiscretePayloadVisible();
});
$('#node-input-lightcolor').change(function () {
if (this.checked) {
$('#color-commandonly').show();
$('#color-type').show();
} else {
$('#color-commandonly').hide();
$('#color-type').hide();
}
updateDiscretePayloadVisible();
updateTemperatureVisible();
});
$('#node-input-colortype').change(function () {
updateTemperatureVisible();
});
$('#node-input-statepayload').change(function () {
if (this.checked || !$('#node-input-brightnesscontrol').is(':checked')) {
$('#light-brightnessoverride').hide();
} else {
$('#light-brightnessoverride').show();
}
});
if (!$('#node-input-colortype').val()) {
$('#node-input-colortype').val('hsv');
}
if (!$('#node-input-temperaturemin').val()) {
$('#node-input-temperaturemin').val('2700');
}
if (!$('#node-input-temperaturemax').val()) {
$('#node-input-temperaturemax').val('5500');
}
},
});
</script>
<script type="text/x-red" data-template-name="noraf-light">
<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> Light</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" for="node-input-errorifstateunchaged"><i class="fa fa-exclamation-triangle"></i> If state doesn't change via voice, warn user: </label>
<input type="checkbox" id="node-input-errorifstateunchaged" style="display:inline-block; width:auto; vertical-align:top;">
</div>
<div class="form-row">
<label style="width:auto" for="node-input-brightnesscontrol"><i class="fa fa-lightbulb-o"></i> Allow brightness control: </label>
<input type="checkbox" checked id="node-input-brightnesscontrol" style="display:inline-block; width:auto; vertical-align:top;">
</div>
<div class="form-row" id="light-brightnesschangeon">
<label style="width:auto" for="node-input-turnonwhenbrightnesschanges"><i class="fa fa-lightbulb-o"></i> Turn on when brightness/color changes: </label>
<input type="checkbox" checked id="node-input-turnonwhenbrightnesschanges" style="display:inline-block; width:auto; vertical-align:top;">
</div>
<div class="form-row" id="light-full-state">
<label style="width:auto" for="node-input-statepayload"><i class="fa fa-arrow-right"></i> Send/receive complete state as payload: </label>
<input type="checkbox" checked id="node-input-statepayload" style="display:inline-block; width:auto; vertical-align:top;">
</div>
<div class="form-row" id="light-brightnessoverride">
<label for="node-input-brightnessoverride" style="width:auto"><i class="fa fa-lightbulb-o"></i> Override brightness when input is 0</label>
<input type="text" id="node-input-brightnessoverride" style="width:100px">
</div>
<div class="form-row">
<label style="width:auto" for="node-input-lightcolor"><i class="fa fa-gamepad"></i> Color support: </label>
<input type="checkbox" id="node-input-lightcolor" style="display:inline-block; width:auto; vertical-align:top;">
</div>
<div class="form-row" id="color-commandonly">
<label style="width:auto" for="node-input-commandonlycolor"><i class="fa fa-gamepad"></i> Command only color support: </label>
<input type="checkbox" id="node-input-commandonlycolor" style="display:inline-block; width:auto; vertical-align:top;">
</div>
<div class="form-row" id="color-type">
<label for="node-input-colortype"><i class="fa fa-question-sign"></i> Type</label>
<select id="node-input-colortype">
<option value="hsv">HSV</option>
<option value="rgb">RGB</option>
<option value="temperature">Temperature</option>
</select>
</div>
<div class="form-row" id="temp-min">
<label for="node-input-temperaturemin" style="width:auto"><i class="fa fa-lightbulb-o"></i> Min temperature (K)</label>
<input type="text" id="node-input-temperaturemin" style="width:100px">
</div>
<div class="form-row" id="temp-max">
<label for="node-input-temperaturemax" style="width:auto"><i class="fa fa-lightbulb-o"></i> Max temperature (K)</label>
<input type="text" id="node-input-temperaturemax" style="width:100px">
</div>
<div class="form-row" id="light-on">
<label for="node-input-onvalue" style="padding-left:25px; margin-right:-25px">On Payload</label>
<input type="text" id="node-input-onvalue" style="width:70%">
<input type="hidden" id="node-input-onvalueType">
</div>
<div class="form-row" id="light-off">
<label for="node-input-offvalue" style="padding-left:25px; margin-right:-25px">Off Payload</label>
<input type="text" id="node-input-offvalue" style="width:70%">
<input type="hidden" id="node-input-offvalueType">
</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-light">
<p>
<a href="https://github.com/andrei-tatar/node-red-contrib-smartnora/blob/master/doc/nodes/light/README.md">https://github.com/andrei-tatar/node-red-contrib-smartnora/blob/master/doc/nodes/light/README.md</a>
</p>
</script>