Set stoptimer value with text input node&environment variables

Hello,

can someone give me a simple example for the following problem

i want to set the timer value from the stoptimer varidelay with an text input node and an environment variable

i tried something but i do not understand the concept of environment variables

how can i set and change the values from this typ of variables and how can i use this in a function node?

Just trying to fully understand your intent .. is it:

a) You'll enter the name of the environment variable to be read using the text input node?

Or

b) You'll enter the desired timer value in the text input node and then write that to the environment which is then used by the stoptimer-varidelay? (if it is this one, then I don't think it'll work as as environment variables aren't really dynamically changeable like that).

Also, you mentioned environment variables, I just want to make sure you are not really talking about context variables (global, flow) instead?

BTW - if you are doing (a) I don't think that can be done cleanly either, as the way environment variables works is that when the runtime loads the flows, that's when it will substitute the value of that environment variable before passing it to the node. So you can't call env.get (or ${}) with a variable env name, the env variable name has to be known when you hit deploy.

There are some other possibilities here, but it would help to understand what relationship you have between the text input node and the environment variable.
If you can explain what the rationale

Not sure if this helps, but attached is a stripped down version of how I use voice commands to Alexa to set the time on the varidelay stop timer. Although I'm using function nodes, I don't see any reason you couldn't feed the information to varidelay via environment variables in a similar way. I use this system for my lights, fans, hubitat modes, and even status reports of different smart home items.

The flow uses the following nodes:

node-red-contrib-alexa-remote2-applestrudel
node-red-contrib-ecolect
node-red-contrib-stoptimer-varidelay

You'll have to put in your Alexa account info if you want to use the Alexa nodes. If not, just delete all of the Alexa nodes and the ECOLECT node. The flows should still give you a pretty good idea of how I'm passing info to varidelay.

Hopefully this is somewhat helpful. I'd be happy to answer any questions I can.

If you have more interest in the Alexa aspect you can find out more at: Pure fun with Alexa and Alexa Skills

varidelay example flow.txt (66.8 KB)

it`s b)

i want to change the timer value by entering the value in a text input node

The delay Timer only offers strings or environment variables as input type

Hi DiverRich

i tried your example for the delaytimer, but i was not able to be change the timer Value from the varidelay timer, for example from 60 Minutes to 5 Minutes.

I don`t understand it

Maybe you can me build a example for changing the value over a text input or injection node?

Here's a simple example - 2 inject nodes, one setting the timer to 5 seconds, the other to 1 minute.

[
    {
        "id": "ddfb266cb8da0676",
        "type": "inject",
        "z": "ab694f2.fb732b",
        "name": "5 seconds",
        "props": [
            {
                "p": "delay",
                "v": "5",
                "vt": "num"
            },
            {
                "p": "units",
                "v": "seconds",
                "vt": "str"
            },
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "This was 5 seconds",
        "payloadType": "str",
        "x": 160,
        "y": 2780,
        "wires": [
            [
                "13bff0f06687b904"
            ]
        ]
    },
    {
        "id": "cc42fca725cf5d80",
        "type": "inject",
        "z": "ab694f2.fb732b",
        "name": "1 minute",
        "props": [
            {
                "p": "delay",
                "v": "1",
                "vt": "num"
            },
            {
                "p": "units",
                "v": "minutes",
                "vt": "str"
            },
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "This was 1 minute",
        "payloadType": "str",
        "x": 160,
        "y": 2840,
        "wires": [
            [
                "13bff0f06687b904"
            ]
        ]
    },
    {
        "id": "13bff0f06687b904",
        "type": "stoptimer-varidelay",
        "z": "ab694f2.fb732b",
        "duration": "5",
        "durationType": "num",
        "units": "Second",
        "payloadtype": "num",
        "payloadval": "0",
        "name": "",
        "reporting": "every_second",
        "persist": false,
        "ignoretimerpass": false,
        "x": 400,
        "y": 2800,
        "wires": [
            [
                "f17ad2fbec50c09d"
            ],
            [],
            []
        ]
    },
    {
        "id": "f17ad2fbec50c09d",
        "type": "debug",
        "z": "ab694f2.fb732b",
        "name": "TEST",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 630,
        "y": 2800,
        "wires": []
    }
]

It might be an idea to describe the problem you are addressing/trying to solve as often others will be able to throw different ideas in the mix as to a different way to approach it

Craig

1 Like

Hi hamsando,

this looks very interesting. Thanks for it.

Now i can try to replace the injection nodes with text input nodes

or can you give me a example for this too?

OK - I understand it, but it doesn't solve my problem because the timer settings are time limited
I want to change the timer value permanently
is there a possibility to change it permanently

Short term solution could be:

  1. for you setup persistent storage for context variables
  2. and then save the delay you want to a global or flow context being saved to a file
  3. Every message going to the timer would then pass through a change mode that could add that delay to the message.

I could update stoptimer-varidelay to be able to directly reference flow or context variables, but I don’t have access to a computer (only my phone) for the next week or so (even then it works only eliminate step 3 above)

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