diff --git a/switchbotScene b/switchbotScene new file mode 100644 index 0000000..c7aa45c --- /dev/null +++ b/switchbotScene @@ -0,0 +1,39 @@ +/* + +Copyright 2021 - Nick Betcher (@nbetcher) + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +------------------------------------------- + +Change history: +0.1.0 - @nbetcher - Initial release. + +*/ + +metadata +{ + definition(name: "SwitchBot Scene", namespace: "tomw", author: "tomw", importUrl: "") + { + capability "Momentary" + } +} + +def push() { + def id = getParent()?.getId(device.getDeviceNetworkId()) + if(id) + { + def respData = getParent()?.executeScene(id) + runIn(2, refresh) + } +} diff --git a/switchbotSystem b/switchbotSystem index 2c5b931..5c69732 100644 --- a/switchbotSystem +++ b/switchbotSystem @@ -17,6 +17,7 @@ limitations under the License. ------------------------------------------- Change history: +0.9.7 - @nbetcher - Added Scene device support as a virtual driver. 0.9.6 - @tomw - Added Humidifier support. 0.9.3 - @tomw - Modified child device creation to reduce confusion around grouped Curtain devices. 0.9.0 - @tomw - Initial release. @@ -123,6 +124,19 @@ def checkCommStatus() def createChildDevices() { def devices = getDevices() + def scenes = getScenes() + + if (scenes) + { + for (it in scenes) + { + logDebug("Scene = ${it}") + if((it.sceneName && it.sceneId) && !findChildDevice(it.sceneId, 'Scene')) + { + createChildDevice(it.sceneName, it.sceneId, 'Scene') + } + } + } if(!devices) { @@ -205,7 +219,7 @@ def createChildDevice(name, id, deviceType) def child try { - if(!["Bot", "Curtain", "Meter", "IR Device", "Humidifier"].contains(deviceType.toString())) + if(!["Bot", "Curtain", "Meter", "IR Device", "Humidifier", "Scene"].contains(deviceType.toString())) { logDebug("createChildDevice: deviceType not supported") throw new Exception("deviceType not supported")