How to access device settings from SmartApp

Is it possible to read device settings from SmartApp?

I have tried:

In Device:
preferences {
input(“myDeviceId”, “text”, title: “Device ID”)
}
def myDeviceId()
{
return settings.myDeviceId
}

in SmartApp:

device.myDeviceId()

  1. Returns null if myDeviceId is defined as command
  2. Throws exception if myDeviceId is not defined as command

No, it’s not possible. The smart app cannot “call” a function defined in another app or device. What may look like a function call, e.g. “myswitch.off()”, actually sends a command to the device, but since commands are asynchronous, it cannot return anything. There’s one exception to this rule: a child device can call a function defined in the parent app.

1 Like