node-red-contrib-value-for
Version:
A Node-RED node to report if sensor stream values are in given value or range for defined time.
97 lines (94 loc) • 4.26 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('fixed-for', {
category: 'function',
color: '#E6E0F8',
defaults: {
name: {
value: ""
},
casesensitive: {
value: false
},
for: {
value: "5",
required: true,
validate: RED.validators.number()
},
units: {
value: "s",
required: true,
},
continuous: {
value: false
},
ondeploy: {
value: false
},
keepfirstmsg: {
value: false
},
},
inputs: 1,
outputs: 2,
icon: "fixed-for.png",
label: function() {
if (this.name) {
return this.name;
} else {
return 'fixed for ' + this.for + this.units;
}
},
outputLabels: ["matched", "not mached"],
paletteLabel: "fixed for"
});
</script>
<script type="text/x-red" data-template-name="fixed-for">
<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="name">
</div>
<div class="form-row">
<input type="checkbox" id="node-input-casesensitive" style="display: inline-block; width: auto; vertical-align: top;">
<label style="width: auto;" for="node-input-casesensitive">Case sensitive</label></input>
</div>
<div class="form-row node-type-for">
<label for="node-input-for"><i class="fa fa-clock-o"></i> For</label>
<input type="text" id="node-input-for" style="text-align:end; width:70px !important">
<select id="node-input-units" style="width:140px !important">
<option value="ms" data-i18n="value-for.for.ms">Milliseconds</option>
<option value="s" data-i18n="value-for.for.s">Seconds</option>
<option value="min" data-i18n="value-for.for.m">Minutes</option>
<option value="hr" data-i18n="value-for.for.h">Hours</option>
</select>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-continuous" style="display: inline-block; width: auto; vertical-align: top;">
<label style="width: auto;" for="node-input-continuous">Trigger for continuous <code>for</code> periods in value.</label></input>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-ondeploy" style="display: inline-block; width: auto; vertical-align: top;">
<label style="width: auto;" for="node-input-ondeploy">Start timer on node (re)deployment.</label></input>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-keepfirstmsg" style="display: inline-block; width: auto; vertical-align: top;">
<label style="width: auto;" for="node-input-keepfirstmsg">Keep first message.</label></input>
<div class="form-tips">
<span style="font-style: italic;">By default, the latest input message will be forwarded to the output. Select this checkbox to forward the very first message that matched the "value" instead.</span>
</div>
</div>
</script>
<script type="text/x-red" data-help-name="value-for">
<p>This node listens to string values in <code>msg.payload</code> input.
If reported value is unchanged (fixed) for defined amount of time –
reports a <code>msg.payload: "trigger"</code> (just once) on first output.</p>
<p>Node accepts any values but comparison is made between strings.
Comparison can be made in case sensitive manner.</p>
<p>Any change of value will reset the timer – that reports
a <code>msg.payload: "reset"</code> to second output.</p>
<p>Sending <code>msg.payload: "reset"</code> will reset timer,
also triggering second output.</p>
<p>Can trigger for continuous <code>for</code> periods if value doesn't change
or just once.</p>
<p>Normally this node waits for first input message to start a timer.
Optionally timer can be started as soon as on node (re)deployment.</p>
</script>