Open
Description
Hi
I solved a lot of things for the MQTT integration to control lights here: https://github.com/pbel78/scratch2/
I want to add to my code a delay if a turnLightOn function is called with a transition time of 2 seconds I want the block to wait for 2 seconds before the next block is executed. Somehow all ideas I had to realize this didn't resulted in the expected functionallity. Did I miss any documentation how to wait correctly (i.e. the same way as if I would drag in a "wait X seconds" block from the control section.
Can I somehow refer the original block in my code?
What I tried:
In Javascript
- to do an async function call with a promise that is waiting
- try to do a loop check for the time passed
In Scratch:
- A custom block combining my own block with the original wait block => this worked but I loose the functionallity of the dropdown list for the lamp fixtures which I have in my new functions.
Example for the light brightness which did not work :) :
setLightBrightness({ LAMP,BRIGHTNESS,TRANSITION }) {
if (this.client) {
this.mqttSend({ MESSAGE, TOPIC })
const TOPIC = 'zigbee2mqtt/'.concat(LAMP).concat('/set');
const MESSAGE = this.addTransition(BRIGHTNESS, TRANSITION);
this.mqttSend({ MESSAGE, TOPIC })
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > Number(TRANSITION) * 1000 ){
break;
}
}
return 'helloWorld'
}
}
Thank you for any hint.
Regards
Petr
Metadata
Metadata
Assignees
Labels
No labels