device.setCapabilityValue duration

Hey all,

I just started dabbling in HomeyScript, and am quite new to JavaScript (fortunately I have some background in C and Python to help me along) but I came upon an issue with the setCapabilityValue function.

Essentially, I’m trying to set the Hue of a light over a certain duration. I notice that the setCapabilityValue function has an option ‘duration’, so I call the function as follows:

device.setCapabilityValue('light_hue', hue, 30000);

But when the light changes hue, it does so instantly (i.e. it doesn’t gradually change the hue over the defined time). When I try the similar thing with a Flow card, it works perfectly (but for my purposes I would really like to do it within a homeyscript, as it allows me to combine 8 or more flows into one script…)

I’m not sure whether I’m supposed to provide this duration in milliseconds (as example) or as seconds, or whether I am wrong in any case to just provide the argument as an integer (maybe I have to generate some special Options Object or something?) Device - Homey Web API

All advice is welcome… Many thanks!

According to the documentation, the call should look like this:

device.setCapabilityValue('light_hue', hue, { duration: 30000 });

No, that also doesn’t seem to do the trick :frowning: The lights still change hue instantly (I even rebooted Homey to make sure the new js version was used)

In that case it’s likely that the documentation just isn’t correct. The SDK method to set a capability value doesn’t have a duration either, and I would think the Web API uses that method under the hood.

Maybe the 30000 is out of range, as 30000 seconds is a lot of seconds (yes, duration is in seconds, not milliseconds)

Thanks for the info on the time unit!
It still doesn’t work though :frowning:

I’m somehow convinced it should be possible to do, as there as a simple flow action card that allows for this. Can I perhaps simply trigger this flow card from within homeyscript? It seems like a terrible workaround, but if it works…
Essentially I would then need a way to retrieve the action cards coupled to a given device, and launch one of those cards…

Of course, it would still be best if the duration option actually worked :slight_smile:

So the SDK uses milliseconds everywhere a duration/timeout can be set, but the Web API uses seconds? :thinking:

No, SDK is using seconds too I believe, or is it just a facade in the app and web app that only seconds can be used. :thinking:

But now thinking about the setCapabilityValue in Homeyscript isn’t possible anyway as it doesn’t have the rights to do so, triggering the action card will be the only way.

Hm :frowning: Sounds strange to me as I would think the action card uses some type of SDK or similar under the hood as well?

Anyway, could you then help me along with an example on how to obtain and launch the action cards matching a given device id or name? I looks at the example script where all flow cards are listed, but I can’t figure out an efficient way of finding a particular flow card selectively for a given device. I’ll keep looking, but perhaps you experts simply know already :stuck_out_tongue:

Ah yes, for mere mortals it’s seconds, not milliseconds :smiley: But the underlying code always uses milliseconds AFAIK.

What kind of device/driver it this?

For some kind of reason calling device.setCapabilityValue doesnt allow passing opts but on ManagerDevices it does so this should work.

Homey.devices.setCapabilityValue({
  deviceId: '1',
  capabilityId: 'id',
  value: 10,
  opts: {
    duration: 3000
  }
});
1 Like

It’s a Philips Hue Centura spot:

Property Value
ID 1f6cc3e5-4cd0-4542-ae3e-02781bd41a27
Class light
Driver homey:app:com.philips.hue.zigbee — 5045131P7
Ready Yes
Available Yes
Warning No
Custom icon No
Data
Key Value
token “a89e210f-38e3-4ae6-97e3-009d449391f4”
Settings
Key Value
zb_product_id “5045148P7”
zb_manufacturer_name “Philips”
transition_time 1
energy_value_off 1
energy_value_on 6
powerOnCtrl_dimvalue 255
powerOnCtrl_state “recover”

Awesome, this works!
The unit of duration is then also in milliseconds :slight_smile:

So this is what I made of it in the end:

    device.setCapabilityValue('onoff', true);
    Homey.devices.setCapabilityValue({
      deviceId: device.id,
      capabilityId: device.capabilitiesObj.light_hue.id,
      value: hue,
      opts: {
        duration: 30000
      }
    });
2 Likes