Virtual Container v1.1
PLEASE NOTE THAT CODE IS IN A NEW LOCATION (SEE BELOW)
IF UPDATING FROM OLDER VERSION, PLEASE HIT THE REFRESH BUTTON AFTER UPDATING
This driver is simply a way to easily create and organize virtual devices in Hubitat.
I created this because, the more I built automations, the more I realized that I need to create multiple virtual devices to keep things in sync with hubitat. I created a version of this in ST (for different reasons) but realized it would be very beneficial for someone like me in HE. I hate having scattered Virt Devices with names that were difficult to remember and tricky to find. This is what most of my Virtual devices look like now.
You create a new virtual device of type "Virtual Container" (see link to code below). This will be the parent driver. From this driver you can create multiple types of child drivers using the built-in HE virtual drivers (and @Cobra's custom drivers if selected).
- Virtual Switch
- Virtual Momentary (Switch with autoOff set to 500ms)
- Virtual Dimmer
- Virtual Button
- Virtual Presence
- Virtual Motion Sensor
- Virtual Contact Sensor
@Cobra custom drivers are also available if the option is chosen in Preferences
- Average All Device
- Custom WU Driver
- Switch Timer
- Virtual Presence Plus
- Weewx Weather Driver - With External Forecasting
For QUICK CREATE - select the type of device you wish to create from the dropdown and click the "Save Preferences" button. Then type in the LABEL and click the QUICK CREATE button. This will create a virtual device of the type selected in the template. When you refresh your device list you should see the newly added child device under the parent container.
For CREATE DEVICE - This will be used to create any drivers (installed on your hub) that are not included in the Quick Create Template. Enter the relevant field and click the CREATE DEVICE button.
Both quickCreate(label) and createDevice(label, type,namespace) can be called from other smartApps to dynamically create virtual devices. For example, I use this to create momentary switches that launch various playlists on my Sonos Speakers.
This is why I also added a cycle() command. This cycles through all the devices in the container and can be set to do the following: Turn on, Turn off or Toggle the state of each device in the container. If the device is a Button device it will always push button 1. If the device does not support on,off or push, it will do nothing.
The setLevel() works similarly, except that it operates one specific device. SetLevel(3) will "operate" the 3rd device in the container. This can be used with Alexa as well eg "Set Family Room Presets to 3" will start my Dinner playlist on my Family room Sonos speaker.
Hopefully some in the community will find this useful.
App Developers Only:
The apiCreateDevice() method was designed specifically for use in smartApps that need bidirectional communication with the child devices in a container.
See documentation on how to use here: