Got a function working for ya. If you want to expand it id start with error checks and not allowing it to be triggered multiple times before it finishes its blink show.
You send it:
msg.lighton a numerical value in ms you want the light to be on
msg.lightoff a numerical value in ms you want the light to be off after it was on
msg.numberofblinks a numerical value of the number of time you want it to blink at that rate.
[{"id":"fd93f008.0e423","type":"change","z":"41f9ead2.0eab04","name":"","rules":[{"t":"set","p":"lighton","pt":"msg","to":"250","tot":"num"},{"t":"set","p":"lightoff","pt":"msg","to":"1000","tot":"num"},{"t":"set","p":"numberofblinks","pt":"msg","to":"3","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":260,"wires":[["1871a0b2.ea84af"]]},{"id":"3a5aa846.ad23c8","type":"inject","z":"41f9ead2.0eab04","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":260,"wires":[["fd93f008.0e423"]]},{"id":"7b2a537a.4ba75c","type":"debug","z":"41f9ead2.0eab04","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":730,"y":260,"wires":[]},{"id":"1871a0b2.ea84af","type":"function","z":"41f9ead2.0eab04","name":"The Light Show","func":"//get the values of msg.* to var's\nvar numberofblinks = msg.numberofblinks;\nvar light_on_for_ms = msg.lighton;\nvar light_off_for_ms = msg.lightoff;\n\n//how long to wait before starting the light show\nvar time_in_ms_to_wait_before_first_execution = 0;\n\n//total run time of light on and light off\nvar time_in_ms_to_wait_between_recursive_setTimeout = (light_on_for_ms + light_off_for_ms);\n\n//set the count to 0\nvar count = 0;\n\n//function to count the number of blinks and stop timmer\nfunction blinks()\n{\n if (count === numberofblinks)\n {\n //stop the recursive setTimeout\n clearTimeout(run);\n \n \n }\n else\n {\n count++;\n }\n}\n\n\n\n//function to set payload to true\nfunction payload_true()\n{\n //set payload to true\n node.send({payload:true});\n \n //display green dot when light is on\n node.status({\n fill: 'green',\n shape: 'dot',\n text: ' '\n });\n}\n\n//function to set payload to false\nfunction payload_false()\n{\n //set payload to false\n node.send({payload:false});\n \n //clear status when payload false\n node.status({\n });\n}\n\n//run the light show!!!!\nsetTimeout(function run() \n{\n blinks();\n //turn the light on by setting msg.payload to true\n payload_true();\n \n //turn the light off by waiting to set the payload to false by the ammount of time light is on\n setTimeout(payload_false, light_on_for_ms);\n //i++;\n \n //total ammount of time light can be on or off before it runs again\n setTimeout(run, time_in_ms_to_wait_between_recursive_setTimeout);\n}, time_in_ms_to_wait_before_first_execution);\n\n\n//clearTimeout(run);\nreturn msg;\n","outputs":1,"noerr":0,"x":560,"y":260,"wires":[["7b2a537a.4ba75c"]]},{"id":"9492094c.fcb338","type":"comment","z":"41f9ead2.0eab04","name":"every thing is in milliseconds","info":"","x":220,"y":180,"wires":[]},{"id":"9510cdff.f4ea8","type":"comment","z":"41f9ead2.0eab04","name":"make sure all msg values are set to numbers","info":"","x":270,"y":220,"wires":[]}]
the JS script in the function:
var numberofblinks = msg.numberofblinks;
var light_on_for_ms = msg.lighton;
var light_off_for_ms = msg.lightoff;
//how long to wait before starting the light show
var time_in_ms_to_wait_before_first_execution = 0;
//total run time of light on and light off
var time_in_ms_to_wait_between_recursive_setTimeout = (light_on_for_ms + light_off_for_ms);
//set the count to 0
var count = 0;
//function to count the number of blinks and stop timmer
function blinks()
{
if (count === numberofblinks)
{
//stop the recursive setTimeout
clearTimeout(run);
}
else
{
count++;
}
}
//function to set payload to true
function payload_true()
{
//set payload to true
node.send({payload:true});
//display green dot when light is on
node.status({
fill: 'green',
shape: 'dot',
text: ' '
});
}
//function to set payload to false
function payload_false()
{
//set payload to false
node.send({payload:false});
//clear status when payload false
node.status({
});
}
//run the light show!!!!
setTimeout(function run()
{
blinks();
//turn the light on by setting msg.payload to true
payload_true();
//turn the light off by waiting to set the payload to false by the ammount of time light is on
setTimeout(payload_false, light_on_for_ms);
//i++;
//total ammount of time light can be on or off before it runs again
setTimeout(run, time_in_ms_to_wait_between_recursive_setTimeout);
}, time_in_ms_to_wait_before_first_execution);
//clearTimeout(run);
return msg;
hope this helps