# How can I store a current value (2)

**URL:** https://discourse.nodered.org/t/how-can-i-store-a-current-value-2/101371
**Category:** General
**Created:** [28 June 2026 16:02 UTC](https://discourse.nodered.org/t/how-can-i-store-a-current-value-2/101371 "2026-06-28T16:02:12Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Johannesje](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@Johannesje](https://discourse.nodered.org/u/Johannesje)
#### Post date: [28 June 2026 16:02 UTC](https://discourse.nodered.org/t/how-can-i-store-a-current-value-2/101371/1 "2026-06-28T16:02:12Z")

</div>

Hi,

Additional on my previous topic ( **[How can I store a current value](https://discourse.nodered.org/t/how-can-i-store-a-current-value/101061)** ) I see that the the context.set("store",msg.payload) is stored at the second pulse from the kWh meter.  
Is it possible that the value stores at the same time when the HOLD button is served?

This is important that someone is clicking on the "HOLD" button with no direct response.on the dashboard.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [29 June 2026 09:10 UTC](https://discourse.nodered.org/t/how-can-i-store-a-current-value-2/101371/2 "2026-06-29T09:10:56Z")

</div>

I'm confused. 🙂

Your other thread is `solved` so I didn't read it too much.

Could you explain where `HOLD` comes into things?

You are receiving messages with kWh values and some of the values are stored.  
I forget the specs for how they are stored.

There is a button connected to the node - `function` I'm guessing - that causes things to store the value (only because you mentioned it's name: `HOLD`)

But what do you want to happen again?

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [29 June 2026 09:24 UTC](https://discourse.nodered.org/t/how-can-i-store-a-current-value-2/101371/3 "2026-06-29T09:24:50Z")

</div>

Ah, it was me who even helped/solved it for you.

I have CRAFT disease. (Don't ask)

Ok, we were keeping it off a `dashboard` in our posts.  
(Only to keep it simple)

I got the code I posted that you said was the solution.

With that code, you _press_ the `hold` and the next message received from the kWh is stored.  
(In flow context)

> [@Johannesje](#):
>
> Is it possible that the value stores at the same time when the HOLD button is served?

Well, it can't as the `hold` message doesn't have any kWh data in it.

> [@Johannesje](#):
>
> This is important that someone is clicking on the "HOLD" button with no direct response.on the dashboard.

Well, you can give it some indication if you want.  
This wasn't mentioned in the original post.

But let's - for now - keep to the question you asked and sorry, I still don't fully understand.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [29 June 2026 10:04 UTC](https://discourse.nodered.org/t/how-can-i-store-a-current-value-2/101371/4 "2026-06-29T10:04:00Z")

</div>

Thinking.....

> [@Johannesje](#):
>
> Is it possible that the value stores at the same time when the HOLD button is served?

I don't know how you get th kWh values.  
Yes, they're from a _node_ that is sending them out, or an `MQTT` node receiving them.

**IF** (big if) it is a **NODE** :  
Can you send a message into that node?

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [29 June 2026 10:39 UTC](https://discourse.nodered.org/t/how-can-i-store-a-current-value-2/101371/5 "2026-06-29T10:39:37Z")

</div>

> [@Johannesje](#):
>
> Is it possible that the value stores at the same time when the HOLD button is served?  
> This is important that someone is clicking on the "HOLD" button with no direct response.on the dashboard.

Although I'm not 100% sure of what you are trying to do, this might be a viable approach.

1. Store _every_ incoming value in a flow context variable flow.latestValue.  
This just needs a change node in your normal message processing flow  

2. Connect the output of the button to another change node to _copy flow.latestValue to flow.heldValue._

---

<div class="post-metadata">

### Author: ![Johannesje](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@Johannesje](https://discourse.nodered.org/u/Johannesje)
#### Post date: [29 June 2026 16:34 UTC](https://discourse.nodered.org/t/how-can-i-store-a-current-value-2/101371/6 "2026-06-29T16:34:17Z")

</div>

Yes the kWh pulses coming via MQTT from Domoticz. But I will receive also pulses from the watermeter and the time between pulses is to long so that's the reason for my question.  
I will try the option @jbudd, I let you know.

---

<div class="post-metadata">

### Author: ![Johannesje](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@Johannesje](https://discourse.nodered.org/u/Johannesje)
#### Post date: [29 June 2026 17:03 UTC](https://discourse.nodered.org/t/how-can-i-store-a-current-value-2/101371/7 "2026-06-29T17:03:39Z")

</div>

I did not completely understand this option. I will test it for the watermeter first, below my flow.

```auto
[
    {
        "id": "02c8da9c9f004ce0",
        "type": "rpi-gpio in",
        "z": "daac5e65e6e72986",
        "name": "Watermeter puls (L1)",
        "pin": "23",
        "intype": "tri",
        "debounce": "25",
        "read": true,
        "bcm": true,
        "x": 200,
        "y": 1660,
        "wires": [
            [
                "ce8d952f.18666"
            ]
        ]
    },
    {
        "id": "fda0a334.bc9588",
        "type": "inject",
        "z": "daac5e65e6e72986",
        "name": "reset",
        "repeat": "",
        "crontab": "",
        "once": false,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 190,
        "y": 1800,
        "wires": [
            [
                "17cce981.975686"
            ]
        ]
    },
    {
        "id": "ce8d952f.18666",
        "type": "function",
        "z": "daac5e65e6e72986",
        "name": "msg object",
        "func": "msg.increment = 1;\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 390,
        "y": 1720,
        "wires": [
            [
                "ac65bf94.6e609"
            ]
        ]
    },
    {
        "id": "17cce981.975686",
        "type": "function",
        "z": "daac5e65e6e72986",
        "name": "msg object",
        "func": "msg.reset = true;\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 390,
        "y": 1800,
        "wires": [
            [
                "ac65bf94.6e609"
            ]
        ]
    },
    {
        "id": "ac65bf94.6e609",
        "type": "counter",
        "z": "daac5e65e6e72986",
        "name": "",
        "init": "100",
        "step": 1,
        "lower": null,
        "upper": null,
        "mode": "increment",
        "outputs": 1,
        "x": 560,
        "y": 1740,
        "wires": [
            [
                "c2893b966e892354",
                "fba855e07eca3774",
                "c9adc4cdcdda4625",
                "96beafdd58160cd1"
            ]
        ]
    },
    {
        "id": "fba855e07eca3774",
        "type": "function",
        "z": "daac5e65e6e72986",
        "name": "Watermeter",
        "func": "flow.set(\"water\",msg.count)\nlet waterT = flow.get(\"water\")\nmsg.payload = waterT;\nmsg.topic = \"Totaal water\"\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 790,
        "y": 1740,
        "wires": [
            [
                "04564826297c0bc0"
            ]
        ]
    },
    {
        "id": "285e0e19.b9680a",
        "type": "inject",
        "z": "daac5e65e6e72986",
        "name": "increment",
        "repeat": "",
        "crontab": "",
        "once": false,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 180,
        "y": 1720,
        "wires": [
            [
                "ce8d952f.18666"
            ]
        ]
    },
    {
        "id": "a8ad38766f6fa0c2",
        "type": "change",
        "z": "daac5e65e6e72986",
        "name": "get value water",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "#:(file)::wstore",
                "tot": "flow"
            },
            {
                "t": "set",
                "p": "whold",
                "pt": "flow",
                "to": "0",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1060,
        "y": 1860,
        "wires": [
            [
                "0ca4f578aa918e28"
            ]
        ]
    },
    {
        "id": "0ca4f578aa918e28",
        "type": "function",
        "z": "daac5e65e6e72986",
        "name": "Water totaal",
        "func": "var waterT = msg.payload;\nmsg.payload = waterT / 1000 + (\" m3\");\nmsg.topic = \"Totaal water\"\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1250,
        "y": 1860,
        "wires": [
            [
                "6ec8afb177c37c43"
            ]
        ]
    },
    {
        "id": "f8d5be30f9e348a5",
        "type": "inject",
        "z": "daac5e65e6e72986",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "HOLD",
        "payloadType": "str",
        "x": 170,
        "y": 1860,
        "wires": [
            [
                "c9adc4cdcdda4625"
            ]
        ]
    },
    {
        "id": "6ec8afb177c37c43",
        "type": "ui-text",
        "z": "daac5e65e6e72986",
        "group": "927da3575e7dfcde",
        "order": 28,
        "width": 2,
        "height": 0,
        "name": "Vastleggen water",
        "label": "Water totaal:",
        "format": "{{msg.payload}}",
        "layout": "row-left",
        "style": true,
        "font": "Arial Black,Arial Black,Gadget,sans-serif",
        "fontSize": "14",
        "color": "#000000",
        "wrapText": false,
        "className": "",
        "value": "payload",
        "valueType": "msg",
        "x": 1450,
        "y": 1860,
        "wires": []
    },
    {
        "id": "0ad55939fdce4995",
        "type": "ui-text",
        "z": "daac5e65e6e72986",
        "group": "927da3575e7dfcde",
        "order": 12,
        "width": 2,
        "height": 0,
        "name": "Water totaal",
        "label": "Water totaal:",
        "format": "{{msg.payload}}",
        "layout": "row-spread",
        "style": true,
        "font": "Arial Black,Arial Black,Gadget,sans-serif",
        "fontSize": "16",
        "color": "#000000",
        "wrapText": false,
        "className": "",
        "value": "payload",
        "valueType": "msg",
        "x": 1430,
        "y": 1740,
        "wires": []
    },
    {
        "id": "992b6aa48bb386f6",
        "type": "trigger",
        "z": "daac5e65e6e72986",
        "name": "",
        "op1": "false",
        "op2": "true",
        "op1type": "bool",
        "op2type": "bool",
        "duration": "250",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "true",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 1040,
        "y": 1680,
        "wires": [
            [
                "99f2b642925a51dc"
            ]
        ]
    },
    {
        "id": "c2893b966e892354",
        "type": "function",
        "z": "daac5e65e6e72986",
        "name": "Water tarief pulsen",
        "func": "const thisvalue = msg.count // Extract the latest value from payload\nconst lastvalue = context.get(\"lastvalueW\") || true // and previous value from context\n\nif (thisvalue > lastvalue) { // Do some sort of comparison\n msg.payload = false\n}\nelse {\n msg.payload = true\n}\n\ncontext.set(\"lastvalueW\", thisvalue)\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 810,
        "y": 1680,
        "wires": [
            [
                "992b6aa48bb386f6"
            ]
        ]
    },
    {
        "id": "99f2b642925a51dc",
        "type": "ui-led",
        "z": "daac5e65e6e72986",
        "name": "Water tatief led",
        "group": "927da3575e7dfcde",
        "order": 13,
        "width": 1,
        "height": 0,
        "label": "",
        "labelPlacement": "left",
        "labelAlignment": "center",
        "states": [
            {
                "value": "false",
                "valueType": "bool",
                "color": "#0000ff"
            },
            {
                "value": "true",
                "valueType": "bool",
                "color": "#ffffff"
            }
        ],
        "allowColorForValueInMessage": false,
        "shape": "circle",
        "showBorder": true,
        "showGlow": true,
        "x": 1440,
        "y": 1680,
        "wires": []
    },
    {
        "id": "04564826297c0bc0",
        "type": "function",
        "z": "daac5e65e6e72986",
        "name": "Water totaal",
        "func": "let waterT = msg.count;\nmsg.payload = waterT / 1000 + (\" m3\");\n\nmsg.topic = \"Totaal water\"\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1030,
        "y": 1740,
        "wires": [
            [
                "0ad55939fdce4995"
            ]
        ]
    },
    {
        "id": "c9adc4cdcdda4625",
        "type": "function",
        "z": "daac5e65e6e72986",
        "name": "Water hold",
        "func": "const message = msg.payload\nlet whold = flow.get(\"holdw\") || 0\n\n// If `HOLD`\nif (message == \"HOLD\")\n{\n flow.set(\"holdw\",1)\n return // Nothing more to do be hone here/now\n}\n\nif (whold == 1)\n{\n // `hold` is set.\n flow.set(\"wstore\",msg.count, \"file\")\n flow.set(\"holdw\",0) // stop next message being storred too.\n}\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 770,
        "y": 1860,
        "wires": [
            [
                "a8ad38766f6fa0c2"
            ]
        ]
    },
    {
        "id": "96beafdd58160cd1",
        "type": "change",
        "z": "daac5e65e6e72986",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "latestValue",
                "pt": "flow",
                "to": "count",
                "tot": "msg",
                "dc": true
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 810,
        "y": 1800,
        "wires": [
            [
                "05c575a78364c32a"
            ]
        ]
    },
    {
        "id": "05c575a78364c32a",
        "type": "change",
        "z": "daac5e65e6e72986",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "heldvalue",
                "pt": "flow",
                "to": "LatestValue",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1050,
        "y": 1800,
        "wires": [
            []
        ]
    },
    {
        "id": "927da3575e7dfcde",
        "type": "ui-group",
        "name": "Nr.11 Verbruik en tellerstanden",
        "page": "a5219b6b7f535c4d",
        "width": 3,
        "height": 1,
        "order": 3,
        "showTitle": true,
        "className": "",
        "visible": "true",
        "disabled": "false",
        "groupType": "default"
    },
    {
        "id": "a5219b6b7f535c4d",
        "type": "ui-page",
        "name": "Nr.11 Groepen / verbruik / WiFi",
        "ui": "9db73792cdc62e1e",
        "path": "/page8",
        "icon": "home",
        "layout": "grid",
        "theme": "2afc50d1d1cfac95",
        "breakpoints": [
            {
                "name": "Default",
                "px": "0",
                "cols": "3"
            },
            {
                "name": "Tablet",
                "px": "576",
                "cols": "6"
            },
            {
                "name": "Small Desktop",
                "px": "768",
                "cols": "9"
            },
            {
                "name": "Desktop",
                "px": "1024",
                "cols": "12"
            }
        ],
        "order": 9,
        "className": "",
        "visible": "true",
        "disabled": "false"
    },
    {
        "id": "9db73792cdc62e1e",
        "type": "ui-base",
        "name": "Muntsetille",
        "path": "/dashboard",
        "appIcon": "",
        "includeClientData": true,
        "acceptsClientConfig": [
            "ui-notification",
            "ui-control"
        ],
        "showPathInSidebar": false,
        "headerContent": "dashpage",
        "navigationStyle": "default",
        "titleBarStyle": "default",
        "showReconnectNotification": true,
        "notificationDisplayTime": 1,
        "showDisconnectNotification": true,
        "allowInstall": false
    },
    {
        "id": "2afc50d1d1cfac95",
        "type": "ui-theme",
        "name": "Default Theme",
        "colors": {
            "surface": "#924f96",
            "primary": "#ccc500",
            "bgPage": "#c19a9a",
            "groupBg": "#84b4e1",
            "groupOutline": "#cccccc"
        },
        "sizes": {
            "density": "default",
            "pagePadding": "12px",
            "groupGap": "4px",
            "groupBorderRadius": "4px",
            "widgetGap": "12px"
        }
    },
    {
        "id": "b23bc31c4967b732",
        "type": "global-config",
        "env": [],
        "modules": {
            "node-red-node-pi-gpio": "2.0.7",
            "node-red-contrib-counter": "0.1.6",
            "@flowfuse/node-red-dashboard": "1.30.2",
            "@flowfuse/node-red-dashboard-2-ui-led": "1.1.0"
        }
    }
]

```

(sorry for the dutch text)

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [29 June 2026 22:31 UTC](https://discourse.nodered.org/t/how-can-i-store-a-current-value-2/101371/8 "2026-06-29T22:31:24Z")

</div>

@jbudd has a good idea in some ways, but reading what you just said, I am not sure it will really _work_.

(No offence @jbudd)

Let's keep it to the kWh thing, and forgive me for now being _vague_ in how I'm describing things.

So your kWh sends you message every 10 minutes.

You want the value stored 5 minutes after receipt of the last one.  
There is no magic way that you can get **THE** reading now.  
(referring back to this.)

> Is it possible that the value stores at the same time when the HOLD button is served?

Because you only get the value every 10 minutes.  
Pressing the `hold` button can't make a value happen.

Well, maybe you can force the value to be sent if you send the thing a message.  
I don't know. You need to expand on what the device is and what commands it accepts.  
(How do you configure it to send the kWh values at the given interval, etc?)

When _we_ know more about that we may be able to make something more to what you are asking.

But I'm not understanding WHY you want this any way.  
You are getting the value every 10 minutes.  
~~It is stored, and the most recent one is kept.~~  
A slight tweak along the line of what @jbudd was saying would go a long way to _resolving_ how my original flow worked.

Though with little effort you could modify mine to do what was said anyway.

Did you ever use the `Read stored value` inject node?

This is a quick effort at what you may want.

```auto
[{"id":"d5990187685fe0bf","type":"inject","z":"26262ba1.62dcbc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":6480,"y":6650,"wires":[["0b397ef8641455c3"]]},{"id":"0b397ef8641455c3","type":"function","z":"26262ba1.62dcbc","name":"random vlue for testing","func":"const randomNumber = Math.floor(Math.random() * 10) + 1\nmsg.payload = randomNumber\n\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":6670,"y":6650,"wires":[["15bb1ef2aa6a1e40"]]},{"id":"3c215e18f98675e6","type":"inject","z":"26262ba1.62dcbc","name":"Read stored value AKA HOLD?","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":6550,"y":6700,"wires":[["636bfb6f41d5f45e"]]},{"id":"636bfb6f41d5f45e","type":"change","z":"26262ba1.62dcbc","name":"get value","rules":[{"t":"set","p":"payload","pt":"msg","to":"store","tot":"flow"},{"t":"set","p":"hold","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":6930,"y":6700,"wires":[["4ed820dd2290e21c"]]},{"id":"4ed820dd2290e21c","type":"debug","z":"26262ba1.62dcbc","name":"Look","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":7220,"y":6700,"wires":[]},{"id":"1bea07235e196dda","type":"debug","z":"26262ba1.62dcbc","name":"to Where ever","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":7250,"y":6650,"wires":[]},{"id":"15bb1ef2aa6a1e40","type":"change","z":"26262ba1.62dcbc","name":"Store the value for later access","rules":[{"t":"set","p":"store","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":7000,"y":6650,"wires":[["1bea07235e196dda"]]}]

```

`to where ever` and `look` are shown as TWO nodes. But you could connect them together and maybe get what you want.

---

<div class="post-metadata">

### Author: ![Johannesje](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@Johannesje](https://discourse.nodered.org/u/Johannesje)
#### Post date: [30 June 2026 16:59 UTC](https://discourse.nodered.org/t/how-can-i-store-a-current-value-2/101371/9 "2026-06-30T16:59:12Z")

</div>

Thanks, I will try to implement this, I will think about it.  
The time between kWh pulses is approximately @200W three seconds.

The problem with the watermeter is, when there is less waterflow through the meter, the time is too long between two pulses. When I push the hold button, the value change to the hold value at the next flowmeter pulse.

I tet it know when I have a solution.

---

<div class="post-metadata">

### Author: ![Johannesje](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@Johannesje](https://discourse.nodered.org/u/Johannesje)
#### Post date: [5 July 2026 11:30 UTC](https://discourse.nodered.org/t/how-can-i-store-a-current-value-2/101371/10 "2026-07-05T11:30:55Z")

</div>

After some thought, I simplified everything myself and also removed the default counter.

Now I can change the fixed value by using one pulse.  
Thanks everyone, I have learned a lot from this again.

```auto
[
    {
        "id": "02c8da9c9f004ce0",
        "type": "rpi-gpio in",
        "z": "daac5e65e6e72986",
        "name": "Watermeter puls (L1)",
        "pin": "23",
        "intype": "tri",
        "debounce": "25",
        "read": true,
        "bcm": true,
        "x": 200,
        "y": 1680,
        "wires": [
            [
                "c2893b966e892354",
                "669eb52e285d84ef"
            ]
        ]
    },
    {
        "id": "285e0e19.b9680a",
        "type": "inject",
        "z": "daac5e65e6e72986",
        "name": "increment",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "",
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 180,
        "y": 1740,
        "wires": [
            [
                "c2893b966e892354",
                "669eb52e285d84ef"
            ]
        ]
    },
    {
        "id": "a8ad38766f6fa0c2",
        "type": "change",
        "z": "daac5e65e6e72986",
        "name": "get value water",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "#:(file)::wstore",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1040,
        "y": 1860,
        "wires": [
            [
                "0ca4f578aa918e28"
            ]
        ]
    },
    {
        "id": "0ca4f578aa918e28",
        "type": "function",
        "z": "daac5e65e6e72986",
        "name": "Water totaal",
        "func": "var waterT = msg.payload;\nmsg.payload = waterT / 1000 + (\" m3\");\nmsg.topic = \"Totaal water\"\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1250,
        "y": 1860,
        "wires": [
            [
                "6ec8afb177c37c43"
            ]
        ]
    },
    {
        "id": "f8d5be30f9e348a5",
        "type": "inject",
        "z": "daac5e65e6e72986",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "HOLD",
        "payloadType": "str",
        "x": 170,
        "y": 1860,
        "wires": [
            [
                "4b674e0a2beb3525"
            ]
        ]
    },
    {
        "id": "6ec8afb177c37c43",
        "type": "ui-text",
        "z": "daac5e65e6e72986",
        "group": "927da3575e7dfcde",
        "order": 28,
        "width": 2,
        "height": 0,
        "name": "Vastleggen water",
        "label": "Water totaal:",
        "format": "{{msg.payload}}",
        "layout": "row-left",
        "style": true,
        "font": "Arial Black,Arial Black,Gadget,sans-serif",
        "fontSize": "14",
        "color": "#000000",
        "wrapText": false,
        "className": "",
        "value": "payload",
        "valueType": "msg",
        "x": 1450,
        "y": 1860,
        "wires": []
    },
    {
        "id": "0ad55939fdce4995",
        "type": "ui-text",
        "z": "daac5e65e6e72986",
        "group": "927da3575e7dfcde",
        "order": 12,
        "width": 2,
        "height": 0,
        "name": "Water totaal",
        "label": "Water totaal:",
        "format": "{{msg.payload}}",
        "layout": "row-spread",
        "style": true,
        "font": "Arial Black,Arial Black,Gadget,sans-serif",
        "fontSize": "16",
        "color": "#000000",
        "wrapText": false,
        "className": "",
        "value": "payload",
        "valueType": "msg",
        "x": 1430,
        "y": 1740,
        "wires": []
    },
    {
        "id": "992b6aa48bb386f6",
        "type": "trigger",
        "z": "daac5e65e6e72986",
        "name": "",
        "op1": "false",
        "op2": "true",
        "op1type": "bool",
        "op2type": "bool",
        "duration": "250",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "true",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 1040,
        "y": 1680,
        "wires": [
            [
                "99f2b642925a51dc"
            ]
        ]
    },
    {
        "id": "c2893b966e892354",
        "type": "function",
        "z": "daac5e65e6e72986",
        "name": "Water tarief pulsen",
        "func": "const thisvalue = msg.count // Extract the latest value from payload\nconst lastvalue = context.get(\"lastvalueW\") || true // and previous value from context\n\nif (thisvalue > lastvalue) { // Do some sort of comparison\n msg.payload = false\n}\nelse {\n msg.payload = true\n}\n\ncontext.set(\"lastvalueW\", thisvalue)\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 810,
        "y": 1680,
        "wires": [
            [
                "992b6aa48bb386f6"
            ]
        ]
    },
    {
        "id": "99f2b642925a51dc",
        "type": "ui-led",
        "z": "daac5e65e6e72986",
        "name": "Water tatief led",
        "group": "927da3575e7dfcde",
        "order": 13,
        "width": 1,
        "height": 0,
        "label": "",
        "labelPlacement": "left",
        "labelAlignment": "center",
        "states": [
            {
                "value": "false",
                "valueType": "bool",
                "color": "#0000ff"
            },
            {
                "value": "true",
                "valueType": "bool",
                "color": "#ffffff"
            }
        ],
        "allowColorForValueInMessage": false,
        "shape": "circle",
        "showBorder": true,
        "showGlow": true,
        "x": 1440,
        "y": 1680,
        "wires": []
    },
    {
        "id": "04564826297c0bc0",
        "type": "function",
        "z": "daac5e65e6e72986",
        "name": "Water totaal",
        "func": "let waterT = flow.get(\"water\", \"file\")\nmsg.payload = waterT / 1000 + (\" m3\");\n\nmsg.topic = \"Totaal water\"\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1030,
        "y": 1740,
        "wires": [
            [
                "0ad55939fdce4995"
            ]
        ]
    },
    {
        "id": "4b674e0a2beb3525",
        "type": "function",
        "z": "daac5e65e6e72986",
        "name": "Water hold",
        "func": "const message = msg.payload\nconst waterH = flow.get(\"water\", \"file\")\n\nif (message == \"HOLD\")\n{\nflow.set(\"wstore\", waterH, \"file\") \n}\nelse\n{\nnull\n}\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 790,
        "y": 1860,
        "wires": [
            [
                "a8ad38766f6fa0c2"
            ]
        ]
    },
    {
        "id": "669eb52e285d84ef",
        "type": "function",
        "z": "daac5e65e6e72986",
        "name": "Watermeter",
        "func": "const message = msg.payload\nlet waterTotal = flow.get(\"water\", \"file\")\nlet waterCurrent = flow.get(\"water\", \"file\")\n\n\nif (waterCurrent >= waterTotal)\nif (message == true)\n{\nflow.set(\"water\", (waterTotal + 1), \"file\")\n}\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 790,
        "y": 1740,
        "wires": [
            [
                "04564826297c0bc0"
            ]
        ]
    },
    {
        "id": "7a77daa523d4aaa0",
        "type": "inject",
        "z": "daac5e65e6e72986",
        "name": "Set currect setting",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 210,
        "y": 1800,
        "wires": [
            [
                "135e948316447978"
            ]
        ]
    },
    {
        "id": "135e948316447978",
        "type": "change",
        "z": "daac5e65e6e72986",
        "name": "Current countersetting",
        "rules": [
            {
                "t": "set",
                "p": "#:(file)::water",
                "pt": "flow",
                "to": "4000",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 820,
        "y": 1800,
        "wires": [
            []
        ]
    },
    {
        "id": "927da3575e7dfcde",
        "type": "ui-group",
        "name": "Nr.11 Verbruik en tellerstanden",
        "page": "a5219b6b7f535c4d",
        "width": 3,
        "height": 1,
        "order": 3,
        "showTitle": true,
        "className": "",
        "visible": "true",
        "disabled": "false",
        "groupType": "default"
    },
    {
        "id": "a5219b6b7f535c4d",
        "type": "ui-page",
        "name": "Nr.11 Groepen / verbruik / WiFi",
        "ui": "9db73792cdc62e1e",
        "path": "/page8",
        "icon": "home",
        "layout": "grid",
        "theme": "2afc50d1d1cfac95",
        "breakpoints": [
            {
                "name": "Default",
                "px": "0",
                "cols": "3"
            },
            {
                "name": "Tablet",
                "px": "576",
                "cols": "6"
            },
            {
                "name": "Small Desktop",
                "px": "768",
                "cols": "9"
            },
            {
                "name": "Desktop",
                "px": "1024",
                "cols": "12"
            }
        ],
        "order": 9,
        "className": "",
        "visible": "true",
        "disabled": "false"
    },
    {
        "id": "9db73792cdc62e1e",
        "type": "ui-base",
        "name": "Muntsetille",
        "path": "/dashboard",
        "appIcon": "",
        "includeClientData": true,
        "acceptsClientConfig": [
            "ui-notification",
            "ui-control"
        ],
        "showPathInSidebar": false,
        "headerContent": "dashpage",
        "navigationStyle": "default",
        "titleBarStyle": "default",
        "showReconnectNotification": true,
        "notificationDisplayTime": 1,
        "showDisconnectNotification": true,
        "allowInstall": false
    },
    {
        "id": "2afc50d1d1cfac95",
        "type": "ui-theme",
        "name": "Default Theme",
        "colors": {
            "surface": "#924f96",
            "primary": "#ccc500",
            "bgPage": "#c19a9a",
            "groupBg": "#84b4e1",
            "groupOutline": "#cccccc"
        },
        "sizes": {
            "density": "default",
            "pagePadding": "12px",
            "groupGap": "4px",
            "groupBorderRadius": "4px",
            "widgetGap": "12px"
        }
    },
    {
        "id": "53051f4e90128c55",
        "type": "global-config",
        "env": [],
        "modules": {
            "node-red-node-pi-gpio": "2.0.7",
            "@flowfuse/node-red-dashboard": "1.30.2",
            "@flowfuse/node-red-dashboard-2-ui-led": "1.1.0"
        }
    }
]

```

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [5 July 2026 11:51 UTC](https://discourse.nodered.org/t/how-can-i-store-a-current-value-2/101371/11 "2026-07-05T11:51:29Z")

</div>

I'm glad you found a solution.

I do think you could further simplify your code though - for example this function seems a complicated way to increment a context variable.

```auto
const message = msg.payload
let waterTotal = flow.get("water", "file")
let waterCurrent = flow.get("water", "file")

if (waterCurrent >= waterTotal)
if (message == true)
{
flow.set("water", (waterTotal + 1), "file")
}
return msg;

```

---

<div class="post-metadata">

### Author: ![Johannesje](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@Johannesje](https://discourse.nodered.org/u/Johannesje)
#### Post date: [5 July 2026 12:26 UTC](https://discourse.nodered.org/t/how-can-i-store-a-current-value-2/101371/12 "2026-07-05T12:26:25Z")

</div>

Ah, thanks!
