[RELEASE] Virtual Switch Universal Device Type (uDTH) - good for Alexa, IFTTT, HSM, and other integrations

EDIT: Now called Universal Virtual Device Switch uDTH in HPM.

This is a Virtual Switch that can also have the following capabilities/functions:
Switch: "on", "off"
Contact Sensor: "open", "closed"
Motion Sensor: "active", "inactive"
Presence Sensor: "present", "not present"
Smoke Detector: "detected", "clear"
Water Sensor: "wet", "dry"
Shock Sensor: "detected", "clear"
Sleep Sensor: "sleeping", "not sleeping"
Battery: 100, 0
Valve: "open", "closed"
(EDIT: I added a bunch more capabilities and features, see post 8 below for more info)

You can select which device types you want it to use (recommend using Motion or Contact if using with Alexa).
There is also the ability to have it auto-shut off (good for motion sensor virtual devices).

This could be used to integrate other systems or devices into Hubitat using IFTTT, Alexa, Webhooks or some other 3rd party platform.

It is similar to @mike.maxwell awesome SmartThings uDTH

If there are some other capabilities you would like added, or ways to improve it, let me know.


Does his happen to be in HPM? I didn't see it, but sometimes the search doesn't work so well.

1 Like

Nope. Relatively new to Hubitat, just switching over from SmartThings that I've been on for years. I'll look into adding it to HPM next week.



Any chance this could be updated with a virtual water shutoff valve? I just ordered a Tuya-Smart one (Chinese Cloud) and I will re-flash it with Tasmota (local only). I'm unsure how it will appear in Hubitat, so I might need a virtual Water Valve with a rule to have it update a switch status.

Hubitat Safety Monitor has a built in leak detector app that can shutoff a water valve upon detecting a leak. I want to stay with HSM if possible.


1 Like

@rick.guthier It's actually in there. I just have Valve functionality commented out so that the Open/Close functions/buttons don't show up for all devices.
Just uncomment the 4 lines with Valve functions (lines 21, 33, 48, and 61). Let me know if you need more help.

Nice! Thanks for this. Working great! I have a virtual valve, since for now my Tasmota water valve is a 'switch'. I have two 'Basic Rules' one to open and one to close, associated the virtual valve with the device. Now HSM closes the valve within about .2 seconds of the leak detector getting wet. All for just $32. My water main ball valve moves pretty easily so this thing's torque should be able to handle it.

Thanks again!

1 Like

I made some major changes. Added a lot more capabilities (see below for full list). In addition to the new capabilities, you can also add Valve, Button, Lock, and/or Door Control to this device driver by setting some flags in the code to true (see lines 13-16). Recommend using the least amount of capabilities needed for your devices. You can also save multiple copies of the driver code with the different Valve/Button/Lock/Door capabilities turned on and it will automatically updated the name of the device driver.
Added Force Status Update preference to be able to force a status update every time an action is requested regardless of current state. Ie If an app tries to turn the device On, it will send an On event, even if it is already On.

    capability "Switch"		//"on", "off"
    capability "Contact Sensor"	//"open", "closed"
    capability "Motion Sensor"	//"active", "inactive"
    capability "Presence Sensor"	//"present", "not present"    
    capability "Smoke Detector"    //"detected", "clear"
    capability "Water Sensor"      //"wet", "dry"
    capability "Acceleration Sensor" //"active", "inactive"
    capability "Shock Sensor"	//"detected", "clear"
    capability "Sound Sensor"	//"detected", "not detected"
    capability "Sleep Sensor"	//"sleeping", "not sleeping"
    capability "Battery"    //100, 0
    capability "FilterStatus"    //"replace", "normal"
    capability "TamperAlert" //"detected", "clear"
    capability "IlluminanceMeasurement" //1000, 0
    capability "Valve"    //"open", "closed"
    capability "Lock" // "locked", "unlocked"
    capability "DoorControl"  //"open", "closing", "closed", "opening"
    capability "GarageDoorControl" //"open", "closing", "closed", "opening"
    capability "PushableButton"
    capability "ReleasableButton"
    capability "HoldableButton"


I also added a Lite version for devices that only need Switch, Contact, Motion, or Presence (ie for Alexa, IFTTT, and other integrations). It is a lot more light weight and efficient for devices that don't need all of the capabilities listed above. Recommend using this device driver for devices that don't need all of the capabilities.


Added them to Hubitat Package Manager. Name is Universal Virtual Device Switch uDTH.


This is nice, I like the all in one approach and also the auto-off with longer time limits. I have a virtual motion sensor that I have an alexa routine turning on/off. I noticed one day the "motion" stayed on for hours which is impossible because its the front door bell. I can set one of the longer auto-off as a backup in case the routine doesnt fire.

Any chance of adding in some basic info logging with a toggle to enable / disable like many other drivers? Here is how it is on the driver I am using now, so for my device named "Front Door" it would log "Front Door motion is active". Not sure how to handle this if people have something setup with multiple capabilities though (not sure why you would want to have more than one?)

def on() {
	sendEvent(name: "switch", value: "on")
	sendEvent(name: "motion", value: "active")
	logTxt "motion is active"

def off() {
	sendEvent(name: "switch", value: "off")
	sendEvent(name: "motion", value: "inactive")
	logTxt "motion is inactive"

void logTxt(String msg) {
	if (txtEnable) log.info "${device.displayName} ${msg}"
1 Like

Will try to add logging tomorrow and get it up by Thurs am. If not will have to wait until Monday afternoon. I will probably just do On/Off.

I have a virtual presence sensor that is controlled by Alexa and IFTTT, therefore it uses Switch, Contact (needed for Alexa), and Presence (needed for HSM). The other option instead of just logging On/Off would be to do each capability it is using. If you can give me a good use case for that I'll do it, but we are adding to the complexity of the code and the size of the logs which may eventually impact performance.

The on/off logging would be sufficient and the easiest way to implement.

Curious for Alexa, why do you need the contact capability? Is that so you can TRIGGER routines in Alexa? I so far have only used switch with either motion or presence, but I have either Alexa or HomeKit turn them ON (like a switch), but want it to show as the motion or presence in Hubitat / Homekit.

Only Motion and Contact are Triggers for Alexa. Alexa can use Switches as Actions.

1 Like

I just used HPM to install this bad boy!

1 Like

So this is pretty cool if I am understanding this right. I will be able to clean up a lot of the extra virtual devices and their rules linking them when integrating for alexa IFTTT and other things.

1 Like

Great device drivers, thank you!

This is probably a dumb question, but what is the best way to be able to hit this via a Webhook? I'm struggling in figuring out what I need to do to expose this as a Webhook for an internal need v.s. IFTTT or Alexa which are more straight forward.

See this post here.
Internet Based Webhooks/Endpoints - Get Help / Integrations - Hubitat

also Maker API - Hubitat Documentation


I've added (and subsequently fixed) logging in both versions and updated HPM. Please check for an Update.

1 Like

@scottbarton76 Any chance you could add a Virtual Garage Door - Need a virtual device that has states of Open, Closed, Moving, Stopped, and Other.