getSubscribedDeviceById error

In the following code the log.debug works, but attempting to set the same data into a field fails

void handlerControlTemp(evt) 
	{
	def deviceId = evt.getDeviceId()
	log.debug getSubscribedDeviceById(deviceId).currentValue("thermostatMode")
	def deviceMode = getSubscribedDeviceById(deviceId).currentValue("thermostatMode")

Hopefully someone smarter than me can let me how to fix this

@bravenel @mike.maxwell

This code works for me, so not sure what the problem is.

Can't reproduce...

Appreciate you both testing that code and the very quick responses.

FWIW I'm on a C-4 with 2.3.2.135

I also found this workaound vs setting a field to the value and then testing it.

if (getSubscribedDeviceById(deviceId).currentValue("thermostatMode") != 'dry')

You don’t have to do all of this. evt.device is the device wrapper.

1 Like

Big Thank You! The following works.
def deviceMode = evt.device.currentValue("thermostatMode")

So would

evt.device.currentThermostatMode

2 Likes

evt.device.currentThermostatMode has to be more efficient than
evt.device.currentValue("thermostatMode") However, I can't find documentation on it or other methods that exist for a thermostat. I remember using this method or something similar a long time ago on another platform, but that was so many brain cells ago.

I did find documentation for Capabilites that includes Methods, but have no idea how to get that data for a device.

I would appreciate a link to, or some code, that will get the methods for a device.

Whenever you have a device attribute that you might use with device.currentValue("attributeName"), you can also use device.currentAttributeName to mean the same thing -- in apps. Notice the capitalization of the first letter of the attribute name in the second form.

2 Likes