Node-RED Calculate Node
node-red-contrib-calculate is a Node-RED contribution package providing nodes for performing simple calculations like average, maximum, minimum, and median over a specified time period or message count. It is currently at version 0.1.4. The package appears to have an infrequent release cadence, with the last update more than six years ago, suggesting it is no longer actively maintained. Its key differentiator lies in its straightforward configuration within the Node-RED visual editor for basic aggregate computations, contrasting with more general-purpose `function` nodes or other calculation-oriented nodes that might offer broader mathematical operations but require more complex setup.
Common errors
-
Error: Cannot find module 'node-red-contrib-calculate'
cause The package was not correctly installed into the Node-RED user directory, or Node-RED was not restarted after installation.fixRun `npm install node-red-contrib-calculate` in your Node-RED user directory (typically `~/.node-red`) and then restart Node-RED. Verify the node appears in the palette. -
Node-RED palette does not show the 'calculate' node after installation.
cause Node-RED may not have picked up the new node, possibly due to an incomplete installation, caching issues, or a conflicting package.fixEnsure Node-RED is completely restarted after installation. Check the Node-RED console logs for any errors during startup. You can also try clearing the Node-RED cache or reinstalling the package.
Warnings
- breaking This package (v0.1.4) has not been updated in over six years and may not be compatible with newer versions of Node.js or Node-RED, potentially causing runtime errors or unexpected behavior.
- gotcha Being unmaintained, this package may contain outdated dependencies with known security vulnerabilities (CVEs). Deploying it in production environments without thorough security auditing is not recommended.
- gotcha The `timeout` and `rate` configurations require careful tuning. If messages arrive too quickly or slowly relative to the configured time period or message count, the node might not output results as expected, or could accumulate excessive memory if not released.
- deprecated The package's low version number (0.1.4) and lack of updates for an extended period indicate it's effectively abandoned. While it might still function for basic tasks, it's not receiving new features, bug fixes, or performance improvements.
Install
-
npm install node-red-contrib-calculate -
yarn add node-red-contrib-calculate -
pnpm add node-red-contrib-calculate
Imports
- Calculate Node
import { Calculate } from 'node-red-contrib-calculate'; // Incorrect: This is a Node-RED palette node, not a programmatic library. const calculateNode = require('node-red-contrib-calculate'); // Incorrect: Not directly consumable via CommonJS require.Install via Node-RED Palette Manager: Search for 'node-red-contrib-calculate' and click install. Alternatively, run `npm install node-red-contrib-calculate` in your Node-RED user directory.
Quickstart
[{"id":"4c3a1551.6c254c","type":"random","z":"aff2cc18.0b484","name":"RandomNumber","low":"1","high":"100","inte":"true","property":"payload","x":340,"y":300,"wires":[["6f127280.30cf3c","6867669e.2a13a8","ac90cf81.6e61b","6dd3b70c.dfd938","596e1e94.3205b"]]},{"id":"6f127280.30cf3c","type":"calculate","z":"aff2cc18.0b484","name":"AvgEveryMinute","pauseType":"timed","calculation":"average","timeout":"1","timeoutUnits":"minutes","rate":"10","x":600,"y":180,"wires":[["4fb1838b.89fb2c"]]},{"id":"b32574cf.036708","type":"inject","z":"aff2cc18.0b484","name":"10SecBump","topic":"","payload":"","payloadType":"date","repeat":"10","crontab":"","once":true,"onceDelay":0.1,"x":140,"y":300,"wires":[["4c3a1551.6c254c"]]},{"id":"6867669e.2a13a8","type":"calculate","z":"aff2cc18.0b484","name":"AvgEvery10Msg","pauseType":"rate","calculation":"average","timeout":"10","timeoutUnits":"seconds","rate":"10","x":600,"y":240,"wires":[["4fb1838b.89fb2c"]]},{"id":"ac90cf81.6e61b","type":"calculate","z":"aff2cc18.0b484","name":"MedEveryMinute","pauseType":"timed","calculation":"median","timeout":"1","timeoutUnits":"minutes","rate":"10","x":610,"y":320,"wires":[["4fb1838b.89fb2c"]]},{"id":"6dd3b70c.dfd938","type":"calculate","z":"aff2cc18.0b484","name":"MinEveryMinute","pauseType":"timed","calculation":"min","timeout":"1","timeoutUnits":"minutes","rate":"10","x":600,"y":380,"wires":[["4fb1838b.89fb2c"]]},{"id":"596e1e94.3205b","type":"calculate","z":"aff2cc18.0b484","name":"MaxEveryMinute","pauseType":"timed","calculation":"max","timeout":"1","timeoutUnits":"minutes","rate":"10","x":610,"y":440,"wires":[["4fb1838b.89fb2c"]]},{"id":"4fb1838b.89fb2c","type":"debug","z":"aff2cc18.0b484","name":"Debug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":870,"y":300,"wires":[]}]