Using homeyscript for light control


I would like to create a homeyscript to control certain lights (devices) in Homey. I know how to get a certain actioncard for a certain light:
e.g. const ac = await Homey.flow.getFlowCardAction({uri: "homey:device:x-x-x-x" ,id: "dim"})

and I can run a card using Homey.flow.runFlowCardAction({uri: "homey:device:x-x-x-x", id: "dim")
But how would I use this when I want dim a light and set the duration of the dimming?

best regards,

Hi Arnar,
In this topic you’ll find several scripts, but it is in Dutch. (I use or for translations of languages I don’t speak (very well) );
The scripts are mostly written in English though:

Thank you very much for your reply. Funnily enough, I have just yesterday created the exact same script myself. Very good learning experience to take these example scripts and tinker. This script never popped up during my searching since I do my searching in English.

Although this script does provide the solution I need, it does not provide an answer to my question.

But perhaps, a little background info to explain why I am asking this.

I made the dimmer script (and actually for light_temperature also). And I wanted to combine the two into one script. Then I started thinking (bad idea). Why use a loop for the light dimming when most lights do provide a flow card for dimming with a set duration? Hence my question. How to use the light’s ‘dim’ flowcard with ‘duration’ in homeyscript?

best regards,

hehe asked and answered. Turned out to be rather simple.
And the surprising thing is that setting a duration when changing a light’s temperature also works!
Even though you do not have that option in the actual action flowcard in Homey

await Homey.flow.runFlowCardAction({
  uri: 'homey:device:x-x-x(id)-x-x-',
  id: 'dim',
  args: {
    dim: 0.45,
  duration: 10

This is the duration (in a way) imho, it only has to be calculated :wink:
0.80/0.05=16 steps

// enter the target dim level
var myDimlevel = 0.80; /* range: 0.01 - 1 */
// enter a start dim level
var myDimlevelStart = 0.01; /* range: 0.01 - 1 */
// Enter a delay time (for the next dim level)
var waitForDimlevel = 750; /* time in ms */
// Enter the value to increase the dim level with
var myDimlevelStep = 0.05; /* range: 0.01 - 1 */

This doesn’t work for the following lights (which don’t have the flowcard option “Duration”)…
KaKu (CoCo) and Tuya wifi lights, they dim right away.
Works fine with Ikea lights.