How to store adc value and add the next value to it every second to get a 1 minute total for calculation

Here is what I have now

[
    {
        "id": "3ec696660ec8b9b4",
        "type": "ncd-ads1115",
        "z": "f672d0ac69fd5b97",
        "name": "ADC",
        "connection": "f4775f0f8553a862",
        "addr": "72",
        "interval": "1000",
        "outputs": 2,
        "output_all": true,
        "output_mult": "0.000628",
        "channel_1": "4",
        "channel_2": "_none",
        "channel_3": "_none",
        "channel_4": "_none",
        "gain": "2",
        "mode": "2",
        "rate": "0",
        "compMode": 0,
        "compPol": 0,
        "compLat": 0,
        "compQueue": 3,
        "delay": "100",
        "x": 230,
        "y": 100,
        "wires": [
            [
                "bc632c21a3802b42"
            ],
            []
        ]
    },
    {
        "id": "8d1b7ccc55bc9acc",
        "type": "ui_text",
        "z": "f672d0ac69fd5b97",
        "group": "8ee0bb75fa4e2113",
        "order": 3,
        "width": 0,
        "height": 0,
        "name": "",
        "label": "AC Current",
        "format": "{{msg.payload | number : 2}} A",
        "layout": "row-center",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#000000",
        "x": 610,
        "y": 100,
        "wires": []
    },
    {
        "id": "bc632c21a3802b42",
        "type": "function",
        "z": "f672d0ac69fd5b97",
        "name": "function 2",
        "func": "msg.payload = (msg.payload / 1000) - 0.02\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 420,
        "y": 100,
        "wires": [
            [
                "8d1b7ccc55bc9acc",
                "37caa9e1987b0a76"
            ]
        ]
    },
    {
        "id": "519b0ad02b478075",
        "type": "ui_gauge",
        "z": "f672d0ac69fd5b97",
        "name": "",
        "group": "8ee0bb75fa4e2113",
        "order": 4,
        "width": 0,
        "height": 0,
        "gtype": "gage",
        "title": "Kilo Watts",
        "label": "KW",
        "format": "{{value | number : 2}}",
        "min": 0,
        "max": "4",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "0.8",
        "seg2": "2",
        "diff": false,
        "className": "",
        "x": 760,
        "y": 140,
        "wires": []
    },
    {
        "id": "37caa9e1987b0a76",
        "type": "function",
        "z": "f672d0ac69fd5b97",
        "name": "function 3",
        "func": "msg.payload = (msg.payload * 120) / 1000\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 600,
        "y": 140,
        "wires": [
            [
                "519b0ad02b478075"
            ]
        ]
    },
    {
        "id": "ec55e34653b1d418",
        "type": "ui_text",
        "z": "f672d0ac69fd5b97",
        "group": "8ee0bb75fa4e2113",
        "order": 5,
        "width": 0,
        "height": 0,
        "name": "",
        "label": "Total KWH",
        "format": "{{msg.payload}}",
        "layout": "col-center",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#000000",
        "x": 770,
        "y": 180,
        "wires": []
    },
    {
        "id": "c166e46294bf507d",
        "type": "function",
        "z": "f672d0ac69fd5b97",
        "name": "function 4",
        "func": "msg.payload = (msg.payload / 3600000)\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 600,
        "y": 180,
        "wires": [
            [
                "ec55e34653b1d418"
            ]
        ]
    },
    {
        "id": "f4775f0f8553a862",
        "type": "ncd-comm",
        "name": "I2C",
        "bus": "1",
        "busManual": "",
        "commType": "standard",
        "addr": "0",
        "useMux": false,
        "muxAddr": "112",
        "muxPort": "0"
    },
    {
        "id": "8ee0bb75fa4e2113",
        "type": "ui_group",
        "name": "Main",
        "tab": "9d03c9290d696c27",
        "order": 1,
        "disp": false,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "9d03c9290d696c27",
        "type": "ui_tab",
        "name": "Solar Power Stats",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]
[{"id":"534995986643d98a","type":"subflow","name":"Subflow 1","info":"","in":[{"x":60,"y":150,"wires":[{"id":"3df73b97bc514f9f"}]}],"out":[{"x":1230,"y":180,"wires":[{"id":"bc18ccfc66f2aac5","port":0}]}],"status":{"x":1060,"y":270,"wires":[{"id":"48497b55569767d2","port":1}]}},{"id":"3df73b97bc514f9f","type":"change","z":"534995986643d98a","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"increment","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":200,"y":150,"wires":[["6c988157801c9493","1e85b3747c303908"]]},{"id":"6c988157801c9493","type":"function","z":"534995986643d98a","name":"magic","func":"var sum = context.get('sum')||0;\n\nif (msg.topic == \"reset\") {\n    sum = 0;\n    context.set('sum',0);\n}\nelse if (msg.topic== \"increment\") {\n    sum += msg.payload;\n    context.set('sum',sum);\n}\nelse if ( (msg.topic == \"decrement\")) {\n        sum -= msg.payload;\n    context.set('sum',sum);\n}\n\n// make it part of the outgoing msg object\nmsg.sum = sum;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":150,"wires":[["0de722ccd592cea1"]]},{"id":"0de722ccd592cea1","type":"change","z":"534995986643d98a","name":"","rules":[{"t":"delete","p":"topic","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":150,"wires":[["48497b55569767d2"]]},{"id":"687466e7aa375990","type":"change","z":"534995986643d98a","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"reset","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":90,"wires":[["6c988157801c9493"]]},{"id":"48497b55569767d2","type":"Message Counter","z":"534995986643d98a","name":"","units":"minutes","interval":1,"alignToClock":true,"generator":"internal","x":840,"y":150,"wires":[["687466e7aa375990"],["bc18ccfc66f2aac5"]]},{"id":"bc18ccfc66f2aac5","type":"change","z":"534995986643d98a","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"sum","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":190,"wires":[[]]},{"id":"1e85b3747c303908","type":"function","z":"534995986643d98a","name":"magic","func":"var count = context.get('count')||0;\n\nif (msg.topic == \"reset\") {\n    count = 0;\n    context.set('count',0);\n}\nelse if (msg.topic== \"increment\") {\n    count += 1;\n    context.set('count',count);\n}\nelse if ( (msg.topic == \"decrement\")) {\n        count -= 1;\n    context.set('count',count);\n}\n\n// make it part of the outgoing msg object\nmsg.count = count;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":240,"wires":[["b08ce012fabacefc"]]},{"id":"b08ce012fabacefc","type":"change","z":"534995986643d98a","name":"","rules":[{"t":"delete","p":"topic","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":240,"wires":[["55bddad2884c2681"]]},{"id":"55bddad2884c2681","type":"Message Counter","z":"534995986643d98a","name":"","units":"minutes","interval":1,"alignToClock":true,"generator":"internal","x":810,"y":240,"wires":[["987a47e43caf056f"],[]]},{"id":"987a47e43caf056f","type":"change","z":"534995986643d98a","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"reset","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":300,"wires":[["1e85b3747c303908"]]},{"id":"e825566587d62313","type":"subflow:534995986643d98a","z":"7d7792c02548b90b","name":"","x":570,"y":900,"wires":[["c166e46294bf507d"]]},{"id":"c0d1b7e222ec89aa","type":"change","z":"7d7792c02548b90b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$round($random()*payload,0)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":840,"wires":[["bc632c21a3802b42","e825566587d62313"]]},{"id":"c166e46294bf507d","type":"function","z":"7d7792c02548b90b","name":"function 4","func":"msg.payload = (msg.payload / 3600000)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":750,"y":890,"wires":[["ec55e34653b1d418"]]},{"id":"839909b9eb24c5bf","type":"inject","z":"7d7792c02548b90b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"100000","payloadType":"num","x":230,"y":840,"wires":[["c0d1b7e222ec89aa"]]},{"id":"bc632c21a3802b42","type":"function","z":"7d7792c02548b90b","name":"function 2","func":"msg.payload = (msg.payload / 1000) - 0.02\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":570,"y":810,"wires":[["8d1b7ccc55bc9acc","37caa9e1987b0a76"]]},{"id":"ec55e34653b1d418","type":"ui_text","z":"7d7792c02548b90b","group":"8ee0bb75fa4e2113","order":5,"width":0,"height":0,"name":"","label":"Total KWH","format":"{{msg.payload|number:2}}","layout":"col-center","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":920,"y":890,"wires":[]},{"id":"8d1b7ccc55bc9acc","type":"ui_text","z":"7d7792c02548b90b","group":"8ee0bb75fa4e2113","order":3,"width":0,"height":0,"name":"","label":"AC Current","format":"{{msg.payload | number : 2}} A","layout":"row-center","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":760,"y":810,"wires":[]},{"id":"37caa9e1987b0a76","type":"function","z":"7d7792c02548b90b","name":"function 3","func":"msg.payload = (msg.payload * 120) / 1000\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":750,"y":850,"wires":[["519b0ad02b478075"]]},{"id":"519b0ad02b478075","type":"ui_gauge","z":"7d7792c02548b90b","name":"","group":"8ee0bb75fa4e2113","order":4,"width":0,"height":0,"gtype":"gage","title":"Kilo Watts","label":"KW","format":"{{payload | number : 2}}","min":0,"max":"4","colors":["#00b500","#e6e600","#ca3838"],"seg1":"0.8","seg2":"2","diff":false,"className":"","x":910,"y":850,"wires":[]},{"id":"8ee0bb75fa4e2113","type":"ui_group","name":"Main","tab":"9d03c9290d696c27","order":1,"disp":false,"width":"6","collapse":false,"className":""},{"id":"9d03c9290d696c27","type":"ui_tab","name":"Solar Power Stats","icon":"dashboard","disabled":false,"hidden":false}]

I will give this a try, thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.