# Dynamic counter

**URL:** <https://discourse.nodered.org/t/dynamic-counter/75487>\
**Category:** General\
**Created:** [20 February 2023 20:03 UTC](https://discourse.nodered.org/t/dynamic-counter/75487 "2023-02-20T20:03:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Flixm](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/flixm/32/17122_2.png) [@Flixm](https://discourse.nodered.org/u/Flixm)\
**Post date:** [20 February 2023 20:03 UTC](https://discourse.nodered.org/t/dynamic-counter/75487/1 "2023-02-20T20:03:01Z")

</div>

Hi there,

I search for a node or a function which counts from 0 - 100 in different speed depends on the distance of the last input value.  
For example the input range is between 0-1500 the output from 0-100. If there's an input about 1000 it should be count really fast up to 1000. Then the next incoming value is 900 it should count slowly downwards. If the next is only 100 then quickly down and so on ...

My first try is a PID controller but the range is not to set, and it's not possible to reset.

Any other ideas?

Thx in advance  
Felix

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [20 February 2023 20:20 UTC](https://discourse.nodered.org/t/dynamic-counter/75487/2 "2023-02-20T20:20:55Z")

</div>

What are you trying to control?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 February 2023 07:39 UTC](https://discourse.nodered.org/t/dynamic-counter/75487/3 "2023-02-21T07:39:24Z")

</div>

Are the input values coming in at a constant rate?

---

<div class="post-metadata">

**Author:** ![Flixm](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/flixm/32/17122_2.png) [@Flixm](https://discourse.nodered.org/u/Flixm)\
**Post date:** [21 February 2023 08:27 UTC](https://discourse.nodered.org/t/dynamic-counter/75487/4 "2023-02-21T08:27:37Z")

</div>

Hi, it's for a heating rod. I'd like to set a Power management which is more dynamic.  
Actually it more a static range for power up and down.

The input signal is in a constant timerate, actually 1msg/s but it's possible to max 1msg/250ms.

```auto
[
    {
        "id": "394b90dd0f76e1eb",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "30",
        "payloadType": "num",
        "x": 710,
        "y": 3680,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    },
    {
        "id": "5cd54232cf19a43d",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "40",
        "payloadType": "num",
        "x": 710,
        "y": 3740,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    },
    {
        "id": "5c80f73f0335850b",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "50",
        "payloadType": "num",
        "x": 710,
        "y": 3800,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    },
    {
        "id": "512e3b7c11aa5c56",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "60",
        "payloadType": "num",
        "x": 710,
        "y": 3860,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    },
    {
        "id": "7273dcbf3e4c3224",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "70",
        "payloadType": "num",
        "x": 710,
        "y": 3920,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    },
    {
        "id": "329694499f1b0d71",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "80",
        "payloadType": "num",
        "x": 710,
        "y": 3980,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    },
    {
        "id": "1261dcc3c2f5fbb9",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "90",
        "payloadType": "num",
        "x": 710,
        "y": 4040,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    },
    {
        "id": "08982fa878da5df7",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "20",
        "payloadType": "num",
        "x": 710,
        "y": 3620,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    },
    {
        "id": "1be571d3c12523f9",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "10",
        "payloadType": "num",
        "x": 710,
        "y": 3560,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    },
    {
        "id": "12858cf00763e2a2",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0",
        "payloadType": "num",
        "x": 710,
        "y": 3500,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    },
    {
        "id": "d14404b6bac28543",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "-10",
        "payloadType": "num",
        "x": 710,
        "y": 3440,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    },
    {
        "id": "74256f09c8dc0619",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "-20",
        "payloadType": "num",
        "x": 710,
        "y": 3380,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    },
    {
        "id": "cf2ff1c36fd7fae9",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "-30",
        "payloadType": "num",
        "x": 710,
        "y": 3320,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    },
    {
        "id": "c1ddd4997a1f7a84",
        "type": "switch",
        "z": "6f607e7be4f8184e",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 930,
        "y": 3600,
        "wires": [
            [
                "f1fa5335c50eb855"
            ]
        ]
    },
    {
        "id": "25b6280d.1ecf6",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "decrement -",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 1870,
        "y": 3640,
        "wires": [
            [
                "8a41c1.6006b64"
            ]
        ]
    },
    {
        "id": "285e0e19.b9680a",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "increment +",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 1870,
        "y": 3560,
        "wires": [
            [
                "ce8d952f.18666"
            ]
        ]
    },
    {
        "id": "fda0a334.bc9588",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "reset",
        "repeat": "",
        "crontab": "",
        "once": false,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 1850,
        "y": 3600,
        "wires": [
            [
                "17cce981.975686"
            ]
        ]
    },
    {
        "id": "ce8d952f.18666",
        "type": "function",
        "z": "6f607e7be4f8184e",
        "name": "msg object",
        "func": "msg.increment = 3;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 2030,
        "y": 3560,
        "wires": [
            [
                "ac65bf94.6e609"
            ]
        ]
    },
    {
        "id": "17cce981.975686",
        "type": "function",
        "z": "6f607e7be4f8184e",
        "name": "msg object",
        "func": "msg.reset = true;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 2030,
        "y": 3600,
        "wires": [
            [
                "ac65bf94.6e609"
            ]
        ]
    },
    {
        "id": "8a41c1.6006b64",
        "type": "function",
        "z": "6f607e7be4f8184e",
        "name": "msg object",
        "func": "msg.decrement = 3;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 2030,
        "y": 3640,
        "wires": [
            [
                "ac65bf94.6e609"
            ]
        ]
    },
    {
        "id": "ac65bf94.6e609",
        "type": "counter",
        "z": "6f607e7be4f8184e",
        "name": "",
        "init": "0",
        "step": "1",
        "lower": "0",
        "upper": "100",
        "mode": "increment",
        "outputs": 2,
        "x": 2220,
        "y": 3600,
        "wires": [
            [
                "9bc803da88d7a81c"
            ],
            []
        ]
    },
    {
        "id": "f1fa5335c50eb855",
        "type": "switch",
        "z": "6f607e7be4f8184e",
        "name": "Eingang",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 1080,
        "y": 3600,
        "wires": [
            [
                "0ddbe65e8ee6dc7f"
            ]
        ]
    },
    {
        "id": "0ddbe65e8ee6dc7f",
        "type": "switch",
        "z": "6f607e7be4f8184e",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gt",
                "v": "50",
                "vt": "num"
            },
            {
                "t": "btwn",
                "v": "50",
                "vt": "num",
                "v2": "100",
                "v2t": "num"
            },
            {
                "t": "lt",
                "v": "50",
                "vt": "num"
            },
            {
                "t": "lt",
                "v": "0",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 4,
        "x": 1290,
        "y": 3600,
        "wires": [
            [
                "8f457e3b4483feca"
            ],
            [
                "285690d8d097abcd",
                "98fc2e2e39d81a53"
            ],
            [
                "6b7bdc93c4810e47"
            ],
            [
                "98fc2e2e39d81a53",
                "285690d8d097abcd",
                "045b51a0549a85c3"
            ]
        ]
    },
    {
        "id": "8f457e3b4483feca",
        "type": "trigger",
        "z": "6f607e7be4f8184e",
        "name": "größer als",
        "op1": "true",
        "op2": "",
        "op1type": "bool",
        "op2type": "nul",
        "duration": "-250",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "stop",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 1500,
        "y": 3520,
        "wires": [
            [
                "285690d8d097abcd",
                "ce8d952f.18666"
            ]
        ]
    },
    {
        "id": "6b7bdc93c4810e47",
        "type": "trigger",
        "z": "6f607e7be4f8184e",
        "name": "kleiner als",
        "op1": "true",
        "op2": "",
        "op1type": "bool",
        "op2type": "nul",
        "duration": "-250",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "stop",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 1500,
        "y": 3680,
        "wires": [
            [
                "98fc2e2e39d81a53",
                "8a41c1.6006b64"
            ]
        ]
    },
    {
        "id": "98fc2e2e39d81a53",
        "type": "change",
        "z": "6f607e7be4f8184e",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "stop",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1530,
        "y": 3640,
        "wires": [
            [
                "8f457e3b4483feca"
            ]
        ]
    },
    {
        "id": "285690d8d097abcd",
        "type": "change",
        "z": "6f607e7be4f8184e",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "stop",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1530,
        "y": 3560,
        "wires": [
            [
                "6b7bdc93c4810e47"
            ]
        ]
    },
    {
        "id": "9bc803da88d7a81c",
        "type": "rpi-gpio out",
        "z": "6f607e7be4f8184e",
        "name": "",
        "pin": "12",
        "set": "",
        "level": "0",
        "freq": "100",
        "out": "pwm",
        "bcm": true,
        "x": 2420,
        "y": 3580,
        "wires": []
    },
    {
        "id": "045b51a0549a85c3",
        "type": "switch",
        "z": "6f607e7be4f8184e",
        "name": "<0",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 1490,
        "y": 3600,
        "wires": [
            [
                "17cce981.975686"
            ]
        ]
    },
    {
        "id": "eca29a029066e63f",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "150",
        "payloadType": "num",
        "x": 710,
        "y": 4100,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    },
    {
        "id": "c459ebe4f79c0824",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1000",
        "payloadType": "num",
        "x": 710,
        "y": 4160,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    },
    {
        "id": "d7eb897f7fc06209",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1700",
        "payloadType": "num",
        "x": 710,
        "y": 4220,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    },
    {
        "id": "2b0818ca6e61637d",
        "type": "inject",
        "z": "6f607e7be4f8184e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "-2000",
        "payloadType": "num",
        "x": 710,
        "y": 3260,
        "wires": [
            [
                "c1ddd4997a1f7a84"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![Flixm](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/flixm/32/17122_2.png) [@Flixm](https://discourse.nodered.org/u/Flixm)\
**Post date:** [21 February 2023 08:29 UTC](https://discourse.nodered.org/t/dynamic-counter/75487/5 "2023-02-21T08:29:29Z")

</div>

Yes, 1msg/s but not fixed

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 February 2023 14:04 UTC](https://discourse.nodered.org/t/dynamic-counter/75487/6 "2023-02-21T14:04:15Z")

</div>

Is this any help to you. The trigger node is to simulate the messages coming in every seoncd. If you want a smoother change you can, for example, change the trigger to 100msec then you will get intermediate messages 10 times/second.

```auto
[{"id":"394b90dd0f76e1eb","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"30","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":3820,"wires":[["ada378c4e02b070e"]]},{"id":"5cd54232cf19a43d","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"40","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":3880,"wires":[["ada378c4e02b070e"]]},{"id":"5c80f73f0335850b","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"50","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":3940,"wires":[["ada378c4e02b070e"]]},{"id":"512e3b7c11aa5c56","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"60","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":4000,"wires":[["ada378c4e02b070e"]]},{"id":"7273dcbf3e4c3224","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"70","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":4060,"wires":[["ada378c4e02b070e"]]},{"id":"329694499f1b0d71","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"80","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":4120,"wires":[["ada378c4e02b070e"]]},{"id":"1261dcc3c2f5fbb9","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"90","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":4180,"wires":[["ada378c4e02b070e"]]},{"id":"08982fa878da5df7","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":3760,"wires":[["ada378c4e02b070e"]]},{"id":"1be571d3c12523f9","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":3700,"wires":[["ada378c4e02b070e"]]},{"id":"12858cf00763e2a2","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":3640,"wires":[["ada378c4e02b070e"]]},{"id":"d14404b6bac28543","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"-10","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":3580,"wires":[["ada378c4e02b070e"]]},{"id":"74256f09c8dc0619","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"-20","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":3520,"wires":[["ada378c4e02b070e"]]},{"id":"cf2ff1c36fd7fae9","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"-30","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":3460,"wires":[["ada378c4e02b070e"]]},{"id":"eca29a029066e63f","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"150","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":4240,"wires":[["ada378c4e02b070e"]]},{"id":"c459ebe4f79c0824","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1000","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":4300,"wires":[["ada378c4e02b070e"]]},{"id":"d7eb897f7fc06209","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1700","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":4360,"wires":[["ada378c4e02b070e"]]},{"id":"2b0818ca6e61637d","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"-2000","payloadType":"num","_mcu":{"mcu":false},"x":130,"y":3400,"wires":[["ada378c4e02b070e"]]},{"id":"c84c6986c5972fd6","type":"function","z":"bdd7be38.d3b55","name":"5 sec low pass filter","func":"// Applies a simple RC low pass filter to incoming payload values\nconst tc = 5*1000; // time constant in milliseconds\nconst resetTime = 5*1000 // resets if no input for this time (msec)\n\nlet lastValue = context.get('lastValue');\nif (typeof lastValue == \"undefined\") lastValue = msg.payload;\nconst lastTime = context.get('lastTime') || null;\nconst now = new Date().getTime();\nconst currentValue = msg.payload;\nlet newValue;\nif (lastTime === null) {\n // first time through\n newValue = currentValue;\n} else { \n const dt = now - lastTime;\n if (dt > resetTime) {\n // too long has elapsed since last input so reset\n newValue = currentValue\n } else {\n if (dt > 0) {\n const dtotc = dt / tc;\n newValue = lastValue * (1 - dtotc) + currentValue * dtotc;\n } else {\n // no time has elapsed leave output the same as last time\n newValue = lastValue;\n }\n }\n}\ncontext.set('lastValue', newValue);\ncontext.set('lastTime', now);\n\nmsg.payload = newValue;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"_mcu":{"mcu":false},"x":590,"y":3880,"wires":[["1dc66e8c5f7edb4d"]]},{"id":"1dc66e8c5f7edb4d","type":"debug","z":"bdd7be38.d3b55","name":"debug 95","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","_mcu":{"mcu":false},"x":600,"y":3800,"wires":[]},{"id":"ada378c4e02b070e","type":"trigger","z":"bdd7be38.d3b55","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"-1","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"_mcu":{"mcu":false},"x":400,"y":3880,"wires":[["c84c6986c5972fd6"]]}]

```

---

<div class="post-metadata">

**Author:** ![Flixm](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/flixm/32/17122_2.png) [@Flixm](https://discourse.nodered.org/u/Flixm)\
**Post date:** [21 February 2023 18:24 UTC](https://discourse.nodered.org/t/dynamic-counter/75487/7 "2023-02-21T18:24:01Z")

</div>

Thx, but it's more a PI controller with a reset by pausing the incomming signal.  
In my case I control a heating rod with the overpower Watt from my PV system.  
I can read the power consumption of my house positiv and negativ (overpower). So, if i can read the there're 250 Watt of overpower i can send the signal to my heater to set nearby 250 Watt, but then my system recognize that there's no overpower an shut down the heater ... and so on.  
My solution now is to trigger the heater slowly (with fixed speed) to power up the Watt consuption till the Overpower is betwen 50-100 Watt to pause the trigger (counter). If it's less then 50 Watt then it triggers the counter fast down to (best case) 50-100 Watt and very importend is if there´s a positiv consumption of my house i reset all triggers (up & down counter) to 0 to get no power consumption of the heater. My only problem is that the trigger node is in a fixed speed. It's much better if there´s a higher different between the last and the newest value it should be a fast trigger, NOT a higher value. And i need to stop/reset this trigger.

Hopefully it's now better to understand my "problem".

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [22 April 2023 18:24 UTC](https://discourse.nodered.org/t/dynamic-counter/75487/8 "2023-04-22T18:24:42Z")

</div>

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