Virtual Switch for Alexa Devices

I made the switch from Smartthings and I am loving the switch but I am on the learning curve. With smartthings I used a virtual switch to control all my Alexa devices (mostly my wifi smart outlets). Does anyone have a step by step to get this up and running? Any assistance would be greatly appreciated.

It's pretty easy to create a virtual switch in HE, just go to the device page and look at the top right hand corner. Click "Add Virtual device"

If you have a Alexa routine already created, it should just be a matter of adding the switch to the Amazon echo skill on the apps page, then go to the Alexa routine and switch your ST switch for the HE switch.

1 Like

To expand a bit on what terminal3 said when you create the virtual device scroll down the drivers list and you'll find a group of various drivers all starting with the word Virtual and pick the appropriate one for the device you are trying to create. That might be obvious but I thought I'd mention it since you said you are still learning.

1 Like

Alexa can not read the state of switches on HE unless they changes something in the skill lately.

She can only see the state of locks, contact sensors, and motion sensors.

There is a custom device driver on here that can be used for a virtual contact switch but you would still need to recreate an Alexa routine to switch your wifi plug on and off for every state of the contact.

The best solution is to find if your wifi switches have a community driver for HE and move them over.

2 Likes

I read that two or three times wondering what you meant, but I think you meant read the state of the switch, which is true. I assume he meant he would use a virtual switch to initiate a rule in HE. I do that with several virtual switches, For example I tell Alexa to Open a shade and it turns a virtual switch on, which then triggers the rule in HE that actually opens the shade.

Whoops sorry for the typo.

When I read it I got that the wifi switches were connected directly to Alexa and he wanted some way to automate them from HE.

When I started I had Teckin SP10 wifi plugs connected directly to Alexa. I have since updated those to run tasmota and use @markus driver to connect them to HE.

Unless something changed, the state of a virtual switch can be "seen" from either HE or Alexa no matter which side - HE or Alexa - flips the switch. A change in state in a virtual switch can trigger a rule in HE. A change in state of a virtual switch in Alexa cannot trigger an Alexa routine.

A change in state of a contact can be seen by either and can trigger a rule in HE or an Alexa routine.

Thus you can use a virtual switch to have Alexa tell Hubitat something, e.g. "Alexa heard 'Good night'". But you cannot use a virtual switch to have Hubitat tell Alexa something, e.g. "Have Alexa announce "Good morning".

My preference is to use a virtual contact/switch (see https://raw.githubusercontent.com/stephack/Hubitat/master/drivers/Virtual%20Contact%20Sensor%20with%20Switch.groovy) so that I can set it like a switch, yet use it to initiate routines in Alexa.

12 Likes

I created the virtual switch on Hubitiat, now how do I get alexa device (wifi smart outlet) to be toggled on and off?

You used the Virtual Contact with Switch driver, right? So, next step is to go into the Alexa Echo Skill app on the Hubitat side, and authorize the virtual thing you created to be propagated to Alexa. Alexa should discover the device on her own, but if not tell Alexa "Discover devices".

Now in the Alexa app on your mobile device, create a routine so that when that contact opens, turn on your wifi smart outlet. And another one, when it closes, to turn it off (or similar).

1 Like

It worked, thank you. How do I do it with a lock? I have a wifi Schlage lock? It will only work once but then how do I make it go back to the other state? I tried auto off but it only works for a switch and not a contact sensor.

Just have Alexa, in the routine, turn off the switch. Alexa sees the virtual thing as both a contact and a switch, but you can only trigger her routines with contacts (or motion sensors .. just not switches).

Okay so I got the routine to lock the wifi lock when the contact switch opens, but how will the state of the virtual contact sensor go back to closed? The wifi lock will not lock again since the state of the contact sensor is open?

In the Alexa routine, make the last thing it does to turn off the "switch" of the virtual thing.

1 Like

tivo, When say drivers list you are talking the list to the right drop named type coreect? sorry only my 3rd day with HE

I meant this on the device driver page:

Hey y'all. I'm a newbie to Hubitat HE and having a bunch of problems getting stuff playing nicely. As well as Hubitat I also have Alexa and a Schlage Encode smart lock on the front door. I have worked out how to make the front door lock, but not unlock, due to a restriction in the Schlage skill. I do kind of value this override in case my Alexa account gets hacked (I'm less worried about the Hubitat lol) But it would be nice to somehow have this virtual contact open the switch and make alexa unlock from hubitat (even if it needs the PIN to do so..)

I kinda wish I got the Schlage Connect instead, but it wasn't in stock.. Oh well :confused:

For anything that Alexa recognizes as a security related device you need to go into the Alexa app and add a PIN for the device. It will prompt you for the pin before opening/unlocking. (I was going to give you some screen shots but it appears that Alexa’s app can’t find the servers this mornin’ - devices are working but…)

OK, I'm tryng to do something much more simple now. I've got Alexa, the HE, and a garage door. I'm using a Shelly One to open then close the door. I want to be able to say "Alexa open the garage door" or "alexa close the garage door"... Or maybe even ask her if it's open or closed. Seems simple right? Well I'm using Stephen Hackets' Virtual Contact Sensor with Switch driver and Alexa sees it as a switch (though it has the convenient option of treating it as a lightbulb). I've set up automation in HE to pulse the Shelly on then off for a second when the vswitch changes state. Telling Alexa to 'turn on' the garage door doesn't roll off the tongue. Queue the Virtual Contact Sensor driver. That seems to show as "open" or "closed" in Alexa's devices menu but when I ask her to open or close the garage door she tells me that the device "doesn't support that". Seriously!

I've also got a Sonoff SNZB zigbee contact sensor on the garage door which is nice except for the fact my damn HE can't hear it without a router in the middle even though its a matter of metres away from it...but that's a different issue. Maybe if I could get that to work I could expose THAT to Alexa and then..I don't know??

Physical contact sensors detect open/close but don’t allow you to set them, thus Alexa, in this instance, is correct. You could use a custom Alexa routine to issue a turn on/off when it hears open/close to get around this.

Ah you're right. Just for once, Alexa actually is doing the right thing!
So... In lieu of getting my REAL contact sensor going I could do something like this

  • expose a virtual contact sensor and a virtual contact sensor with switch (or just a virtual switch) to Alexa
  • Setup a routine for Alexa to flip on the virtual switch when she hears "open the garage door" or "close the garage door"
  • Setup Hubitat basic rule to turn the Shelly on, wait a second, turn it off when it sees that switch flipped, and then update the virtual contact sensor status with the opposite of what it currently is (open/closed)

Then when I resolve my ridiculous zigbee range issue I can expose the real garage door contact sensor to her instead? Hmm let me try all this...