@mschaeffler/node-red-logic 3.7.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/logic_timerelay.html +148 -0
- package/logic_timerelay.js +174 -0
- package/package.json +2 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('timerelay',{
|
|
3
|
+
category: 'logic',
|
|
4
|
+
color: "#C0DEED",
|
|
5
|
+
defaults: {
|
|
6
|
+
name:{value:""},
|
|
7
|
+
property:{value:"payload",required:true},
|
|
8
|
+
delay:{value:"0",required:true},
|
|
9
|
+
minOn:{value:"0",required:true},
|
|
10
|
+
maxOn:{value:"0",required:true},
|
|
11
|
+
postrun:{value:"0",required:true},
|
|
12
|
+
outputOn:{value:true,required:true},
|
|
13
|
+
outputOnType:{value:"bool"},
|
|
14
|
+
outputOff:{value:false,required:true},
|
|
15
|
+
outputOffType:{value:"bool"},
|
|
16
|
+
showState:{value:false}
|
|
17
|
+
},
|
|
18
|
+
inputs:1,
|
|
19
|
+
outputs:1,
|
|
20
|
+
icon: "font-awesome/fa-clock-o",
|
|
21
|
+
label: function() {
|
|
22
|
+
return this.name||"timerelay";
|
|
23
|
+
},
|
|
24
|
+
labelStyle: function() {
|
|
25
|
+
return this.name?"node_label_italic":"";
|
|
26
|
+
},
|
|
27
|
+
paletteLabel: "timerelay",
|
|
28
|
+
inputLabels: 'input',
|
|
29
|
+
outputLabels: 'boolean',
|
|
30
|
+
oneditprepare: function() {
|
|
31
|
+
$("#node-input-property").typedInput({
|
|
32
|
+
type:"msg",
|
|
33
|
+
types:["msg"],
|
|
34
|
+
typeField: "#node-input-property-type"
|
|
35
|
+
})
|
|
36
|
+
$("#node-input-outputOn").typedInput({
|
|
37
|
+
type:"bool",
|
|
38
|
+
types:["str","num","bool","json"],
|
|
39
|
+
typeField: "#node-input-outputOnType"
|
|
40
|
+
})
|
|
41
|
+
$("#node-input-outputOff").typedInput({
|
|
42
|
+
type:"bool",
|
|
43
|
+
types:["str","num","bool","json"],
|
|
44
|
+
typeField: "#node-input-outputOffType"
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<script type="text/html" data-template-name="timerelay">
|
|
51
|
+
<div class="form-row">
|
|
52
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
53
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
54
|
+
</div>
|
|
55
|
+
<div class="form-row">
|
|
56
|
+
<label for="node-input-property"><i class="fa fa-ellipsis-h"></i> Eigenschaft</label>
|
|
57
|
+
<input type="text" id="node-input-property">
|
|
58
|
+
<input type="hidden" id="node-input-property-type">
|
|
59
|
+
</div>
|
|
60
|
+
<div class="form-row">
|
|
61
|
+
<label for="node-input-delay"><i class="fa fa-play"></i> Delay</label>
|
|
62
|
+
<input type="text" id="node-input-delay">
|
|
63
|
+
</div>
|
|
64
|
+
<div class="form-row">
|
|
65
|
+
<label for="node-input-postrun"><i class="fa fa-stop"></i> Postrun</label>
|
|
66
|
+
<input type="text" id="node-input-postrun">
|
|
67
|
+
</div>
|
|
68
|
+
<div class="form-row">
|
|
69
|
+
<label for="node-input-minOn"><i class="fa fa-hourglass-start"></i> min on time</label>
|
|
70
|
+
<input type="text" id="node-input-minOn">
|
|
71
|
+
</div>
|
|
72
|
+
<div class="form-row">
|
|
73
|
+
<label for="node-input-maxOn"><i class="fa fa-hourglass-end"></i> max on time</label>
|
|
74
|
+
<input type="text" id="node-input-maxOn">
|
|
75
|
+
</div>
|
|
76
|
+
<div class="form-row">
|
|
77
|
+
<label for="node-input-outputOn"><i class="fa fa-sign-out"></i> on Output</label>
|
|
78
|
+
<input type="text" id="node-input-outputOn">
|
|
79
|
+
<input type="hidden" id="node-input-outputOnType">
|
|
80
|
+
</div>
|
|
81
|
+
<div class="form-row">
|
|
82
|
+
<label for="node-input-outputOff"><i class="fa fa-sign-out"></i> off Output</label>
|
|
83
|
+
<input type="text" id="node-input-outputOff">
|
|
84
|
+
<input type="hidden" id="node-input-outputOffType">
|
|
85
|
+
</div>
|
|
86
|
+
<div class="form-row">
|
|
87
|
+
<label for="node-input-howStatus"><i class="fa fa-star-o"></i> Status</label>
|
|
88
|
+
<input type="checkbox" id="node-input-showState" style="display:inline-block; width:20px; vertical-align:baseline;">
|
|
89
|
+
</div>
|
|
90
|
+
</script>
|
|
91
|
+
|
|
92
|
+
<script type="text/html" data-help-name="timerelay">
|
|
93
|
+
|
|
94
|
+
<p>Sends the payload converted to boolean delayed. The delay time can de controlled for on and off switching individually.</p>
|
|
95
|
+
<p>If the msg property <code>invalid</code> is present in the message, all nodes ignore the message.</p>
|
|
96
|
+
|
|
97
|
+
<table>
|
|
98
|
+
<tr> <th>type</th> <th>input</th> <th>output</th> </tr>
|
|
99
|
+
<tr> <td>boolean</td> <td>false</td> <td>false</td> </tr>
|
|
100
|
+
<tr> <td></td> <td>true</td> <td>true</td> </tr>
|
|
101
|
+
<tr> <td>number</td> <td>0</td> <td>false</td> </tr>
|
|
102
|
+
<tr> <td></td> <td>1</td> <td>true</td> </tr>
|
|
103
|
+
<tr> <td>string</td> <td>false</td> <td>false</td> </tr>
|
|
104
|
+
<tr> <td></td> <td>true</td> <td>true</td> </tr>
|
|
105
|
+
<tr> <td></td> <td>0</td> <td>false</td> </tr>
|
|
106
|
+
<tr> <td></td> <td>1</td> <td>true</td> </tr>
|
|
107
|
+
<tr> <td></td> <td>off</td> <td>false</td> </tr>
|
|
108
|
+
<tr> <td></td> <td>on</td> <td>true</td> </tr>
|
|
109
|
+
</table>
|
|
110
|
+
|
|
111
|
+
<h3>Input</h3>
|
|
112
|
+
|
|
113
|
+
<p>The message property to be used as payload can be defined with the <code>Property</code> property.</p>
|
|
114
|
+
|
|
115
|
+
<dl class="message-properties">
|
|
116
|
+
<dt>payload <span class="property-type"></span></dt>
|
|
117
|
+
<dd> input value.</dd>
|
|
118
|
+
</dl>
|
|
119
|
+
|
|
120
|
+
<h3>Output</h3>
|
|
121
|
+
|
|
122
|
+
<dl class="message-properties">
|
|
123
|
+
<dt>payload <span class="property-type">boolean</span></dt>
|
|
124
|
+
<dd> bool value of payload.</dd>
|
|
125
|
+
</dl>
|
|
126
|
+
|
|
127
|
+
<h3>Parameter</h3>
|
|
128
|
+
|
|
129
|
+
<dl class="message-properties">
|
|
130
|
+
<dt>Property <span class="property-type">string</span></dt>
|
|
131
|
+
<dd> defines the message property to be used as payload.</dd>
|
|
132
|
+
<dt>Delay <span class="property-type">number</span></dt>
|
|
133
|
+
<dd> delay time in msec for switching from on to off.</dd>
|
|
134
|
+
<dt>Postrun <span class="property-type">number</span></dt>
|
|
135
|
+
<dd> delay time in msec for switching from off to on.</dd>
|
|
136
|
+
<dt>min on time <span class="property-type">number</span></dt>
|
|
137
|
+
<dd> minimal time in msec to be in on state.</dd>
|
|
138
|
+
<dt>max on time <span class="property-type">number</span></dt>
|
|
139
|
+
<dd> maximal time in msec to be in on state; 0 is infinite.</dd>
|
|
140
|
+
<dt>on Output <span class="property-type">multi</span></dt>
|
|
141
|
+
<dd> Value to be sent in on case.</dd>
|
|
142
|
+
<dt>off Output <span class="property-type">multi</span></dt>
|
|
143
|
+
<dd> Value to be sent in off case.</dd>
|
|
144
|
+
<dt>Status <span class="property-type">boolean</span></dt>
|
|
145
|
+
<dd> shows the actual value as a node status.</dd>
|
|
146
|
+
</dl>
|
|
147
|
+
|
|
148
|
+
</script>
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
module.exports = function(RED) {
|
|
2
|
+
var tools = require('./tools.js');
|
|
3
|
+
|
|
4
|
+
function TimeRelayNode(config) {
|
|
5
|
+
RED.nodes.createNode(this,config);
|
|
6
|
+
//this.config = config;
|
|
7
|
+
var node = this;
|
|
8
|
+
this.property = config.property || "payload";
|
|
9
|
+
this.delay = Number( config.delay ?? 0 );
|
|
10
|
+
this.postrun = Number( config.postrun ?? 0 );
|
|
11
|
+
this.minOn = Number( config.minOn ?? 0 );
|
|
12
|
+
this.maxOn = Number( config.maxOn ?? 0 );
|
|
13
|
+
this.outputOn = tools.convertTypedInput( config.outputOn ?? "true", config.outputOnType ?? "bool" );
|
|
14
|
+
this.outputOff = tools.convertTypedInput( config.outputOff ?? "false",config.outputOffType ?? "bool" );
|
|
15
|
+
this.showState = Boolean( config.showState );
|
|
16
|
+
this.state = null;
|
|
17
|
+
this.last = null;
|
|
18
|
+
this.msg = null;
|
|
19
|
+
this.timerDelay = null;
|
|
20
|
+
this.timerPostRun = null;
|
|
21
|
+
this.timerMinOn = null;
|
|
22
|
+
this.timerMaxOn = null;
|
|
23
|
+
node.status( "" );
|
|
24
|
+
|
|
25
|
+
function setStatus(color,text)
|
|
26
|
+
{
|
|
27
|
+
console.log( text );
|
|
28
|
+
if( node.showState )
|
|
29
|
+
{
|
|
30
|
+
node.status( { text:text, shape:"dot", fill:color } );
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function doswitch()
|
|
35
|
+
{
|
|
36
|
+
node.msg.payload = node.state ? node.outputOn : node.outputOff;
|
|
37
|
+
node.send( node.msg );
|
|
38
|
+
if( node.state )
|
|
39
|
+
{
|
|
40
|
+
if( node.minOn )
|
|
41
|
+
{
|
|
42
|
+
node.timerMinOn = setTimeout( function() { node.emit("minOn"); }, node.minOn );
|
|
43
|
+
}
|
|
44
|
+
if( node.maxOn )
|
|
45
|
+
{
|
|
46
|
+
node.timerMaxOn = setTimeout( function() { node.emit("maxOn"); }, node.maxOn );
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else
|
|
50
|
+
{
|
|
51
|
+
clearTimeout( node.timerMinOn );
|
|
52
|
+
clearTimeout( node.timerMaxOn );
|
|
53
|
+
node.timerMinOn = null;
|
|
54
|
+
node.timerMaxOn = null;
|
|
55
|
+
node.msg = null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
node.on('input', function(msg,send,done) {
|
|
60
|
+
if( msg.invalid )
|
|
61
|
+
{
|
|
62
|
+
done();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
node.state = tools.property2boolean( RED.util.getMessageProperty( msg, node.property ) );
|
|
66
|
+
if( node.state !== null )
|
|
67
|
+
{
|
|
68
|
+
if( node.state !== node.last )
|
|
69
|
+
{
|
|
70
|
+
node.last = node.state;
|
|
71
|
+
node.msg = msg;
|
|
72
|
+
if( node.state )
|
|
73
|
+
{
|
|
74
|
+
if( node.timerPostrun )
|
|
75
|
+
{
|
|
76
|
+
clearTimeout( node.timerPostrun );
|
|
77
|
+
node.timerPostrun = null;
|
|
78
|
+
doswitch();
|
|
79
|
+
setStatus( "green", "on (change of mind)" );
|
|
80
|
+
}
|
|
81
|
+
else
|
|
82
|
+
{
|
|
83
|
+
if( node.delay > 0 )
|
|
84
|
+
{
|
|
85
|
+
node.timerDelay = setTimeout( function() { node.emit("sendOnMsg"); }, node.delay );
|
|
86
|
+
setStatus( "yellow", "startdelay" );
|
|
87
|
+
}
|
|
88
|
+
else
|
|
89
|
+
{
|
|
90
|
+
doswitch();
|
|
91
|
+
setStatus( "green", "on" );
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else
|
|
96
|
+
{
|
|
97
|
+
if( node.timerDelay )
|
|
98
|
+
{
|
|
99
|
+
clearTimeout( node.timerDelay );
|
|
100
|
+
node.timerDelay = null;
|
|
101
|
+
doswitch();
|
|
102
|
+
setStatus( "gray", "off (change of mind)" );
|
|
103
|
+
}
|
|
104
|
+
else
|
|
105
|
+
{
|
|
106
|
+
if( node.postrun > 0 )
|
|
107
|
+
{
|
|
108
|
+
node.timerPostrun = setTimeout( function() { node.emit("sendOffMsg"); }, node.postrun );
|
|
109
|
+
setStatus( "yellow", "postrun" );
|
|
110
|
+
}
|
|
111
|
+
else if( node.timerMinOn )
|
|
112
|
+
{
|
|
113
|
+
setStatus( "yellow", "minimal on" );
|
|
114
|
+
}
|
|
115
|
+
else
|
|
116
|
+
{
|
|
117
|
+
doswitch();
|
|
118
|
+
setStatus( "gray", "off" );
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else
|
|
124
|
+
{
|
|
125
|
+
setStatus( node.state ? "green" : "gray", "filter" );
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else
|
|
129
|
+
{
|
|
130
|
+
console.log("error")
|
|
131
|
+
setStatus( "red", "error" );
|
|
132
|
+
}
|
|
133
|
+
done();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
node.on('sendOnMsg', function() {
|
|
137
|
+
node.timerDelay = null;
|
|
138
|
+
doswitch();
|
|
139
|
+
setStatus( "green", "on" );
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
node.on('sendOffMsg', function() {
|
|
143
|
+
node.timerPostrun = null;
|
|
144
|
+
doswitch();
|
|
145
|
+
setStatus( "gray", "off" );
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
node.on('minOn', function() {
|
|
149
|
+
node.timerMinOn = null;
|
|
150
|
+
if( ! node.state )
|
|
151
|
+
{
|
|
152
|
+
doswitch();
|
|
153
|
+
setStatus( "gray", "off (min time)" );
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
node.on('maxOn', function() {
|
|
158
|
+
node.timerMaxOn = null;
|
|
159
|
+
node.last = false;
|
|
160
|
+
node.state = false;
|
|
161
|
+
doswitch();
|
|
162
|
+
setStatus( "gray", "off (max time)" );
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
node.on('close', function() {
|
|
166
|
+
clearTimeout( node.timerDelay );
|
|
167
|
+
clearTimeout( node.timerPostrun );
|
|
168
|
+
clearTimeout( node.timerMinOn );
|
|
169
|
+
clearTimeout( node.timerMaxOn );
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
RED.nodes.registerType("timerelay",TimeRelayNode);
|
|
174
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mschaeffler/node-red-logic",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"description": "nodes for simple operations.",
|
|
5
5
|
"license": "LGPL-2.1",
|
|
6
6
|
"homepage": "https://github.com/m-schaeffler/node-red-my-nodes/tree/main/node-red-logic",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"not": "logic_not.js",
|
|
23
23
|
"or": "logic_or.js",
|
|
24
24
|
"and": "logic_and.js",
|
|
25
|
+
"timerelay": "logic_timerelay.js",
|
|
25
26
|
"tonumber": "math_number.js",
|
|
26
27
|
"negate": "math_minus.js",
|
|
27
28
|
"reduce": "math_reduce.js",
|