How To: Alexa - Play the radio when Hubitat does something

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 :sweat_smile:).

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! :grin:

1 Like

This has been the long-established method for triggering Alexa routines from Hubitat. If you do a search, you'll find I recommended stephack's driver many times in the past.

However, I (and some others) have come to the conclusion that switch/contact or switch/motion devices aren't totally reliable on the Amazon side. I don't know why, and like all things Alexa, there is no consistency. But I've been changing mine to contact devices only and have never had an issue with contact only.

The only difference is that on the Hubitat side, you use a custom action to set the contact to open or closed as desired. This may not seem as natural as turning a switch on or off, but it simplifies things on the Alexa side.

1 Like

Can you tell me how to do that? I couldn't figure it out.

There are other virtual drivers out there for this, and I never had any issues with this one:

Then you do not need a custom action rule to change a contact state, you just use it as a switch.

Ah, that's beautiful. Thank you! Trying it now...

Perfect. I knew it must exist somewhere, which is why I hedged on that point. Thank you!

The issue isn't the driver. The issue is how Alexa handles devices with multiple capabilities inconsistently sometimes. It is very intermittent, but in my opinion, worth avoiding if possible.

Opening/closing a contact is easy (as shown above).

Could be. I don't use that driver or method anymore, but I had no issues when using it.

I moved on to using the Echo Speaks app to trigger routines, so that became my go-to way to trigger Alexa routines without fail, though I also use connector apps to make a virtual switch trigger the routines in Echo Speaks so it acts like a switch.

For that matter, what OP wants to do is leverage an Alexa function, so Echo Speaks makes much more sense here, as the command can be sent to the echo device directly from Hubitat, with no routines needed at all.

1 Like

Gave it a try and it worked. I guess in the grand scheme of things, if it eliminates the need for a custom driver and works more consistently on the Alexa end, then that's the way to go. Appreciate the insight.

1 Like

Echo Speaks is a powerful solution, and I've used it in the past. However, with power comes complexity and some overhead. Those with a limited number of fixed things they want to trigger on the Alexa side may want to start with a simpler method.

1 Like

I'm totally new to all this. I had read about Echo Speaks, and dipped my toes into installing it, but the server requirement and all that complexity put me off.

That thread seems to suggest that unless you're getting really complicated, Echo Speaks is not worth the hassle...?

So maybe I'll go there eventually, but, I think simpler is better overall.

1 Like

@photonclock what you have outlined - using a virtual 'switch' to trigger a routine is the simplest method - and you really did a nice job of outlining start to finish, this would be helpful for someone just starting out. I think @HAL9000 's comment on Echo Speaks sums it up.

I agree, The Echo Speaks cookie server setup is a pain, even if you do the paid cloud server option. I went to running the cookie server on a PI when they started charging for the cloud server access, which make it even more complicated. However, I followed the procedures for setting up the PI server and it was pretty easy. I went with simpler Dockerless method and it works fine.

There are lots of reasons to go through the setup pain, though. The command in Echo Speaks for voiceCommandAsText is really powerful. At one point I was controlling a wifi dimmer linked to Alexa using voice command as text. I would construct a string based on level, so I would just send to Alexa a command like "Turn on the kitchen light to 50%" That string was built using a virtual dimmer. When I changed level on the virtual dimmer, it took the dimmer value and made the command string to change the dimmer to that level in Alexa automatically.

I still use it to make my Echo's Speak as well, by constructing strings for the echo to say. Triggering a routine by ID is also very handy.

For OP, here are just a few of the many other things you can do with Echo Speaks:

  • Search Amazon Music, Apple Music, iheart, Pandora, Sirus XM, Spotify, and others and play it.
  • Set volume, mute, play announcements
  • Play a track from URI/URL
1 Like