Countdown from Number

Hi
I am trying to build an countdown from a number (7777777777).
Every 4 Seconds it should decrease at 1
And this number is shown in Dashboard.
That works all.
Now my Question: If the Raspyery gets off from Power and restarts the Number starts decreasing from 7777777777. i want to start decreasing from the number where the raspberry get out of power. so i have to give the latest output in an variable, so i think. but how can i do that?
Thanks for Help

Here is my flow

[
    {
        "id": "3bcdcc3bcf7c430e",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "0bdf612159e2a8ec",
        "type": "function",
        "z": "3bcdcc3bcf7c430e",
        "name": "function 2",
        "func": "var count = context.get('count') || 0;\ncount += 1;\nmsg.payload = Number (7777777777) - count;\ncontext.set('count', count);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 420,
        "y": 180,
        "wires": [
            [
                "7fbee56ef37d9748",
                "5f8d5d36cf1f74d6",
                "82d96936305edca3"
            ]
        ]
    },
    {
        "id": "d4b4a1e8b2e8fa31",
        "type": "inject",
        "z": "3bcdcc3bcf7c430e",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "4",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "ON",
        "payloadType": "str",
        "x": 190,
        "y": 180,
        "wires": [
            [
                "0bdf612159e2a8ec"
            ]
        ]
    },
    {
        "id": "7fbee56ef37d9748",
        "type": "debug",
        "z": "3bcdcc3bcf7c430e",
        "name": "debug 4",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 640,
        "y": 140,
        "wires": []
    },
    {
        "id": "5f8d5d36cf1f74d6",
        "type": "ioBroker out",
        "z": "3bcdcc3bcf7c430e",
        "name": "Counter",
        "topic": "0_userdata.0.Counter",
        "ack": "false",
        "autoCreate": "false",
        "stateName": "",
        "role": "",
        "payloadType": "",
        "readonly": "",
        "stateUnit": "",
        "stateMin": "",
        "stateMax": "",
        "x": 640,
        "y": 260,
        "wires": []
    },
    {
        "id": "82d96936305edca3",
        "type": "ui_text",
        "z": "3bcdcc3bcf7c430e",
        "group": "316dca5a2cf81cf0",
        "order": 0,
        "width": "20",
        "height": "6",
        "name": "",
        "label": "Counter",
        "format": "{{msg.payload}}",
        "layout": "col-center",
        "className": "",
        "x": 640,
        "y": 200,
        "wires": []
    },
    {
        "id": "316dca5a2cf81cf0",
        "type": "ui_group",
        "name": "Standard",
        "tab": "0a3fda28b8bfc042",
        "order": 1,
        "disp": false,
        "width": "20",
        "collapse": false,
        "className": ""
    },
    {
        "id": "0a3fda28b8bfc042",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "disabled": false,
        "hidden": true
    }
]

Are you using file based context or memory?
https://nodered.org/docs/user-guide/context#saving-context-data-to-the-file-system
file will survive a reboot

Hi
Thanks for the info
That is to much for mee, i am not shure where to set the parameters

  1. make my psg.payload to a variabel
    2 store the variabel to context
    3...how can i but the context back in the funktion to do the encreasing from it

if tried this, do you have any tips for me, thanks

msg.payload = var countnew

// store the value back

context.set('countnew', countnew);

// make it part of the outgoing msg object

msg.payload = countnew;

return msg;

Again unless you use file context your var will not survive a reboot.
https://nodered.org/docs/user-guide/runtime/settings-file

This might help you get a better understanding of persistent context:

2 Likes

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