Homey Community Forum

Can't get "setTimeout()" to work (SOLVED!)

Using script example “Say.js” as template…

// Say Something
function talk() {
say(“I am Homey, and this is written in HomeyScript!”);
} //END Talk

setTimeout(talk, 5000);


Console output:
" Script Error:
setTimeout is not defined"

I’m new to JS, just trying to make the function to wait 5sec. before executing…

Athom apparently doesn’t want you to use timers from Homeyscript, but they weren’t careful enough and left a few workarounds because they’re passing in lodash:

function talk() {
  say("I am Homey, and this is written in HomeyScript!");
}

// workaround one:
_.debounce(talk, 5000)();

// workaround two:
_.delay(talk, 5000);

However, if you want to introduce delays like this, it’s probably better to use the standard “delay” option for flow cards.

Tank you, it worked… ( _,delay() doesn’t seem precise, 10sec delay was really more like 8, but works for me)
I am planning to use this inside my own app, so having to use flow cards is not somthing i want to do…

Apps aren’t built using Homeyscript though, so inside a proper app you’re able to use setTimeout and other timers just fine.

Ok, tanks, was using homeyScript to test solutions to various problems, was not aware of different behaviour from apps…