Custom Driver Command returning strange result

Hi all,
I have a custom device with a custom driver that I'm using to store information I want available to multiple apps. The custom device is called "Room Monitor Device" and some simple commands like:

Device Code:

        command "getAllRooms"
        command "getRoomInfo", ["string"]        
        command "getOccupiedRooms"  
...
HashMap getAllRooms() {return state?.rooms}

HashMap getRoomInfo(roomID) {
    log.debug "getRoomInfo: returning ${state?.rooms[roomID]}"
    return state?.rooms[roomID]
}

HashMap getOccupiedRooms(HashMap roomStatus = state?.rooms) {return roomStatus?.findAll{it.value.isOccupied == true}}

When I run these commands from the device page, it produces the correct response. When I call those commands from a custom application, the device debug log records the correct response but the application does not.

Application Code

            def roomInfo = roomsDevice.getRoomInfo(id)
            if (functionLogEnable) log.debug "refresh: roomInfo: ${roomInfo}"

Log Entries:

app: debug refresh: roomInfo: 2689354
dev: debug getRoomInfo: returning [motionDevices:1450, airConditionerMode:auto, water:dry, roomName:Great Room, freezeDevices:1238, HVAC Device Powered:off, commStatus:ok, freeze:clear, coolingSetpoint:66, humidityDevices:1331, temperature:49.6, humidity:47, tempDevices:1331, hvacDevices:1303]

The same is true for all of the custom commands I wrote. They all produce some number that starts with "2689" with the last 3 numbers incrementing.

Any ideas?

Is this a parent/child app? If so, that should work, but a more complete example might show what's going wrong where.

If it's an arbitrary app that has selected this device as an input/setting, it won't work. Commands can't "return" values -- they are just something an app (or the user) can execute on a device. (Internally, the driver may very well return a value from the method that implements the command for other reasons, e.g., sending a Z-Wave or Zigbee command -- one use for return values from driver commands at the platform level.) To get something an arbitrary app can access, you'd need a device attribute or other way of sharing this information -- or, of course, to make them parent/child.

1 Like

Ah, well you live and learn!

Yes, it's an arbitrary app that has selected the device as a setting. I didn't realize device commands couldn't return values :frowning:

Indirectly related question, if an app has access to a device (by selecting it in the app settings) does it automatically have access to the child devices fo said device?

No, from the perspective of an app, parent and child devices are all completely separate.

You could send a command to the parent that then sends a command to a child (or children). So you would only ever need to directly "talk" to the parent.

1 Like

Understood, but what I'm trying to do is get some dynamic data back from the Device, hence attributes don't really work for me.

Is getDataValue() available to apps or just to the device itself?

Yes, that is available on any device reference: getDataValue(), along with ways to write/update and remove such values (though regarding the specific concern of being "dynamic" I'm not sure what this would do for you that an attribute wouldn't).