I have a driver that reproduces the HA MQTT Discovery mechanism. It was fairly easy to reproduce; hopefully I won’t get a cease and desist letter for replicating it on SmartThings
This driver is modeled after a Home Assistant solution, and as @jpeden explained above, is a general-purpose way to create and update basic SmartThings devices via MQTT messages. These messages can be initiated through configurable MQTT-enabled applications, or custom applications or scripts running on your home network. It’s quite easy to set up, and requires no programming expertise to implement.
I’ve stayed true to the HA-defined format for discover and state update topics and included the ability to have SmartThings capability commands sent back to the device at a configured topic.
Topic format for device creation and state updates:
smartthings/<type>/[nodename/]<uniquename>/<config | state>
- ‘smartthings’ is mandatory topic prefix
type is device type (currently: switch | light | plug | momentary | motion | presence)
nodename is an optional name identifying the source node [a-zA-Z0-9_]; no other special characters or spaces
uniquename is a unique identifying name for the device; [a-zA-Z0-9_]; no other special characters or spaces
- ‘config’ indicates device creation, ‘state’ indicates device capability attribute update
More device types can easily be added, but is dictated by SmartThings capabilities, rather than the HA list of supported types.
For device discovery, I have a couple different ways it could be implemented. One is to only create new MQTT devices at the request of a SmartThings Add device / Scan nearby devices. The second approach is to create them any time a config topic message is received.
At the moment, I’ve gone with the latter approach. I’m not sure how well the SmartThings platform - especially the mobile app - will handle this latter approach. The devices do appear spontaneously, but their functionality suffers from initial delays and the typical SmartThings app hiccups that occur while it’s still trying to update all the devices. The other interesting aspect is that it is awfully easy now to rapidly create a proliferation of SmartThings devices programmatically from any LAN-connected thing that can publish MQTT messages!
I invite anyone to try this out and give me your thoughts.
Pre-requisite: Must have an operating MQTT broker on your LAN (e.g. Mosquitto)
Driver is available on my test channel; from the available drivers list, install MQTT Handler V1
Once available on hub, from mobile app, do an Add Device / Scan nearby devices, and a new device called MQTT Discovery will be created in the ‘No room assigned’ room.
Open the MQTT Discovery device and go into Settings and configure the MQTT broker IP address (IP only, no port; secure connections or authorization not yet supported). This has only been tested with Mosquitto as broker.
After saving the broker IP address, return to the device Controls screen and tap the Refresh button. The driver will now connect to broker and subscribe to topics ‘smartthings/#’
Using an app like mosquitto_pub, create a new device (e.g. switch)
mosquitto_pub -h localhost -t “smartthings/switch/myswitch/config” -m “create it!”
Note that the message content is unimportant, and Retain option is optional (unlike HA)
Update the state of the switch:
mosquitto_pub -h localhost -t “smartthings/switch/myswitch/state” -m “on”
mosquitto_pub -h localhost -t “smartthings/switch/myswitch/state” -m “off”
Created SmartThings MQTT devices can be configured to publish capability commands to a chosen topic. This is configured in device Settings. Note that this is implemented only for the devices containing switches (switch, plug, light) at the moment.