# Variable countdown timer

**URL:** <https://discourse.nodered.org/t/variable-countdown-timer/85878>\
**Category:** General\
**Created:** [25 February 2024 11:21 UTC](https://discourse.nodered.org/t/variable-countdown-timer/85878 "2024-02-25T11:21:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![daycare](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daycare/32/88634_2.png) [@daycare](https://discourse.nodered.org/u/daycare)\
**Post date:** [25 February 2024 11:21 UTC](https://discourse.nodered.org/t/variable-countdown-timer/85878/1 "2024-02-25T11:21:26Z")

</div>

Hello,  
I'm new to node-red, which I use with the Rhasspy voice assistant.  
I'm trying to create a countdown whose duration is variable depending on the choice made vocally.  
I manage to retrieve this value from the Rhasspy sentence, but can't figure out how to use it afterwards.

None of the nodes I've tried allow you to assign a variable to the countdown, all of them offer only fixed values (node-red-contrib-mytimeout and node-red-contrib-countdown-2).  
Am I missing the right node or do I need to do something different?

I'd appreciate a clue,  
Thanks

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [25 February 2024 11:40 UTC](https://discourse.nodered.org/t/variable-countdown-timer/85878/2 "2024-02-25T11:40:00Z")

</div>

The trigger node will accept msg.delay in milliseconds to set a delay before passing on the second message. so set first output to nothing and check enable override with msg.delay. You can even set a unique topic and have multiple delays.

---

<div class="post-metadata">

**Author:** ![daycare](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daycare/32/88634_2.png) [@daycare](https://discourse.nodered.org/u/daycare)\
**Post date:** [25 February 2024 13:28 UTC](https://discourse.nodered.org/t/variable-countdown-timer/85878/3 "2024-02-25T13:28:03Z")

</div>

Thanks for your reply  
Using the delay module, I managed to cobble something together.  
It's probably not the best, but it works pretty well :

```auto
[
    {
        "id": "e504dd10cbae1274",
        "type": "delay",
        "z": "2b2676f81a6deb7d",
        "name": "",
        "pauseType": "delayv",
        "timeout": "0",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 740,
        "y": 980,
        "wires": [
            [
                "af57212ef76772e9"
            ]
        ]
    },
    {
        "id": "50db0c636e060eab",
        "type": "http request",
        "z": "2b2676f81a6deb7d",
        "name": "Text to Speech",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "http://192.168.1.22:12101/api/text-to-speech",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "basic",
        "senderr": false,
        "headers": [],
        "x": 1080,
        "y": 980,
        "wires": [
            [
                "cce696cc46725848"
            ]
        ]
    },
    {
        "id": "af57212ef76772e9",
        "type": "function",
        "z": "2b2676f81a6deb7d",
        "name": "Terminé",
        "func": "msg.payload = \"\\\"Compte à rebours de \" + (msg.delay/60000) + \" minutes terminé.\\\"\"\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 900,
        "y": 980,
        "wires": [
            [
                "50db0c636e060eab"
            ]
        ]
    },
    {
        "id": "cce696cc46725848",
        "type": "repeat",
        "z": "2b2676f81a6deb7d",
        "name": "Repeat",
        "repetitions": "1",
        "elseOutput": false,
        "outputs": 1,
        "x": 1260,
        "y": 980,
        "wires": [
            [
                "af57212ef76772e9"
            ]
        ]
    },
    {
        "id": "6f7df16989fcca0f",
        "type": "function",
        "z": "2b2676f81a6deb7d",
        "name": "Compte à rebours",
        "func": "msg.delay = (msg.payload.entities[0].value*60000); // conversion millisecondes en minutes\nmsg.payload = { \"speech\": { \"text\": \"J'active un compte à rebours de \" + msg.payload.entities[0].value + \" minutes\" }};\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 550,
        "y": 980,
        "wires": [
            [
                "e504dd10cbae1274",
                "f2a97ecabff94b75"
            ]
        ]
    },
    {
        "id": "f2a97ecabff94b75",
        "type": "http response",
        "z": "2b2676f81a6deb7d",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 750,
        "y": 940,
        "wires": []
    }
]

```

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [25 February 2024 17:56 UTC](https://discourse.nodered.org/t/variable-countdown-timer/85878/4 "2024-02-25T17:56:25Z")

</div>

Not to put too fine a point but the mytimeout node will accept a timeout in the msg  
msg = {  
payload: 'on',  
timeout: 60,  
warning: 0,  
topic: 'timer',  
}

this set the time in the node, you can set it to any value you want and also several other parameters. They are listed in the node readme.

---

<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:** [25 May 2024 17:57 UTC](https://discourse.nodered.org/t/variable-countdown-timer/85878/5 "2024-05-25T17:57:16Z")

</div>

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