Alexa Integration - Virtual Switch/Button. etc

Just to add my 2 cents, Alexa has been automatically recognizing my new additions once its added in HE / Alexa. Haven't had to ask her to discover.

5 Likes

I wanted to add my solution to the fact there was no "button" functionality to expose in the Alexa Skill app:

Hubitat developers were super clever to be able to make a virtual switch automatically shut off after a predetermined amount of time.

So Alexa "turns on the switch" in the Alexa app/routine, I've got a Rule Machine rule kicked off when the switch becomes on, and then Hubitat automatically turns it off (effectively resetting it for next time the Alexa routine runs)

I hope that makes sense

1 Like

I use @ogiewon virtual motion-switch for this.

Virtual switches don't show up for me under 'When this happens' when setting up a routine in Alexa. They do show up under 'Add actions'. The virtual motion-switch shows up under both.

How are others getting virtual switches to show up for 'When this happens'?

2 Likes

I've done this before, but it doesn't show in the "When This Happens" menu... which is what's required for Alexa to react to smart home operations. Do you know how to get this to be added to the "When this Happens" trigger?

Just updating this thread with my findings... someone from another forum told me the Virtual Contact Sensor shows in the "When This Happens" menu and I tested it to confirm does work. I will build my automation announcements off this workaround until there is a Virtual Echo Button or Alexa Speaks becomes a little more stable. Thanks for the responses everyone!

1 Like

Sorry, didn’t saw that you wanted the device to show under “When this happens”. Good that you found a solution.

It does but it doesn't automatically close itself (turn off). You will have to run a custom action to open it and then again to close it every-time. If you use the virtual motion/switch you won't have to do that.

You also won't be able to trip the contact sensor from Alexa to HE.

The motion/switch will allow HE to trigger Alexa and have Alexa trigger HE.

2 Likes

Has anyone came up with a solution? In SmartThings(ST) I could press my ST button next to my bed which would trigger a command in Alexa to start my music and turn on my 13 infrared candles using my Broadlink repeaters.
To create this action I would use bjpierron's Simulated Alexa Switch and their Button ST device handlers. This handler would show virtual switches as device handlers in Alexa's Smart home. These virtual switches could be used as devices in "When this happens" to trigger an Alexa routine. I can not get this to work with Hubitat.
I also created 18 virtual buttons in ActionTiles to run my 6 music playlists in three zones. Once again no way to accomplish this in HT.
This link shows more detail. How To Make Any Alexa Enabled Device Work With SmartThings

I have a SmartThings button in a kids room that they can slap to have Alexa play some music for them.
I have a button controller set to turn on a particular virtual switch that is also seen in Alexa as a Contact Sensor when the button is pressed. When the switch is on, the contact sensor is open and when the switch is off the contact sensor is closed. Then I use the opening of the contact sensor to trigger an Alexa routine that includes turning off the virtual switch that closes the contact sensor setting up the next button press to turn the virtual switch on.

/*
 * Virtual Contact Sensor with Switch
 *
 * Created by Stephan Hackett
 * 
 */

metadata {
    definition (name: "Virtual Contact Sensor with Switch", namespace: "stephack", author: "Stephan Hackett") {
		capability "Sensor"
        capability "Contact Sensor"
        capability "Switch"
		
		command "open"
		command "close"
    }
	preferences {
        input name: "reversed", type: "bool", title: "Reverse Action"
	}
}

def open(){
	sendEvent(name: "contact", value: "open")
	if(reversed) switchVal = "off"
	else switchVal = "on"
	sendEvent(name: "switch", value: switchVal)
}

def close(){
	sendEvent(name: "contact", value: "closed")
	if(reversed) switchVal = "on"
	else switchVal = "off"
	sendEvent(name: "switch", value: switchVal)
}

def on(){
    sendEvent(name: "switch", value: "on")
	if(reversed==true) contactVal = "closed"
	else contactVal = "open"
	sendEvent(name: "contact", value: contactVal)
}

def off(){
    sendEvent(name: "switch", value: "off")
	if(reversed==true) contactVal = "open"
	else contactVal = "closed"
	sendEvent(name: "contact", value: contactVal)
}

def installed(){
	initialize()
}

def updated(){
	initialize()
}

def initialize(){
	sendEvent(name: "switch", value: "off")
	sendEvent(name: "contact", value: "closed")
	
}
4 Likes

when i try to use the virtual contact sensor with switch i can't see it in the when this happens menu on alexa. It seems others in this thread can see it there....what am i doing wrong?

You have shared it with Alexa correct? Here is one that I have, this is the device setting page in the Alexa app. You'll notice that it says 'Virtual Contact Sensor with Switch' does yours say that?


In Alexa routines I use the device to trigger a routine when the contact sensor opens/switch turns on.

I use Rule Machine to turn on the switch when my son presses a button in his room. RM then turns the switch back off. All this so he can make his Echo fart on command.

1 Like

I had the same issue until I learned that a VS won't migrate to Echo, you need to use a custom driver such as Virtual Contact with Switch. You open/close the VS which passes the On/Off to Echo... Easy as 1-2-3

check it out by @cwwilson08

yea you nailed it. I fixed it last night then seen your post this morning. Thanks for the reply though.

Ok, so realized the virtual button vs switch issue. Indeed button doesn't show in Alex but switch does. However HSM seems to require a button device for arming/disarming. Trying to allow Alexa to Arm HSM...any advice welcome.

You can use a driver that includes both the Button capability and the Switch capability. There are several floating around the forums, but I have one I use for myself:

Alexa will see it as a switch and HSM will see it as a button. It also includes the Contact Sensor capability so that you can use it to trigger Alexa routines.

2 Likes

This was very helpful! I was able to create virtual motion sensor-buttons that Alexa recognized, which I could then use to create routines to control Alexa devices using Hubitat buttons (which I could then import into my dashboards).

Thank you!

1 Like

This is a very useful thread, and I used this technique of creating a Virtual Contact Sensor and a "Rules Machine" entry to have its state triggered by another device, in my case a Zooza ZEN34 Bluetooth LR button, to trigger Alexa to take a number of actions when the ZEN34 is pressed, double-tapped and so forth. I then used a similar technique to flash lights and make announcements when any of my First Alert Z-Wave Combo Gen 2 Smoke/CO detectors are triggered. Obviously the latter should be regarded as a supplemental and not relied on for safety purposes. Allowing the trigger to be the real, or a matching virtual smoke alarm, gave me a handy way to test the routines (but not the test physical alarms of course).

@mikee385 That driver ROCKS

Any thought why it inits with

sendEvent(name: "numberOfButtons", value: 1)

But it registers 5 buttons?

  • contact : closed
  • numberOfButtons : 5
  • pushed : 1
  • switch : off

Hmm, that’s very odd. Mine doesn’t seem to be doing that. There’s nothing in the code that sets the number of buttons to anything other than 1. I don’t know what to think about that. I’m completely baffled…

LOL - yeah I looked at your code, which is clean and concise and am baffled too ...

Download the Hubitat app