ey everyone,
We’re working on an MQTT driver that uses a “Creator” device to dynamically create virtual energy meters. Needless to say, we had a heck of a time trying to get EDGE_CHILD devices to spawn…
We ran into the “Silent Rejection” issue: the log says everything is fine, try_create_device runs, but the device is nowhere to be found. After days of debugging and digging through the forums (thanks to everyone for the previous posts!), we finally figured it out.
It seems the platform is dead serious about how child devices are created, and there’s a “holy trinity” of parameters that, if you don’t get them exactly right, it just silently drops your request.
The code that finally worked:
Here’s our create_energy_device function that’s now doing its job. The magic is all in the new_device_args table.
-- Required libraries
local log = require "log"
local socket = require "cosock.socket"
local utils = require "st.utils"
-- ...
function create_energy_device(driver, device, command)
local deviceName = command.args.deviceName
if not deviceName or deviceName == "" then
log.warn("Device name cannot be empty.")
return
end
log.info(string.format("Creating new virtual energy meter named '%s'...", deviceName))
-- Generating the key to make sure it's unique
local child_key = "MQTT_Energy_" .. deviceName:gsub("%s+", "_") .. "_" .. socket.gettime()
-- The "Holy Trinity" - the key part that was missing
local new_device_args = {
type = "EDGE_CHILD",
parent_device_id = device.id,
parent_assigned_child_key = child_key,
label = deviceName,
profile = "mqtt-energy-st-energy.v1",
manufacturer = "SmartThingsCommunity",
model = "Virtual-Energy-Meter"
}
-- Just in case, logging what we're sending
log.info("Sending device creation request with the following metadata:")
log.info(utils.stringify_table(new_device_args))
local success, err_msg = driver:try_create_device(new_device_args)
if success then
log.info(string.format("Creation request for device '%s' sent successfully.", deviceName))
else
log.error(string.format("Failed to send creation request: %s", tostring(err_msg)))
end
end
Our key takeaways were:
-
typeabsolutely must beEDGE_CHILD. -
parent_device_idis mandatory. -
You have to use
parent_assigned_child_keyinstead ofdevice_network_id.
So, our question to the more experienced folks here: Does this look right to you? Is there anything we missed or could be doing better?
Thanks in advance for any feedback!