Easily Change Virtual to Group?

So would a virtual switch driver that just sends an event any time an "on" or "off" command is issued, regardless of the current state, work? You could try this as a driver (just threw it together quick, but I tested and it seems to work):

/*

 * ========+=============  Virtual Switch: State Change (Driver) =======+==================

 *

 *  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.

 *

 * =======================================================================================

 *

 *  PLATFORM: Hubitat

 *  PURPOSE: Virtual switch driver that always causes events (state change) with on() or off() comamnds,

 *           regardless of current device state.

 *  Last modified: 2021-04-05

 *

 *  Changelog:

 *  v1.0    - Initial Release

 */ 

metadata {

   definition (name: "Virtual Switch: State Change", namespace: "RMoRobert", author: "Robert Morris", importUrl: "https://raw.githubusercontent.com/RMoRobert/Hubitat/master/drivers/virtual-switch-state-change.groovy") {

      capability "Actuator"

      capability "Switch"

   }

       

   preferences {

      input name: "autoOff", type: "enum", title: "Automatically switch back to off this many seconds after being turned on:",

         options: [[0:"Do not automatically switch off"],[1:"1 second"],[2:"2 seconds"],[5:"5 seconds"],[10:"10 seconds"],[30:"30 seconds"]]      

      input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true

      input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true 

   }

}

void installed() {

   log.debug "installed()"

}

void updated() {

   log.debug "updated()"

}

void on() {

   if (logEnable) log.debug "on()"

   sendEvent(name: "switch", value: "on", descriptionText: "${device.displayName} is on", isStateChange: true)

   if (txtEnable) log.info "${device.displayName} is on"

   if (autoOff) {

      Integer disableTime = autoOff as Integer

      if (disableTime > 0) {

         runIn(disableTime,"off")

      }

   }

}

void off() {

   if (logEnable) log.debug "off()"

   sendEvent(name: "switch", value: "off", descriptionText: "${device.displayName} is off", isStateChange: true)

   if (txtEnable) log.info "${device.displayName} is off"

}
2 Likes