UNPKG

node-red-contrib-boolean-logic-ultimate

Version:

A set of Node-RED enhanced boolean logic and utility nodes, flow interruption, blinker, invert, filter, toggle etc.., with persistent values after reboot. Compatible also with Homeassistant values.

101 lines (88 loc) 5.73 kB
<script type="text/javascript"> RED.nodes.registerType('SumUltimate', { category: 'Boolean Logic Ultimate', color: '#ff8080', defaults: { name: { value: "Math" }, property: { value: "payload" }, math: { value: "sum" }, subtractstartfrom: { value: "" } }, inputs: 1, outputs: 1, icon: "font-awesome/fa-plus", label: function () { return this.name || "Math"; }, paletteLabel: function () { return "Math"; }, oneditprepare: function () { if ($("#node-input-property").val() === "") $("#node-input-property").val("payload"); $("#node-input-property").typedInput({ default: 'msg', types: ['msg'] }); $("#node-input-math").on('change', function () { if ($("#node-input-math").val() === "subtract") { $("#divSubtractFirst").show() } else { $("#divSubtractFirst").hide() } }) } }); </script> <script type="text/html" data-template-name="SumUltimate"> <div class="form-row"> <b>Math Ultimate</b>&nbsp&nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-question-circle"></i>&nbsp<a target="_blank" href="https://github.com/Supergiovane/node-red-contrib-boolean-logic-ultimate"><u>Help online</u></a></span> &nbsp&nbsp&nbsp<span style="color:red"><i class="fa fa-youtube-play"></i>&nbsp<a target="_blank" href="https://youtu.be/jLIbQgmRzuc"><u>Youtube Sample</u></a></span> <br/> <br/> </div> <div class="form-row"> <label for="node-input-name"><i class="icon-tag"></i> Topic</label> <input type="text" id="node-input-name" placeholder="Topic"> </div> <div class="form-row"> <label for="node-input-property"><i class="icon-tag"></i> Input</label> <input type="text" id="node-input-property" placeholder="payload"> </div> <div class="form-row"> <label for="node-input-math"><i class="icon-tag"></i> Operation</label> <select type="text" id="node-input-math" placeholder=""> <option value="sum">Sum</option> <option value="multiply">Multiply</option> <option value="subtract">Subtract</option> </select> </div> <div class="form-row" id="divSubtractFirst" hidden> <label for="node-input-subtractstartfrom"><i class="icon-tag"></i> Subtract from</label> <input type="text" id="node-input-subtractstartfrom" placeholder="See the help."> </div> </script> <script type="text/markdown" data-help-name="SumUltimate"> <p>The pourpose of this node is to do maths on the incoming values. Each incoming message MUST HAVE OWN TOPIC, that means, each inbound **msg.topic** must be **different**.</p> |Property|Description| |--|--| | Input | It's the msg property to be evaluated. *By default, it is *payload*, but you can also specify other properties, for example "payload.value"* | | Operation | Operation to be performed. | | Subtract from | Only visible when the *operation* is **subtract**. It's the *msg.topic value* of the message containing the payload from wich the node starts subtracting. For example, if the incoming msg has ***msg.topic = 'startNumber'***, you must write only **startNumber** in the *Subtract from* field. | <br/> ### Inputs : reset (any) : by passing msg.reset, the node will reset all values and sarts from scratch. : topic (string) : the topic identifying the incoming message. Each incoming msg, must have a different topic. : payload (number) : the payload containing the number. If you've changed the incoming evaluation property in the ***Input*** field, the number to be evaluated must be put in such message's property, instead of the *payload* property. ### Example of "subtract" Copy this code and paste it in to your flow. ```json [{"id":"430cc033ed140940","type":"inject","z":"1050ddfb1ce105e8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"a","payload":"20","payloadType":"num","x":110,"y":140,"wires":[["97d95d92ddf4bf08"]]},{"id":"514067713f250a42","type":"inject","z":"1050ddfb1ce105e8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"startNumber","payload":"100","payloadType":"num","x":140,"y":100,"wires":[["97d95d92ddf4bf08"]]},{"id":"97d95d92ddf4bf08","type":"SumUltimate","z":"1050ddfb1ce105e8","name":"Subtract","property":"payload","math":"subtract","subtractstartfrom":"startNumber","x":320,"y":140,"wires":[["c55f332fe2dadc53"]]},{"id":"c55f332fe2dadc53","type":"debug","z":"1050ddfb1ce105e8","name":"Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":470,"y":140,"wires":[]},{"id":"fe0ac0d4cd660a65","type":"inject","z":"1050ddfb1ce105e8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"b","payload":"10","payloadType":"num","x":110,"y":180,"wires":[["97d95d92ddf4bf08"]]},{"id":"3de15e77a932a0eb","type":"inject","z":"1050ddfb1ce105e8","name":"Reset","props":[{"p":"reset","v":"true","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":220,"wires":[["97d95d92ddf4bf08"]]}] ``` <br/> [SEE THE README FOR FULL HELP AND SAMPLES](https://github.com/Supergiovane/node-red-contrib-boolean-logic-ultimate) [Find it useful?](https://www.paypal.me/techtoday) </script>