[ST Edge] Access to _envlibrequire("devices")

I am trying to use Driver:try_create_device(device_metadata)
The code is being executed until the end, but still no device is created.

So I am trying to understand what is happening and am stuck at these lines…

-- lua_libs-api_v0/st/driver.lua

local devices = _envlibrequire("devices")

...

return devices.create_device(metadata_json)

I saw in the docs ( Driver — SmartThings Edge Device Drivers documentation ) that this command doesn’t create a device, but only sends a request to create it.

I don’t know what I am missing or doing wrong.

So my question: Is there anyway to access _envlibrequire("devices") ?

What type of driver are you working on? That method currently is only supported for LAN drivers, not zigbee or z-wave.

Assuming LAN, the code below works for me. I think the only critical pieces are that type is LAN, device_network_id is unique, and profile matches one of the profiles in your driver. All the others can be whatever string you want.

  local create_device_msg = {
                              type = "LAN",
                              device_network_id = id,
                              label = 'Initial Device Label in ST App',
                              profile = device_profile,
                              manufacturer = 'Manufacturer Name',
                              model = 'Model Name,
                              vendor_provided_label = 'Vendor Label',
                            }
  assert (driver:try_create_device(create_device_msg), "failed to create device")

So you’re saying that if it doesn’t match these 3 parameters, then the device is not created. Is that right?
I will recheck mine. Thanks.

local metadata = {
  type = "LAN",
  profile = "child-smart-plug.v1",
  manufacturer = device:get_manufacturer(),
  model = device:get_model(),
  vendor_provided_label = "Child Smart Plug",
  device_network_id = device.device_network_id .. ":0" .. index,
  parent_device_id = device.id,
  label = "Child Smart Plug " .. index,
}

index comes from a for-loop.

Due to the LAN limitation, I tried 2 approaches, both being called at init lifecycle handler of the zigbee device:

  1. zbDriver:try_create_device(metadata)
  2. lanDriver:try_create_device(metadata)

I think doesn’t matter zbDriver or lanDriver as both will end up at the same implementation mentioned in the first post of the thread.

The second approach, I am doing something similar to this:
init.lua

local zigbee_driver = ZigbeeDriver("zigbee-smart-plug", driver_template)

local lan_driver = Driver("child-smart-plug", require('child'))

zigbee_driver:run()

lan_driver:run()

config.yaml

name: 'Zigbee Smart Plug'
packageKey: 'br.com.wesley.zigbee-smart-plug'
permissions:
  zigbee: {}
  lan: {}
  discovery: {}

In other words, due to this LAN limitation, I am trying to do a mix.

If you get that to work, you’ll be the first. I’d also caution that, if you find a loophole, it might be closed in the future.

My impression of the way things are headed is that components are replacing child devices for zigbee/z-wave devices. I don’t expect to ever see official support for zigbee/z-wave child devices in Edge drivers. The difficulty right now is that components don’t provide the same user experience as child devices - they can’t be renamed, they don’t display on the app dashboard, they don’t integrate with voice assistants, and they don’t present well in the automation screens. I’m hoping that there’s work being done behind the scenes on those issues, and that there an update sometime before Edge moves out of beta that makes components more viable.

1 Like

Totally agree with everything you said about advantages of the child devices.
Hope they will think fondly about availability of child devices in zigbee/zwave drivers.
I will not go deeper into this subject because it fulfills another thread.

1 Like

Just to let people know, I found out the first “:run()” prevents the second one from executing.
So back to the drawing board.

I will study the API a little more.

Maybe 2 drivers installed separately will do the trick.
Or some kind of communication among drivers.

UPDATE
I was able to create LAN child devices as a ZIGBEE subdriver. I had to override some methods to make it work.
Also, I found out defining parent_device_id was causing the problem of not creating/showing child devices as I am mixing these device types.

I didn’t like the solution, but this is my only option to circumvent the LAN child device limitation.
Again, hope zigbee child devices will be offered natively.

I will update the post later soon with the link to the code.

My driver is under tests with unusual test cases.

UPDATE 2
Here is the link of working ZIGBEE driver with LAN child devices…

References:
rawset (table, index, value)
Driver.try_create_device

3 Likes