Node-Red how to use input number value

Using mustache templates in the entity id field

[{"id":"0eee5ed698f079b5","type":"inject","z":"89650f988807e878","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":228,"y":128,"wires":[["32e4873d4f403529"]]},{"id":"32e4873d4f403529","type":"api-current-state","z":"89650f988807e878","name":"","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_select.which_light","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":470,"y":128,"wires":[["6b4b38e8e28c2d1c"]]},{"id":"6b4b38e8e28c2d1c","type":"api-call-service","z":"89650f988807e878","name":"","server":"","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["{{data.entity_id}}"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":730,"y":128,"wires":[[]]}]

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/mustache-templates.html

Using node input

[{"id":"0eee5ed698f079b5","type":"inject","z":"89650f988807e878","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":228,"y":128,"wires":[["32e4873d4f403529"]]},{"id":"32e4873d4f403529","type":"api-current-state","z":"89650f988807e878","name":"","server":"2dad33ee.42bf5c","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_select.which_light","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"data","propertyType":"msg","value":"{\t    \"target\": {\t        \"entity_id\": $entity().state\t    }\t}","valueType":"jsonata"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":470,"y":128,"wires":[["6b4b38e8e28c2d1c"]]},{"id":"6b4b38e8e28c2d1c","type":"api-call-service","z":"89650f988807e878","name":"","server":"2dad33ee.42bf5c","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":730,"y":128,"wires":[[]]},{"id":"2dad33ee.42bf5c","type":"server","name":"Home Assistant","version":4,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"id","statusSeparator":"","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h12","statusTimeFormat":"h:m"}]

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/call-service.html#input

Using JSONata inside the call-service node

[{"id":"0eee5ed698f079b5","type":"inject","z":"89650f988807e878","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":228,"y":128,"wires":[["6b4b38e8e28c2d1c"]]},{"id":"6b4b38e8e28c2d1c","type":"api-call-service","z":"89650f988807e878","name":"","server":"","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":[],"data":"{\t    \"entity_id\": $entities(\"input_select.which_light\").state\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":390,"y":128,"wires":[[]]}]

thanks a lot, working very well!!!

Hey guys.
I’m learning node red, I’m pretty basic in programming, but I’ve already managed to do some cool things. I’m trying to do something with my occupancy sensors I have them all over the house.
I created a subflow with two functions, turn the light on and another function turn off the light this worked but now I’m trying to determine a time for the lamps to turn off I’m having a lot of difficulties in the function to turn off the light (turn_of).
It has several conditionals in it, my biggest problem is resetting the time to turn off the lamp when the presence sensor is activated. What I need is this to reset the time to turn off the lamp every time the presence sensor goes on. Can someone help me? That is my funcion turn_off:

const entities = global.get('homeassistant').homeAssistant.states;
var msg1,msg2;
var grupo = env.get("grupo");
var sensor = env.get("sensor");
var tempo = env.get("tempo");
var meutempo = (entities[tempo].state * 1000 * 60)
var setar;




if((msg.payload === "on"))  
        {
        clearTimeout(setar);
        node.send(msg);  //{payload:false}
}

if((msg.payload === "off"))  
        {
if((entities[grupo].state === "on") && (entities[sensor].state === "on") ) 
{            
    setar = setTimeout(function(){
        msg.payload = {
                domain: "light",
                service: "turn_off",
                data: {
                    entity_id: [grupo],
                }
        };
        node.send(msg);
        },
        meutempo);
}
}
return null;

and this is my subflow:

If anyone can help me I would greatly appreciate it.

Hello. I changed a lot in the function and now it seems to be working, below is how it turned out. If anyone has any thoughts on changes or improvements I would appreciate it.

const entities = global.get('homeassistant').homeAssistant.states;
var grupo = env.get("grupo");
var sensor = env.get("sensor");
var tempo = env.get("tempo");
var mytime = (entities[tempo].state * 1000 *60)



function desligarFunction(){
        msg.payload = {
                domain: "light",
                service: "turn_off",
                data: {
                    entity_id: [grupo],
                }
        };
    node.send(msg);
}

function setarFunction() {
  let setar = setTimeout(desligarFunction, mytime);
  context.set('mem',setar);
}


function ResetFunction() {
  let setar = context.get('mem');    
  clearTimeout(setar);
  node.send({payload:false});  
}






if((msg.payload === "on"))  
        {
        ResetFunction();  //{payload:false}
}

if((msg.payload === "off"))  
        {
        if((entities[grupo].state === "on") && (entities[sensor].state === "on") ) 
            {            
            setarFunction();
            }
        }

return null;

You are likely not getting a response because it is uncommon to use a function node for a timer. Nodered’s trigger node works very well as a resetable timer.