node-red-contrib-mytimeout
Version:
A timer that supports setting the run time by passing JSON to the input
187 lines (156 loc) • 7.06 kB
HTML
<!--
This software puts out one of several messages on change of state
which could be sent to the MQTT node and can be triggered by
the INJECT module, an mqtt topic or a button on the UI.
Based on Peter Scargill's work on BigTimer
Copyright 2018 Neil Cherry (ncherry@linuxha.com - https://linuxha.com)
Peter Scargill's (https://tech.scargill.net)
-->
<script type="text/x-red" data-template-name="mytimeout">
<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">
<label for="node-input-outtopic"><i class="fa fa-tag"></i> Output Topic</label>
<input style="width:70%" type="text" id="node-input-outtopic" placeholder="topic">
</div>
<div class="form-row">
<label for="node-input-outsafe"><i class="fa fa-tag"></i> Timer On payload</label>
<input style="width:70%" type="text" id="node-input-outsafe" placeholder="safe">
</div>
<div class="form-row">
<label for="node-input-outwarning"><i class="fa fa-tag"></i> Warning state payload</label>
<input style="width:70%" type="text" id="node-input-outwarning" placeholder="">
</div>
<div class="form-row">
<label for="node-input-outunsafe"><i class="fa fa-tag"></i> Timer Off payload</label>
<input style="width:70%" type="text" id="node-input-outunsafe" placeholder="unsafe">
</div>
<div class="form-row">
<label for="node-input-timer"><i class="fa fa-clock-o"></i> Countdown (secs)</label>
<input style="width:15%" type="text" id="node-input-timer" placeholder="30">
</div>
<div class="form-row">
<label for="node-input-warning"><i class="fa fa-clock-o"></i> Warning (secs)</label>
<input style="width:15%" type="text" id="node-input-warning" placeholder="10">
</div>
<div class="form-row">
<span style="width: 350px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-ndebug" placeholder="debug" > Debug logging</span>
<br/><br/>
<span style="width: 350px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-ignoreCase" placeholder="ignoreCase" > Ignore input case</span>
</div>
<!--
<div class="form-row">
<label for="node-input-debug"><i class="fa fa-clock-o"></i> Debug loggin</label>
<input style="width:15%" type="text" id="node-input-debug" placeholder="0">
</div>
<!--
<div>
<span style="width: 350px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-repeat" placeholder="repeat" > Repeat message every second</span>
<br/><br/>
</div>
<div>
<span style="width: 350px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-again" placeholder="again" > Auto-restart when timed out</span>
<br/><br/>
</div>
<div>
<span style="width: 350px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-atStart" placeholder="atStart" > Run at start</span>
<br/><br/>
</div>
-->
</script>
<script type="text/x-red" data-help-name="mytimeout">
<h3>myTimeout</h3>
<p> A simple timeout node, "on" starts the timer and sends out the
"Timer on payload" (on) message. Every additional "on" will
send an additional "Timer on payload" message on output 1. If
the counter counts down to the warning level it outputs the
WARNING message. If the timer is allowed to count down to 0 -
the UNSAFE (off) message is sent out.</p>
<p> An empty WARNING message in the node's properties will allow
you to skip sending the warning message. As will setting the
warning seconds to 0.</p>
<h3>Acceptable input</h3>
<p> The normal input msg.payload can contain an "on" or "1" for
the Timer On payload, For the Timer Off payload an "off" or
"0", a payload of "stop" will stop the time and output a
"stop" message, a payload of "cancel" will cancel the timer
with no additional messages on output 1. </p>
<ul>
<li>on or 1 (case insensitive)</li>
<li>off or 0</li>
<li>stop</li>
<li>cancel</li>
<li>Any junk will be considered an on condition (a kicker if you will)</li>
<li>JSON in the msg.payload (see below)</li>
</ul>
<p> <b>Please note:</b> The countdown and warning values must be
whole, integer numbers. Using floating point numbers can cause
the timer to not send the appropriate off state payload.</p>
<h3>JSON input</h3>
<p> You can override the user's default settings by send a JSON
packet with a payload, timeout and warning (in seconds).</p>
<pre><code>{
"payload": "on",
"timeout": 600,
"warning": 30
}
or
{
"payload": "off"
}
or
{
"payload": "stop"
}
or
{
"payload": "cancel"
}</code></pre>
<p> <b>Please note:</b> The timeout and warning values must be
whole, integer numbers. Using floating point numbers can cause
the timer to not send the appropriate off state payload.</p>
<ul>
<li>on - turns on the timer and runs for timeout and warns at warning (all 3 fields are required) and sends an on as the msg.payload</li>
<li>1 - turns on the timer and runs for timeout and warns at warning (all 3 fields are required) and sends an on as the msg.payload</li>
<li>off - immediately turns off the timer and sends an off as the msg.payload</li>
<li>0 - immediately turns off the timer and sends an off as the msg.payload</li>
<li>stop - immediately turns off the timer and sends an stop as the msg.payload (which is not an off)</li>
<li>cancel - immediately turns off the timer and sends nothing</li>
<li>JSON payload - (see above)</li>
<li>anything else - is treated as an on command allowing us to tickle or kick the timer (keep it on)</li>
</ul>
</script>
<script type="text/javascript">
RED.nodes.registerType('mytimeout',{
category: 'cherry',
color:"#ff66cc",
inputLabels: "Any old input resets the timer",
outputLabels: "Output message depends on state",
defaults: {
name: { value: "" },
outtopic: { value: "" },
outsafe: { value: "" },
outwarning: { value: "Warning" },
outunsafe: { value: "off", required: true },
warning: { value: "5" },
timer: { value: "30" },
debug: { value: false },
ndebug: { value: false },
ignoreCase: { value: false },
repeat: { value: false },
again: { value: false }
},
inputs: 1,
outputs: 2,
icon: "stopwatch.png",
label: function() {
return this.name||"mytimeout";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {}
});
</script>