linuxha / node-red-contrib-mytimeout

A dynamic count down timer for node-red
MIT License
10 stars 10 forks source link

Run different instances of timer based on msg.topic #18

Closed sriramsv closed 4 years ago

sriramsv commented 5 years ago

I would like to have a functionality which the original delay node in node-red has, variable delay per message topic which allows us to run multiple instances of the timer based on the msg.topic value passed to the node. I tried doing the same with the mytimeout and new invocations always reset the timer. Would be really nice to keep multiple timers running.

Sample Flow:

[
    {
        "id": "e9c0e6e2.b401f8",
        "type": "mytimeout",
        "z": "d24adb51.bd89f8",
        "name": "",
        "outtopic": "",
        "outsafe": "on",
        "outwarning": "",
        "outunsafe": "off",
        "warning": "5",
        "timer": "30",
        "debug": false,
        "ndebug": false,
        "ignoreCase": false,
        "repeat": false,
        "again": false,
        "x": 1330,
        "y": 220,
        "wires": [
            [
                "28a04c14.1e2fa4"
            ],
            []
        ]
    },
    {
        "id": "37366a80.05b1a6",
        "type": "inject",
        "z": "d24adb51.bd89f8",
        "name": "",
        "topic": "",
        "payload": "{\"payload\":\"on\",\"timeout\":50,\"warning\":30,\"topic\":\"foo\"}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 950,
        "y": 200,
        "wires": [
            [
                "69883483.758bdc"
            ]
        ]
    },
    {
        "id": "28a04c14.1e2fa4",
        "type": "debug",
        "z": "d24adb51.bd89f8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 1540,
        "y": 220,
        "wires": []
    },
    {
        "id": "69f9a286.29315c",
        "type": "inject",
        "z": "d24adb51.bd89f8",
        "name": "",
        "topic": "",
        "payload": "stop",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 1050,
        "y": 320,
        "wires": [
            [
                "e9c0e6e2.b401f8"
            ]
        ]
    },
    {
        "id": "2685c496.bfdf3c",
        "type": "inject",
        "z": "d24adb51.bd89f8",
        "name": "",
        "topic": "",
        "payload": "pause",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 1050,
        "y": 400,
        "wires": [
            [
                "e9c0e6e2.b401f8"
            ]
        ]
    },
    {
        "id": "c665e6ad.370bb8",
        "type": "inject",
        "z": "d24adb51.bd89f8",
        "name": "",
        "topic": "",
        "payload": "{\"payload\":\"on\",\"timeout\":20,\"warning\":10,\"topic\":\"bar\"}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 930,
        "y": 260,
        "wires": [
            [
                "69883483.758bdc"
            ]
        ]
    },
    {
        "id": "69883483.758bdc",
        "type": "change",
        "z": "d24adb51.bd89f8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "payload.topic",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1120,
        "y": 200,
        "wires": [
            [
                "e9c0e6e2.b401f8"
            ]
        ]
    }
]
linuxha commented 5 years ago

I need to think about this. I don't think the current structure of the code would be able to handle this. At the moment I'm rather busy with my work schedule which is keeping me from looking at anything to do with mytimeout. So I'm not saying no and not ignoring you.

sriramsv commented 5 years ago

ok, thanks a lot, I could try to do send you a pull-request over the weekend, but I am bit of a JS noob.

linuxha commented 4 years ago

Sriramsv, I'm going to close this for now. This would be a major change in the way the code works and I'm not quite sure how to implement that. I'll keep it on the wish list.

And for the record I'm not an expert at Javascript. I just decided to write some code one day and ended up with mytimeout. :-)