Using Alexa for voice feedback

Not sure if this can be done, but I'm working on something for my Mom with her Hubitat and Alexa. I'm setting up a tilt sensor on the garage door, so that she can know if the door is closed at night. Ideally, She has a button in the house that will trigger a rule to turn off all the lights in the house. I'd like to have it so that if the garage door is open or closed, Alexa will tell her.

I don't have the sensor yet, so for the moment to test things out, I'm just using a virtual switch and a table lamp that has a smart switch. I've got everything linked up to where Alexa can turn the lamp on and off. What I'd like to do for testing is when I turn the virtual switch on, it would have Hubitat check the state of the lamp and have Alexa tell if the lamp is on or off.

I forgot to mention, when I go to routines the in Alexa app, I don't have an option to see any of my Hubitat devices that are linked.

You can only use a sensor in Alexa Routines, so you will need to use a small piece of code the mimics a contact or motion sensor triggering when a virtual switch is closed.

You’ll find other more sophisticated examples here too, but this will do the job.

2 Likes

Part of the problem though, is that when I go to the Echo app, under routines, I cannot find my virtual switch listed there, but it is on the devices. From everything I've read, Echo is supposed to be able to see virtual switches.

Something I thought of is, I could have two virtual switches. One for if the garage door is open, other if it's closed. When Mom hits the button, the rule would use an If statement to turn on one switch or the other, which would then trigger Alexa to say the appropriate thing. The rule could then turn the switch back off. But I have to be able to see the switch in the routine.

In the routine, I have Smart Home (or something like that - I don't have the app in front of me at the moment.) All that shows up is the Echo.

I believe that’s what @SmartHomePrimer explained. You can connect a virtual switch to Alexa, but you can’t use it as a trigger for an Alexa routine. That’s a restriction imposed by Amazon.

Unless you use a workaround like the one he posted a link to.

1 Like

If you are not seeing the switch appear in alexa, then you need to check it is exposed. Go to your alexa skill on Hubitat and makes sure any switches you want exposed to alexa are checked..

It doesn’t sound like we’re all on the same page about what @tpaairman is even seeing in their Alexa app.

As mentioned before, expected behavior is:

  • Hubitat virtual switch appears in Alexa app list of devices
  • Hubitat virtual switch does not appear in Alexa app routines as a trigger
3 Likes

Agreed. Though that's one of the reasons I wanted to establish that he has the alexa skill installed on HE and that that skill has the devices exposed to it...

Marktheknife is correct. The switch is in the list of devices in the Echo app, but does not appear in the app as a trigger.

I'm still getting my head around working with Alexa in all of this, but I've read several places that Alexa will work with virtual switches, I thought at tigers.

All switches cannot be used as triggers.

Virtual and real motion/contact/leak sensors work as triggers. And also locks.

2 Likes

Usually, when people make a claim that they use a virtual switch as an Alexa Routine Trigger, they are actually using a custom Virtual Switch + Contact Sensor driver. These drivers expose both the switch and contact sensor attributes to both Hubitat and Alexa. Also, these drivers often offer an “automatic off” feature, that resets the switch to be ready for the next time it is needed to be used.

So, on the Hubitat side, the virtual switch is turned on by Rule Machine, or some other app. This causes the contact sensor attribute of the virtual device to also change states. On the Alexa side, the “contact sensor” portion is used as an Alexa Routine Trigger.

However, recently it has been reported that the dual attribute driver is not behaving properly on the Alexa side of things, resulting in no triggers. Thus, many have simply switched the driver type to a built-in Virtual Contact Sensor, and then use Rule Machine to “open” the sensor, wait a few seconds, and then “close” the sensor. Alexa sees the transition from closed to open, and then triggers the Routine properly. You can then perform whatever Actions you’d like on the Alexa side, including having Alexa make a simple TTS announcement.

4 Likes

Well said. However in regard to...

I've not personally experienced this. All of my existing virtual switch as contact sensor devices have continued to work without issue.

2 Likes

Nice! Glad to hear that.

@tpaairman So, if Alexa is still properly working with the custom drivers, here is one that I wrote a while back that should help.

5 Likes

Just created a simple test with your code and it's working as expected.

@tpaairman Using Dan's code will also give you the results you're looking for, and it's one of the more sophisticated examples of how to do it.

4 Likes

I got it working. Thank you everyone for pointing me in the right direction. The key for me is that I didn't know a virtual switch wouldn't work, but a virtual sensor would. So I created a tilt sensor, and was able to have Alexa do exactly what I wanted without any code being added. Just set up the routine so that when the sensor was open, it would say "The garage door is open."

3 Likes