currentValue of contact not supported for contact sensor?

code:

if (contactSensor)      ind = (contactSensor.currentValue("contact").contains('closed') ? 1 : 0);
else                    ind = -1

log:

app:16 2018-03-06 13:09:55.696:errorCommand ā€˜currentValue’ is not support by device. on line 1668

Any reason why contactSensor.currentContact == 'closed' can’t be used?

no particular reason but this seems to work:

if (motionSensors)      ind = (motionSensors.currentValue("motion").contains('active') ? 1 : 0);

any reason the same style would not work for contact sensor?

Gotcha. I thought for a second that might be working since it seems to be a map of multiple motion sensors, but after testing it quickly it still doesn’t work. I’d just go with what works for now since there’s no official documentation. currentValue() and current[attribute name] seem to have the same functionality.

I’ll test this tomorrow, as it makes no sense why this doesnt work…
In this instance, contactSensor is multiple:true?, or false…

1 Like

thanks. multiple:true

they do have the same functionality. but i use currentValue(ā€œattributeā€) all over the place and too lazy to write a regex to replace everything :grinning:

were you able to confirm why this one fails and when a fix would be available?

thanks.

its failing with every occurrence so cant get the app to work.

code:

log:

app:16 2018-03-08 18:37:27.610:errorCommand 'currentValue' is not support by device. on line 2411

This only fails against an input where multiple is true, which is a list, has nothing to do with the attribute name. For now just use an iterator.

thanks. yes had figured out that part already.

i am trying to keep the codebase the same for ST and hubitat. any word on when there will be a fix?

thanks.

Please submit an issue to support on this, we’ll then get it into our issues list.
For the time being you can use an iteration (find, findAll, each, collect ect), this will also work on your other platform…

Here’s a little javascript to regex it. It’ll convert .currentValue("contact") to .currentContact or any other attribute. I haven’t tested if current[Attribute] works on a map though.

1 Like

thank you. unfortunately this would not solve the issue though. see @mike.maxwell response above.

I just did a quick test and it works on a map. I know it doesn’t solve the currentValue bug but might be an easier transition until a fix is in place. Run it through the regex and copy the updated code to Hubitat. Or Mike’s suggestion is probably better to make a change that’ll work on both platforms.

didnt get this part :slight_smile:

whether its sensor.currentValue(ā€œcontactā€) or sensor.currentContact both are going to fail when sensor is multiple unless i use an iterator.

Hm, I might be missing something. It should work in the context of your first post:

if (contactSensor)      ind = (contactSensor.currentContact.contains('closed') ? 1 : 0);
else                    ind = -1

I tested this section and had no errors and returned true/false correctly. Is there another context where it won’t work?

1 Like

thought it didnt work without an iterator when contact sensors specified is multiple?

Worked for me testing with switches:

2018-03-08 21:57:44.864:debug switches.currentSwitch.contains('on'): false
2018-03-08 21:57:44.863:debug switches.currentSwitch.contains('off'): true
2018-03-08 21:57:44.861:debug switches.currentSwitch: [off, off]
2018-03-08 21:57:44.855:debug switches: [Backyard Light, Office Lamp]
1 Like

ahh … ok. wasnt expecting that based on that post. will check with contact sensors. if it works … i use atom for github personal stuff so these should work for me:

search: (\.currentValue\(")([a-z])(.+)("\))
replace: .current\U$2\L$3

will give it a try after i have confirmed.

thanks again.

1 Like