Unfortunately the code for the built-in drivers are not made available. But if you need assistance with developing / enhancing a driver there are plenty of developers on this forum than can help with any questions you may have. If you want to ask a question though, perhaps post under another thread with a title relating to your question.
EDIT: By way of an answer I suggested you post in a different thread ... Scheduling options may be something that you need to look at. I may be able to assist by documenting some of the approaches I have taken in my drivers, but there are also notes on other threads.
I just threw this together quick (including some copy/paste from another driver I had already written ), and it is likely more or less how Hubitat's internal virtual switch driver was written if you do still want to use that as a starting point. To be clear, this is a "reverse engineered" community driver that is similar (identical?) in functionality; as mentioned above, the built-in drivers are (mostly) all closed-source:
There are a ton of community drivers and most are posted publicly. So you can always base a driver off what someone has written before and most developers are totally happy as long as you give them credit.
For example, I usually have a Thanks section at the end of my opening comments just before the actual code starts.
With the help I got from Robert Morris I was able to make the changes I wanted to the HTTP Driver I currently use. It's now tested and working just fine.
I am just posting it here in case anyone else finds it useful.
/*
* ====================== Virtual Switch (Community 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: HTTP Switch including "auto-off" functionality
* Last modified: 2021-06-29
*
* Changelog:
* v1.0 - Initial Release - Thanks to Robert Morris for his guidance in getting this to work.
*/
metadata {
definition(name: "HTTP Switch with Auto Off", namespace: "community", author: "Robert Morris/N Vass") {
capability "Actuator"
capability "Switch"
}
}
preferences {
section("URIs") {
input "onURI", "text", title: "On URI", required: false
input "offURI", "text", title: "Off URI", required: false
input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true
input name: "autoOff", type: "enum", title: "Auto off",
options: [[0:"Never"],[1:"1 second"],[2:"2 seconds"],[5:"5 seconds"],[10:"10 seconds"],[30:"30 seconds"]]
}
}
void installed() {
log.debug "installed()"
}
void updated() {
log.debug "updated()"
}
def on() {
if (logEnable) log.debug "Sending on GET request to [${settings.onURI}]"
try {
httpGet(settings.onURI) { resp ->
if (resp.success) {
sendEvent(name: "switch", value: "on", isStateChange: true)
}
if (logEnable)
if (resp.data) log.debug "${resp.data}"
}
}
catch (Exception e) {
log.warn "Call to on failed: ${e.message}"
}
if (autoOff) {
Integer disableTime = autoOff as Integer
if (disableTime > 0) {
runIn(disableTime,"off")
}
}
}
def off() {
if (logEnable) log.debug "Sending off GET request to [${settings.offURI}]"
try {
httpGet(settings.offURI) { resp ->
if (resp.success) {
sendEvent(name: "switch", value: "off", isStateChange: true)
}
if (logEnable)
if (resp.data) log.debug "${resp.data}"
}
}
catch (Exception e) {
log.warn "Call to off failed: ${e.message}"
}
}