Is it possible to add a timer to this


#1

Hi all,

I just came into this site after seeing a link to remix a multiple command IFTTT trigger for Google home. I’m not new to coding, I’ve done lots of it in the past with many languages but its been a while.

Anyway my question is: rather than executing the code in the server.js script right away, is it possible to add a timer to this?

The code can be seen here

https://messy-lan.glitch.me


#2

Yes, something similar came up before, you can use setTimeout().


#3

So I have used setTimeout as you suggested. I have an error popping up in the log - why is this happening? I have a feeling it’s because I’m also passing a value to waitFunction, but how do I do that without an error?

Please see this link for code.

https://glitter-college.glitch.me

The error is:

TypeError: “callback” argument must be a function at exports.setTimeout (timers.js:327:11)


#4

It looks like you got past this. If you’re still having trouble, let us know.


#5

Hi thanks for the replies.

Sorry I’m still having trouble.

I made some changes to see if that was why the error was popping up - and it was. But the problem still remains as to how I can pass something to waitFunction. I tried to do it using a global by placing a var statement at the top (which for rid of the errors) but that was just passing undefined (I’m not used to the way variables are handled in JS any more).


#6

I have now changed it back to how it was originally so you guys can see where I’m going wrong with this. I won’t make any changes until someone suggests something


#7

We figured this out together. If anyone is interested, there’s an example here of how to schedule delayed callbacks with different arguments in response to an HTTP request:

https://glitch.com/edit/#!/thin-detective?path=server.js:18:38

#8

Thanks for the help Tim.

It turned out the problem was because of the timer delay. The variable triggerEvent was being overwritten by the function checkForTrigger with “undefined” before the waitFunction was being called.

As a solution, I stored triggerEvent in a new variable called theTriggerEvent immediately and accessed that in waitFunction instead.


#9

Tim that was such a bad way to do it anyway. I have done the same thing in a much cleaner way like this

https://glory-poultry.glitch.me

Now you can set a list of up to 10 IFTTT commands (easy to expand to more if you wanted) and they will all be done after the time limit you set with the variable timeLimit at the top.