Documenting this for myself and other Hubitat noobs who may be trying to figure all this out for the very first time without losing your mind (I already lost mine, so light a candle in my honor ).
My goal was to have an audio device intermittently make some noise/play some music when I'm away, and/or when a specific event occurs (in my case, motion detected near front or back exterior doors). Also, I wanted to do it with a device that is relatively inexpensive and power efficient. Obviously, the cheapest & simplest way to do this would be to simply hook up a clock radio to a smart switch, but my building happens to be a large metal building about 10 miles beyond the middle of nowhere, and I pick up exactly zero radio stations FM or AM out here, and the only way around that is going to be to install a big antenna on the building, which I'll probably do someday so I can start picking shortwave and turn myself into a HAM geek, but A) I have enough hobbies, and B) I really have to psyche myself up to climb a 24 foot ladder to get on top of my building. It's a long way down and I don't fall as gracefully as I used to...
So I got an Amazon Echo Dot to test this out. This was my first time ever using the "Alexa" environment.
Download the Amazon Alexa app on your phone's App Store
Plug in your new Echo Dot and wait. It'll wake up after a minute and tell you to download and start the app. The app will then walk you through connecting to the Echo Dot.
Play with the app a bit. There's a lot of junk in it.
The two things I honed in on are the little "hamburger" menu (actually called the "More menu") at the bottom left/center of the screen (the 3 horizontal lines) and the "+" at top right of the screen.
The three things that matter for our purposes in the Alexa app are "Skills", "Devices", and "Routines".
The goal:
When someSwitch (more precisely, someContactSensor) does someThing, Alexa shall do someStuff (play a radio station in this example).
In Hubitat, go to Settings, and make sure you have "Show advanced/developer options" switch enabled (top of screen). Refresh the UI after turning this on.
In Hubitat sidebar, click on "Drivers Code". Click "Add Driver".
In another browser window, go to this github page.
Click the little squares icon next to where it says "Raw" above the code (top right) to copy all the code.
Paste the code into the text field in the Hubitat driver page and save it.
This driver accomplishes a simple workaround/trick. Alexa Routines won't react to switches (on/off), but they will will react to contact sensors (open/closed), so this driver will make a Virtual Contact Sensor toggle it's contact state (open/closed), whenever it's switch state is toggled (on/off). (note: see comments below - there is a way to change contact sensor states with a 'custom rule' negating the need for the custom driver - but this was a good exercise for me nonetheless)
Thus, with this driver, a Rule can toggle the switch state, and the driver will then toggle the device contact state (which normally can't be directly toggled by a Rule), and thus Alexa will be able to react to the contact state changing vis a vis the switch state changing vis a vis the Rule.
Why can't Alexa simply respond to a switch on/off? No idea. Call 1-900-JEFF-BEZOS to find out ($2.99 for the first minute $0.99 thereafter). (anyone born this century won't get this)
Next, in Hubitat Devices, add a new Virtual device of type "Virtual Contact Sensor". Then go to its Device Info page and change the "Type" (driver) to the new driver (it should be labeled "Virtual Contact Sensor with Switch (user)". Change the device label for this exercise to "Alexa Sensor".
Now make a simple test rule. I did this:
Trigger: bedroom light on (whatever trigger you prefer)
Actions: Alexa Sensor on, delay 15 seconds, Alexa Sensor off (this driver doesn't automatically revert the contact state from open to closed so I added a delay and then manually toggle it back to closed. Undoubtedly there are more elegant ways & better drivers to do this but I'm going with the simple example I managed to get working...)
Now we switch back to the Alexa app, and enabled the "Hubitat skill". Click the "more" menu in Alexa (bottom of screen), and choose "Skills and Games". Then in the search field type "Hubitat", and one of the results will be "Hubitat Elevation Skill". Choose that. Then it shows a list of examples, the first one in my case being "Hubitat: Alexa, lock the front door". Click on that. Now you're in the Hubitat Skill page. Click Settings to link the skill to your Hubitat account (you'll need your Hubitat account credentials).
Done with Alexa for the moment.
Next, install the "Amazon Echo Skill" app in your Hubitat:
Sidebar > Apps > Add built-in app > Amazon Echo Skill
In the Amazon Echo Skill app, click 'Select Devices' and choose your new 'Alexa Sensor' device. Click update, then done.
The Echo Dot (in my case) immediately announced that Alexa had discovered a new device. However, it took a minute before the device actually showed up in the list of available devices in the next step...
Now back to the Alexa app, tap that "More" menu at the bottom of the screen, and choose Routines. Then click on "Your Routines" at the top, and then click the little + button (top right) to make a new Routine.
In the Routine:
When: choose "Alex Sensor Opens" (if the sensor doesn't show up, try pulling the window down to make the device list refresh)
Alexa Skill: type in "Play classic rock from iHeartRadio" (choose whatever you want...I like the good stuff...)
Timer: 2 minutes (optional for testing)
That's it.
Now, when I turn on my bedroom light, the Echo Dot starts cranking Rock 'N Roll.
Obviously the goal from there is to leverage more useful trigger events, ie, some motion/sensor triggers your Alexa Sensor, which then triggers your Alexa Routine, which does whatever you like.
This Hubitat stuff is very cool, but it's clearly not for Luddites. Hopefully this little tutorial helps someone out. This community has helped me figure out a ton of stuff in the last couple weeks, so I wanted to try to contribute something cohesive for those who are diving into all this for the very first time. There were so many different threads on this topic with people reporting success and failure, I had no idea if this would actually work. The Hubitat Alexa integration does actually work, at least as of today, 2025-05-16.
Cheers!