Homey Community Forum

Use of getCapabilityValue

I’m trying to read the ‘light_temperature’ of a zigbee lightbulb.
setting the value using device.setCapabilityValue('light_temperature, .2) is working without problems.
But reading the value: lighttemp = device.getCapabilityValue(‘light_temperature’) gives an error;

TypeError: device.getCapabilityValue is not a function.

The getCapabilityValue is a valid method. So why is it not a function? How to get this value anyway?

You can get the value, but the method is asynchronous. It returns a “promise” that will tell you either the value or the error when it is done. Putting await before the call will help you deal with handling the promise and get the actual result you are looking for. But I’m not sure that this error is what you’d normally get so there might be more things wrong. AFAIK the method is a function returning a promise.

@Edwin_D
device.getCapabilityValue is not a function is unrelated to if it returns promises or not; the error is quite self-explanatory: the object device doesn’t have a function getCapabilityValue.

@hkoopmans you’re using the Web API (or Homeyscript, but that also uses the Web API under the hood) for your code, but you’re looking at the SDK documentation. Those two API’s are different. The Web API only has setCapabilityValue for a device, getCapabilityValue is only available from the SDK (which is used to create apps).

Try using device.capabilitiesObj['light_temperature'].value

1 Like

@robertklep
Thanks Robert! This works!