UNPKG

node-red-contrib-majordomus

Version:

Smart Home nodes not only for Majordomus platform.

220 lines (201 loc) 10.2 kB
<script type="text/javascript"> RED.nodes.registerType('light', { category: 'majordomus', color: '#FFCC66', defaults: { name: { value: '', required: true }, typeLight: { value: 'onoff', required: true }, rampTime: { value: 1000 }, colorTemperature: { value: 2700 }, // Default for CCT Light autoOnMotion: { value: 'false' }, // Auto turn on with motion autoOnNight: { value: 'false' }, // Auto turn on only at night nightThreshold: { value: 10 }, // Threshold in lux for night detection autoOffNoMotion: { value: 'false' }, // Auto turn off when no motion detected offDelay: { value: 5 } // Delay in minutes before turning off }, inputs: 1, outputs: 2, outputLabels: function() { switch (this.typeLight) { case "dimmable": return ["Light State", "Intensity"]; case "cct": return ["Light State", "Intensity", "Color Temperature"]; case "rgb": return ["Color"]; default: return ["Light State"]; } }, icon: "font-awesome/fa-lightbulb-o", label: function () { return this.name || "light"; }, oneditprepare: function () { let node = this; $("#node-input-name").val(node.name); $("#node-input-type").val(node.typeLight); $("#node-input-rampTime").val(node.rampTime); $("#node-input-colorTemperature").val(node.colorTemperature); $("#node-input-autoOnMotion").typedInput({ default: "bool", types: ["bool", "flow", "global", "msg"] }).typedInput("value", node.autoOnMotion); $("#node-input-autoOnNight").val(node.autoOnNight); $("#node-input-nightThreshold").val(node.nightThreshold); $("#node-input-autoOffNoMotion").val(node.autoOffNoMotion); $("#node-input-offDelay").val(node.offDelay); function toggleFields() { $("#node-input-nightThreshold").toggle($("#node-input-autoOnNight").val() === "true"); $("#node-input-offDelay").toggle($("#node-input-autoOffNoMotion").val() === "true"); $(".rampTime-row").toggle($("#node-input-type").val() === "dimmable" || $("#node-input-type").val() === "cct"); } function updateOutputs() { var selectedType = $("#node-input-type").val(); if (selectedType === "dimmable") { //node.outputs = 2; node.outputLabels = ["Light State", "Intensity"]; } else if (selectedType === "cct") { //node.outputs = 3; node.outputLabels = ["Light State", "Intensity", "Color Temperature"]; } else if (selectedType === "rgb") { //node.outputs = 1; node.outputLabels = ["Color"]; } else { //node.outputs = 1; node.outputLabels = ["Light State"]; } $("#node-input-outputs").val(node.outputs); } $("#node-input-autoOnNight").on("change", toggleFields); $("#node-input-autoOffNoMotion").on("change", toggleFields); $("#node-input-type").on("change", function() { toggleFields(); updateOutputs(); }); toggleFields(); updateOutputs(); }, oneditsave: function () { this.name = $("#node-input-name").val(); this.typeLight = $("#node-input-type").val(); this.rampTime = parseInt($("#node-input-rampTime").val(), 10) || 0; this.colorTemperature = parseInt($("#node-input-colorTemperature").val(), 10) || 2700; this.autoOnMotion = $("#node-input-autoOnMotion").val(); this.autoOnNight = $("#node-input-autoOnNight").val(); this.nightThreshold = parseInt($("#node-input-nightThreshold").val(), 10) || 10; this.autoOffNoMotion = $("#node-input-autoOffNoMotion").val(); this.offDelay = parseInt($("#node-input-offDelay").val(), 10) || 5; // Ensure outputs update when saving if (this.typeLight === "dimmable" || this.typeLight === "cct") { this.outputs = this.typeLight === "dimmable" ? 2 : 3; this.outputLabels = this.typeLight === "dimmable" ? ["Light State", "Intensity"] : ["Light State", "Intensity", "Color Temperature"]; } else if (this.typeLight === "rgb") { this.outputs = 1; this.outputLabels = ["Color"]; } else { this.outputs = 1; this.outputLabels = ["Light State"]; } } }); </script> <script type="text/html" data-template-name="light"> <div class="form-row"> <label for="node-input-name"> <i class="fa fa-tag"></i> Name </label> <input type="text" id="node-input-name" placeholder="Enter node name"> </div> <div class="form-row"> <label for="node-input-type"> <i class="fa fa-lightbulb-o"></i> Type </label> <select id="node-input-type" style="width:70%"> <option value="onoff">Light ON/OFF</option> <option value="dimmable">Dimmable light</option> <!-- <option value="cct">CCT Light</option> --> <!-- <option value="rgb">RGB Light</option> --> </select> </div> <div class="form-row rampTime-row" style="display: none;"> <label for="node-input-rampTime"> <i class="fa fa-clock-o"></i> Ramp Time (ms) </label> <input type="number" id="node-input-rampTime" min="0" placeholder="Enter ramp time"> </div> <div class="form-row"> <label for="node-input-autoOnMotion"> <i class="fa fa-user"></i> Auto On with Motion </label> <input type="text" id="node-input-autoOnMotion" style="width: 70%" > </div> <div class="form-row"> <label for="node-input-autoOnNight"> <i class="fa fa-moon-o"></i>Auto On Only at Night (lux threshold)</label> <select id="node-input-autoOnNight" style="width: 35%" > <option value="true">True</option> <option value="false">False</option> </select> <input type="number" id="node-input-nightThreshold" min="0" placeholder="Night Threshold (lux)" style="margin-left: 2%; width: 33%"> </div> <div class="form-row"> <label for="node-input-autoOffNoMotion"> <i class="fa fa-clock-o"></i>Auto Off Without Motion (sec) </label> <select id="node-input-autoOffNoMotion" style="width: 35%"> <option value="true">True</option> <option value="false">False</option> </select> <input type="number" id="node-input-offDelay" min="1" placeholder="Off Delay (s)" style="margin-left: 2%; width: 33%"> </div> </script> <script type="text/html" data-help-name="light"> <div class="form-row"> <label>Light Node Help</label> <p>The Light node allows control your light with buttons, presense senor and luxmeter. The node supports ON/OFF or dimmable light.</p> <h3>Features:</h3> <ul> <li>Control with buttons (toggle output)</li> <li>Automatic turn on the light on motion</li> <li>Automatic on only in night based on luxmeter</li> <li> Automatic turn off the light after no presense timeout</li> <li>Fade in and fade out for dimmable lights</li> </ul> <h3>Configuration Options:</h3> <dl> <dt><b>Name</b></dt> <dd>Specify a unique name for the node.</dd> <dt><b>Type</b></dt> <dd>Select type of the light:</dd> <ul> <li><b>Light ON / OFF:</b> The light supports to be ON or OFF.</li> <li><b>Dimmable:</b> The light supports to be ON or OFF and it can adjust the intensity 0 - 100%.</li> </ul> <dt><b>Ramp time</b></dt> <dd>Ramp time in miliseconds for fade in adn fade out effect.</dd> <dt><b>Auto On with Motion </b></dt> <dd>Enable automatic on in presense.</dd> <dt><b>Auto On Only at Night (lux threshold) </b></dt> <dd>Enable automatic on only if lux are less than threshold (in the night).</dd> <dt><b>Auto Off Without Motion (sec) </b></dt> <dd>Enable automatic off when there is no presense (timeout in seonds).</dd> </dl> <h3>Inputs:</h3> <ul> <li><b>button:</b> Event of the button - payload must be 1.</li> <li><b>setIntensity:</b> Actual requested insenity, when light is on.</li> <li><b>presense:</b> Presense in the room. Payload in range 0 - 1.</li> <li><b>lightIntensity:</b> Light intensity in the room in Luxes.</li> </ul> <h3>Outputs:</h3> <ul> <li><b>state:</b> The output is for power control of the light - 0 or 1</li> <li><b>intensity:</b> The output is for power control of the intensity - 0 - 100 %</li> </ul> <h3>Status Indicators:</h3> <ul> <li><b>Green dot:</b> Indicates that light is on. Date of last changed of the state.</li> <li><b>Gray dot:</b> Indicates that light is off.</li> </ul> <h3>More Information:</h3> <p>Visit the <a href="https://github.com/jirihusak/majordomus" target="_blank">project's GitHub repository</a> for more details and updates.</p> </div> </script>