[Release] Virtual Container Driver

Update: 11/17/19
v1.1.20181118


Update: 11/17/18
Virtual Container v1.1
v1.1.20181115

PLEASE NOTE THAT CODE IS IN A NEW LOCATION (SEE BELOW)
IF UPDATING FROM OLDER VERSION, PLEASE HIT THE REFRESH BUTTON AFTER UPDATING


Update: 10/14/18


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.

Hubitat/Virtual Container.groovy at master · stephack/Hubitat · GitHub

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:

15 Likes

Thanks I love it get things tidied up at last? Pity there ist away to organize rules better?

2 Likes

Yea this is a really nice way to handle this under the current operating constraints. As always Hubitat will one day hopefully evolve to make things more organized and replace this but see below gif...

Edit ( lame size restrictions, oh well it looked good in preview... What is this 2005?)

Loving this!! but hating the thought of recreating 40 virtual switches.
Any way to retrospectively get those virtual devices linked to a "Virtual Container"? :wink:

2 Likes

I truly wish there was a way but unfortunately not. I went through the pain of recreating most of mine. I didn't hurt as much as I thought but it definitely wasn't painless.

Just do a few at a time.

1 Like

Oh man, thats p****d on my chips :smiley: I kind of thought as much, but if you don't ask......
I think I'll wait for one of those days at work, where I'm working, just not on work :wink:

I'm doing the same as yourself for music, so thats a lot of switches, and a lot of rules, not to mention dashboards. But, I thinks certainly worth it and cheers for sharing. :+1: Its an awesome way of doing it.

1 Like

So I tried this out. Might be a lack of my understanding.
How does one access the device page of the child device?
When I click a child device it brings me to the parent.

??
Can you post a screenshot?

Sure
Clicking here:

Brings me here:

Maybe I missed a step. I installed it under "Drivers Code". At first I tried App Code because I thought there was no way DTHs could create children, but I was wrong. It succeeded. I can try again if you think I missed something.

I'm about to get on the road but will assist when I get home. There really arent any steps to miss.

What browser are you using?

When adding the Virtual Switch did you have the Type = "Switch" ? I didn't at first, and didn't see the device. I then used "Switch" and now all good.
I've created a load and working great.

Good point. I chose Momentary. Let me try switch.

1 Like

Same result with Switch.

Weird. Maybe try removing all and trying again?

I don't know if you need to, I created as "Virtual Container" and then renamed afterwards. Just plugged in a Device Network Id, and then saved. Then started creating the Virtual switches.

If you type an invalid entry in TYPE you will get an error in ther logs and nothing will be created. That's not the issue.

@keithcroshaw It could also be because you have a space in the container dni. I have seen that cause weird issues in the past.

1 Like

So I deleted the Parent Device, which deleted the Children... I hope...
Then I recreated the Container with no spaces and two Children, each with no spaces and see the same results.

I see a log entry that says: "Please choose a valid device type..." I'm using Teamviewer, maybe it's sending hidden characters? I tried CamelCase and all lowercase.

Edit: Lowercase was what failed. "Switch" yields the same result.

Yeah...its case sensitive.
What browser are you using?

1 Like

Also, I'm not home so I cant verify, but I believe you can get the device I'd if you hover your mouse over the child link. You can then manually enter the url.
yourHubIP/device/edit/yourDeviceId

Let me know if this at least brings up the device page.

Good question. Safari, which I only use when I'm remote.
Usually I use Chrome which I can try later.

Download the Hubitat app