Help with app porting error

Hello, I ported an app from ST, the app is working but I am getting the below error. Was wondering if somebody can help me fix this?

java.lang.IllegalArgumentException: Command 'currentValue' is not supported by device. on line 250 (onDeviceAttributeChange)

code in question
def values = devices?.currentValue(name)

While no one can say without the full context that's missing here, from your variable names, I might assume these are collections and not a single device. I'm pretty sure Hubitat won't let you use currentValue on a collection (likely technically something like a DeviceWrapperList), and your error seems to support that. What I would do instead is either iterate over or search through the collection (any standard Groovy method for doing this should work) to retrieve or calculate whatever value(s) you're looking for in a way that makes sense for your app. Alternatively, you could make devices a single device and not a list (e.g., without multiple: true on the input).

Since it's hard to say without seeing more, hopefully this is enough to get you the right track!

1 Like

I believe the ST method on a list is just shorthand for devices.collect(...).

not sure what hyou are doing with the question mark but current value looks like this


for an individual device..
gets current value of the attribute.. are you trying to loop over them

The question mark in groovy is a null safe operator. It’s a shorthand way of checking a variable before using it

This article I think explains it.

It’s hard to say how to fix this without seeing more code. Devices could be a list which causes this error. As mentioned above you would want to use .collect but now you have to see what the code does with the results as that may break as well.