Call Service node for a user-defined amount of time?

Hi Everyone,

A newbie to node-red. I have been searching all over the place but can’t seem to find an answer to what should be an ‘easy’ thing to do :(.

I have a service node that opens a relay which then connects to a trigger node - which turns off the relay after 10 seconds. But this is hard coded (ie. the Trigger node) for a set amount of time. What I want to be able to do is allow the users to change the amount of time the relay is open (dynamically) ie. set the time in trigger node dynamically. In HA - I have defined an entity (a slider) that ranges from 0-10 minutes (input_number. row1_duration).

Is it possible to do something in the service node to set a dynamic time to run the service? Otherwise - other ideas on the ‘best’ way to dynamically set how long the service node (the relay) runs?

Thanks.

Yes you can use the slider value as in input to your service call. You could easily achieve this via usage of a function node and then send your payload as formated like this:

{"data" : { "VALUETOCHANGE" : {{YOUVALUE}} } }

Hi Almost Serious,

Not sure what you mean - could you show me a flow?

Thx.

easiest way to do is probably with the delay node.

[
    {
        "id": "642f64be.2deb0c",
        "type": "server-state-changed",
        "z": "6b8efe0d.bc75e",
        "name": "",
        "server": "2fba4297.e4145e",
        "version": 1,
        "entityidfilter": "input_number.alexa_spot",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": true,
        "x": 1650,
        "y": 380,
        "wires": [
            [
                "6c1889e8.fb3f88"
            ]
        ]
    },
    {
        "id": "b0e43c73.8fa6f",
        "type": "delay",
        "z": "6b8efe0d.bc75e",
        "name": "",
        "pauseType": "delayv",
        "timeout": "10",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 2140,
        "y": 380,
        "wires": [
            []
        ]
    },
    {
        "id": "6c1889e8.fb3f88",
        "type": "change",
        "z": "6b8efe0d.bc75e",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "delay",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1930,
        "y": 380,
        "wires": [
            [
                "b0e43c73.8fa6f"
            ]
        ]
    },
    {
        "id": "2fba4297.e4145e",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "legacy": false,
        "hassio": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true
    }
]

This just takes the payload of the slider and sets it msg.delay

Make sure to select set delay via msg.delay.
The delay is calculated in milliseconds.
image

If you want to use a different timeunit with your slider, you could just multiply the payload to make it more userfriendly