@strato-automation/node-red-contrib-strato-automation
Version:
Strato Automation Official Node Red Library
164 lines (143 loc) • 6 kB
HTML
<script src="/nodered/utils.js"></script>
<script type="text/javascript">
RED.nodes.registerType('func-on-off', {
category: 'Strato Automation',
color: '#f3b567',
defaults: {
name: { value: "", label: "Name" },
topic: { value: "default", required: true, label: "Topic" },
on_value: { value: null, label: "On Value" },
off_value: { value: null, label: "Off Value" },
initialized: { value: false },
},
inputs: 1,
outputs: 1,
icon: "font-awesome/fa-power-off",
paletteLabel: function () {
return "ON/OFF";
},
label: function () {
var node = this;
return this.name || "ON/OFF";
},
labelStyle: function () {
return this.name ? "node_label_italic" : "";
},
outputLabels: function (index) {
return this.topic;
},
inputLabels: function (index) {
return "Input 1: ON Value\nInput 2: OFF Value";
},
oneditprepare: function () {
$("#node-input-topic").typedInput({
types: [
{
value: "",
options: topics()
}
]
})
}
});
</script>
<script type="text/html" data-template-name="func-on-off">
<!-- Basic Settings -->
<div class="form-tips" style="margin-bottom: 20px;">
<b>Basic Settings</b>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-bookmark"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Optional name for this function">
</div>
<!-- Threshold Settings -->
<div class="form-tips" style="margin: 20px 0;">
<b>Threshold Settings</b>
</div>
<div style="padding-left: 10px; border-left: 3px solid #ddd;">
<div class="form-row">
<label for="node-input-on_value"><i class="fa fa-toggle-on"></i> ON Value</label>
<input type="num" id="node-input-on_value" placeholder="Value to trigger ON state">
</div>
<div class="form-row">
<label for="node-input-off_value"><i class="fa fa-toggle-off"></i> OFF Value</label>
<input type="num" id="node-input-off_value" placeholder="Value to trigger OFF state">
</div>
</div>
<!-- Output Settings -->
<div class="form-tips" style="margin: 20px 0;">
<b>Output Settings</b>
</div>
<div style="padding-left: 10px; border-left: 3px solid #ddd;">
<div class="form-row">
<label for="node-input-topic"><i class="fa fa-tags"></i> Topic</label>
<input type="text" id="node-input-topic">
</div>
</div>
<div class="form-tips" style="margin-top: 20px;">
<p><i class="fa fa-info-circle"></i> Tip: This node implements hysteresis control - the ON and OFF thresholds can prevent rapid switching.</p>
</div>
</script>
<script type="text/html" data-help-name="func-on-off">
<p>A function node that implements ON/OFF control with hysteresis based on an input value and two thresholds.</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>payload <span class="property-type">number</span></dt>
<dd>The input value to compare against thresholds</dd>
<dt>topic <span class="property-type">string</span></dt>
<dd>
<ul>
<li><code>default</code> - Input value to evaluate</li>
<li><code>in1</code> - Dynamically set ON threshold</li>
<li><code>in2</code> - Dynamically set OFF threshold</li>
</ul>
</dd>
</dl>
<h3>Outputs</h3>
<dl class="message-properties">
<dt>payload <span class="property-type">number</span></dt>
<dd>Binary output: 1 (ON) or 0 (OFF)</dd>
<dt>topic <span class="property-type">string</span></dt>
<dd>The configured topic name</dd>
</dl>
<h3>Configuration</h3>
<dl class="message-properties">
<dt>Name <span class="property-type">string</span></dt>
<dd>Optional name to identify the node in the flow</dd>
<dt>ON Value <span class="property-type">number</span></dt>
<dd>The threshold value that triggers the ON state (when increasing)</dd>
<dt>OFF Value <span class="property-type">number</span></dt>
<dd>The threshold value that triggers the OFF state (when decreasing)</dd>
<dt>Topic <span class="property-type">string</span></dt>
<dd>Topic identifier for the output messages</dd>
</dl>
<h3>Status</h3>
<dl class="message-properties">
<dt>Green dot</dt>
<dd>Node is configured and operating (shows current values)</dd>
<dt>Red dot</dt>
<dd>Missing ON or OFF threshold values</dd>
</dl>
<h3>Details</h3>
<p>This node implements hysteresis control with separate ON and OFF thresholds. The output behavior depends on both the current input value and the previous state:</p>
<h4>Operation</h4>
<ul>
<li>When current state is OFF (0):
<ul>
<li>Input must rise above ON value to switch to ON (1)</li>
</ul>
</li>
<li>When current state is ON (1):
<ul>
<li>Input must fall below OFF value to switch to OFF (0)</li>
</ul>
</li>
</ul>
<p>The hysteresis (difference between ON and OFF values) prevents rapid switching when the input value fluctuates around a single threshold.</p>
<h4>Dynamic Configuration</h4>
<p>The ON and OFF thresholds can be dynamically updated by sending messages with topics:</p>
<ul>
<li><code>in1</code> - Updates the ON threshold</li>
<li><code>in2</code> - Updates the OFF threshold</li>
</ul>
</script>