# Using homeyscript for light control

**URL:** <https://community.homey.app/t/using-homeyscript-for-light-control/68686>\
**Category:** Questions & Help\
**Created:** [September 10, 2022, 3:08pm UTC](https://community.homey.app/t/using-homeyscript-for-light-control/68686 "2022-09-10T15:08:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArnarS](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arnars/32/33981_2.png) [@ArnarS](https://community.homey.app/u/ArnarS)\
**Post date:** [September 10, 2022, 3:08pm UTC](https://community.homey.app/t/using-homeyscript-for-light-control/68686/1 "2022-09-10T15:08:04Z")

</div>

Hi.

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,  
Arnar

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [September 10, 2022, 10:39pm UTC](https://community.homey.app/t/using-homeyscript-for-light-control/68686/2 "2022-09-10T22:39:26Z")

</div>

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

> [@Advanced flow. Controleren of er nog lampen aan staan](https://community.homey.app/t/advanced-flow-controleren-of-er-nog-lampen-aan-staan/65274/15):
>
> Graag gedaan. Voor nu weet ik daar een heel handige app voor, Zone Memory. Je kunt ook een paar losse ‘actie’ flows maken, waarin je een groep lampen op verschillende gewenste dim nivo’s instelt. Een groep voor overdag, 's avonds etc De \< group \> app is ook erg handig. Zet een paar lampen in een groep, en je kunt de gezamenlijke capaciteiten als zijne 1 lamp bedienen. Je kunt ook groepen in een groep ‘hangen’. Ik heb hier een dim script, welke instelbare tijdsduur en stapgrootte heeft. (Hier…

---

<div class="post-metadata">

**Author:** ![ArnarS](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arnars/32/33981_2.png) [@ArnarS](https://community.homey.app/u/ArnarS)\
**Post date:** [September 11, 2022, 7:31am UTC](https://community.homey.app/t/using-homeyscript-for-light-control/68686/3 "2022-09-11T07:31:15Z")

</div>

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,  
Arnar

---

<div class="post-metadata">

**Author:** ![ArnarS](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arnars/32/33981_2.png) [@ArnarS](https://community.homey.app/u/ArnarS)\
**Post date:** [September 11, 2022, 10:40am UTC](https://community.homey.app/t/using-homeyscript-for-light-control/68686/4 "2022-09-11T10:40:24Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [September 11, 2022, 7:47pm UTC](https://community.homey.app/t/using-homeyscript-for-light-control/68686/5 "2022-09-11T19:47:58Z")

</div>

This is the duration (in a way) imho, it only has to be calculated 😉  
0.80/0.05=16 steps  
16\*750=12,000ms

```auto
// 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 */

```

> [@ArnarS](#):
>
> ```auto
> await Homey.flow.runFlowCardAction({
> uri: 'homey:device:x-x-x(id)-x-x-',
> id: 'dim',
> args: {
> dim: 0.45,
>     
> },
> duration: 10
> });
> 
> ```

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.
