Virtual Device

I’m new to setting up a home automation environment and did little with my smartthings device before coming to Hubitat. Can someone point me in the right direction on how to setup a virtual device like a switch or other virtual
Devices? I’m not sure what values to use in the fields when creating a. New virtual device. Thank you.

1 Like

Devices: Add Virtual Device

There's only 3 mandatory fields, marked with *

Two of them are the same as for real devices. The Name you're calling it and the driver to use.

The unique one is the Device Network Id and it's a unique ID, anything you don't already have or maybe have in the future.

ZWave uses numbers, so a pure number would be a bad choice, for example. You can use anything else, and all of us have our own naming convention/pattern. For Presence virtual devices, for example, I use "presence-" and some number. It's not like there's going to be a hundred presence sensors here so I'm likely to remember which one I created first, etc.

For the most part, I just use an abbreviated form of the Name I'm giving it.

EDIT: Aug 2019
Hubitat now pre-populates the Device Network Id with a lengthy 'uuid' style value. That makes the field Optional now. Using the pre-populated value is probably the best practice.

2 Likes

Thank you!

I like to incorporate the date + 24 time as well.. something like DENSW1810150643

brand new and first of many stupid questions. what is the add virtual device for?

1 Like

The virtual device you are most likely to use is a virtual switch. A little hard to explain, but it allows you to create a switch that has no physical device attached to it.
It may be better to use examples:

I have a virtual switch for each room's motion lighting. The switch itself is attached to /controls nothing. But then, in my motion lighting apps in rule machine, I have it set that if that switch is on the motion lighting app should be disabled. So now I can change the virtual switch to on and it stops my lights from automatically turning on and off. I can also call that virtual switch from google home or alexa, and it can be shown in a dashboard.

Another example - I need to send a http command to my blue iris server to trigger the security cameras to record. I have a virtual switch that when turned on triggers a rule machine rule to send the http command.

The idea behind other virtual devices is the same.

Hope that helps!

1 Like

hmm. i think i get it. jut kinda like toggles for extra control

Exactly. But they can also be much more.

For another example (and honestly this was implemented in smartthings not hubitat - but the concept is the same), I have a window AC unit in a bedroom that I plugged into a zigbee outlet and a motion sensor that tells me the living room temperature.

I created a virtual thermostat and used some rules to set the virtual thermostat's current room temp to equal the living room motion sensor temperature. Then a rule that when the current temp was higher than the thermostat's cooling setpoint, it should turn on the zigbee outlet (which turns on the AC), and the opposite turns off the outlet.

I then linked the virtual thermostat to google home. It gave me voice control of the AC like I had central air and a smart thermostat. By voice (or also a dashboard) I could set the virtual thermostat to a desired temp, and the rules behind the thermostat would turn on the AC unit until the room temp matched the desired temp.

Allow me to describe an even more intricate example....

Presence Sensor.
My presence sensor is my iPhone. I can't connect my iPhone to Hubitat. It's connected to HomeKit. HomeKit sees my one device called Homebrige. HomeKit has automations that update a device -- either present or not. I have to somehow get a device, a switch, that can be turned on/off from HomeKit's automation.

Virtual Switch to the rescue!! :slight_smile:
I create a Virtual Switch in Hubitat, name it "my presence" or something equally brilliant and add it to the Homebridge app so that HomeKit sees it. Now I have an automation that works. A bit Rube Goldberg, but not too much. :slight_smile:

I arrive home (or depart) and my iPhone detects the geofence, informs Homekit, which runs the automation and turns on (or off) the switch. Homebrige informs Hubitat, and I can now run Rules based on that event and the state of the switch.

2 Likes

Another example. I have a space heater in my home office. I created virtual switch and set it to auto turn off after 1 second. I have a rule that watches that switch and turns on the heater, that rule also turns off the heater on false with a 15 minute delay. So even if I get distracted and leave my office I know it will go off after 15 minutes.

Because it's a switch, even a virtual one I can also call it from Alexa, use it with my button controllers, and also use it in other rules without having to redo the logic and programming of the 15 minute run rule.

1 Like

Do you use a motion switch to detect when there is no movement to trigger the delayed off? If not, how does it work when you leave?

Andy. Question please. I’m also trying to learn the functionality of the different options ( including virtual devices) and recently was searching for info.
Now that rule manager has options to comparetemp to, would yiu be able to control a smart plug directly without the virtual device in this scenario?

Similar question on the heater. Can that be done on rule manager now with a motion sensor?

Looking to see if i can find some uses for virtual devices but im thinking the feature improvements in rule manager 4 may make some previous setups more straight fowrawd now perhaps?
Appreciate your time.
Mac

Hi Mac. It's all going to depend on exactly what you want to do and personal preference. There is no right or wrong way. With the new options in rule machine, likely you may not need as many virtual devices. But I would say that virtual devices are still the best way (maybe the only way) to change a value from outside of rule machine - such as from a dashboard, or google home, etc.

One of the nice new features in rule machine is you can create a global variable and have a virtual device automatically created and linked to that variable (called a connector). Virtual devices are still very important / not going away.

The boards have a lot of great info. In the end though, I think you are going to have to just try all the options out and see what works best for you.

I'm trying to create a virtual switch, and set it to type "Generic Component Switch". I just want to use it sort of like a state variable that will keep some other rules from triggering over and over again for a period of about 20 minutes. However, I cannot seem to get or set any state for this switch. I assume I'm missing something here. I'm attaching a screenshot of the device setup page. You can see there is no "Current State" displayed.

I don't think you want "Generic Component Switch". Shouldn't you be using "Virtual Switch" instead?

I am not positive, but I think that Generic Component Switch is more for when you are using it within an app.

1 Like

Ah, thanks. I can see a Current State now. I didn't know there was a "Virtual Switch" type, but that makes sense. Guess I didn't scroll down that far. But I'm still a bit confused as to why Generic Component Switch didn't work. Anyway, now I can proceed to work on fixing my rule...

UPDATE: Rule works now! I was basically just trying to turn off my coffee pot after 20 minutes. I had a rule to trigger when the power draw exceeded 10W, but the thermostat in the coffee maker cycles on and off multiple times once it finishes brewing, just trying to keep the coffee warm. So, the rule would trigger each time, and my coffee pot would be going on and off for 20 minutes. Now the rule turns on the virtual switch, and won't trigger again if the virtual switch is still on. Thanks again!

I have a Yale Smart lock (swave plus version). Could I set up a virtual switch to Lock & Unlock the door from my dashboard (since my lock devices seems to have a lot of functions associated with the template)? How would that be set up? Also, can this virtual switch then translate over to Google Home?

It is possible to add the switch capability in the native driver of virtual thermostat ???

Yes.

Not sure if that has anything to do with it. Why can't you just use the dashboard lock template?

You would create the virtual switch. Then you would make a rule using Rule Machine to say (pseudo-code here) IF virtual switch is on THEN lock door. IF virtual switch is off, THEN unlock door. Or however you want it to work.

I don't know for sure what virtual devices Google recognizes (I don't use Google Home). Alexa has some limitations in this area. It would be easy enough to create a virtual device and see if Google recognizes it.