/* Contact Sensor Close / Motion Sensor Inactive * Licensed Virtual 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. * */ static String version() { return '0.0.2' } definition ( name: "Force Sensor Close-Inactive", namespace: "thebearmay", author: "Jean P. May, Jr.", description: "Sends inactive/close event to designated sensors.", category: "Utility", importUrl: "https://raw.githubusercontent.com/thebearmay/hubitat/main/apps/forceClose.groovy", oauth: false, iconUrl: "", iconX2Url: "" ) preferences { page name: "mainPage" page name: "deviceCharacteristics" } def installed() { log.info "${app.name} v${version()} installed()" state?.isInstalled = true state?.singleThreaded = true initialize() } def uninstalled() { log.info "${app.name} v${version()} uninstalled()" removeDevice() } def updated(){ // log.trace "updated()" if(!state?.isInstalled) { state?.isInstalled = true } if(debugEnable) runIn(1800,logsOff) } def initialize(){ } void logsOff(){ app.updateSetting("debugEnable",[value:"false",type:"bool"]) } def mainPage(){ dynamicPage (name: "mainPage", title: "", install: true, uninstall: true) { if (app.getInstallationState() == 'COMPLETE') { section("Main") { input "qryDevice", "capability.contactSensor", title: "Contact Sensors Selected:", multiple: true, required: false, submitOnChange: true input "qryDevice2", "capability.motionSensor", title: "Motion Sensors Selected:", multiple: true, required: false, submitOnChange: true input "createChild", "bool", title: "Create Button Device?", defaultValue: false, submitOnChange: true if(createChild) { addDevice() } else { removeDevice() } if (qryDevice != null || qryDevide2 != null) href "deviceCharacteristics", title: "Send Close-Inactive Event", required: false } } else { section("") { paragraph title: "Click Done", "Please click Done to install app before continuing" } } } } def deviceCharacteristics(){ dynamicPage (name: "deviceCharacteristics", title: "", install: false, uninstall: false) { section(""){ closeContacts() qryDevice.each{ paragraph "

${it.displayName} ${it.currentValue('contact')}

" } qryDevice2.each{ paragraph "

${it.displayName} ${it.currentValue('motion')}

" } } } } def closeContacts(evt = "pushed"){ qryDevice.each{ it.sendEvent(name:"contact",value:"closed",isStateChange:true) } qryDevice2.each{ it.sendEvent(name:"motion",value:"inactive",isStateChange:true) } } def addDevice() { if(!this.getChildDevice("cscButton001")){ addChildDevice("hubitat","Virtual Button","cscButton001",[name:"Close Contact Button"]) chDev = this.getChildDevice("cscButton001") subscribe(chDev, "pushed", "closeContacts") } } def removeDevice(){ unsubscribe() if(this.getChildDevice("cscButton001")) deleteChildDevice("cscButton001") } def appButtonHandler(btn) { switch(btn) { default: log.error "Undefined button $btn pushed" break } } def intialize() { }