Start the discovery for Zwave or Zigbee through Alexa

Running inclusion for the Zwave and Zigbee Bindings to add a device can be a logistics challenge. Discovery needs to be started in Habmin or PaperUI, and then you need to run to the device to put it into inclusion mode. This is what I setup so that I can just ask Alexa to turn on discovery. I use the HueEmulation Binding, but this should work with the skill too. This could easily be expanded for exclusion too.

Switch    Zwave_Discovery    "Z-Wave Discovery"    ["Switchable"]    {autoupdate="false"}
Switch    Zigbee_Discovery   "Zigbee Discovery"    ["Switchable"]    {autoupdate="false"}

rule "Start zwave discovery"
when
    Item Zwave_Discovery received command
then
    val String discoveryResponse = executeCommandLine("/bin/sh@@-c@@/usr/bin/curl -o /dev/null -s -w \"%{http_code}\" --connect-timeout 10 -m 10 -X POST --header \"Content-Type: application/json\" --header \"Accept: text/plain\" \"localhost:8080/rest/discovery/bindings/zwave/scan\"",10000)//start discovery
    logDebug("Rules", "Start Zwave discovery: Response=[{}]",discoveryResponse)
end

rule "Start zigbee discovery"
when
    Item Zigbee_Discovery received command
then
    val String discoveryResponse = executeCommandLine("/bin/sh@@-c@@/usr/bin/curl -o /dev/null -s -w \"%{http_code}\" --connect-timeout 10 -m 10 -X POST --header \"Content-Type: application/json\" --header \"Accept: text/plain\" \"http://localhost:8080/rest/discovery/bindings/zigbee/scan\"",10000)//start discovery
    logDebug("Rules", "Start Zigbee discovery: Response=[{}]",discoveryResponse)
end
6 Likes

This is great! Thanks for sharing.

Confirmed, works.
Amazing piece of code (for us non programmers) :heart_eyes: