How to run a rule when device command is sent (from Alexa)

New user, first post. Really enjoying my Hubitat, and looking forward to being more involved in this community.

Question.. Is there a way to run a rule when a command is sent to turn on a device, prior to the device turning on? Or is there a way to disable a device, and only send the command to turn it on if a rule is true?

A little background... I've installed a smart outlet for my garage door opener, which is connected to a relay. When the garage door outlet is turned on, my garage door opens/closes. I've also purchased a BeSense z-wave contact sensor for the garage door. After buying this, I quickly realized that, while compatible with HE, it is not compatible with Amazon. I'd like to be able to control the garage door, but only to close (if open). So, ideally I'd like to ask Alexa to "close the garage door", at which point it would first check if the contact sensor is open, and then do nothing if it is closed, or close it (if sensor is open). I'm doing this, because saying "close the garage door" will open or close it, as it is. Is this possible using rule machine or do I need to create an Alexa skill for the contact sensor?

Appreciate any help! Thank you!

3 Likes

I'm not sure this is the best / easiest way:

For all my Alexa commands I create a Virtual device. The Alexa command triggers that Virtual device.

I've not done this but it would be easy to create a rule in Rules Manager that will trigger on the above Virtual device and do almost anything you can imagine, including delays etc.

John

4 Likes

How do you create a virtual device?

Good Question....

from Devices -- upper right "add virtual devices" then in the "type" (bottom right) select "Virtual Button"

You can add more virtual device types as you gain more comfort with HE.

2 Likes

I created the virtual device, but cannot figure out how to assign it to control the garage door.

Thanks for the response @JohnRob. This did indeed worked well. I couldn't get it to work previously because I chose the virtual garage door, which I couldn't seem to get added to Alexa. This time I chose a virtual switch which I called "Garage Door" and it worked. Appreciate your help.

@Stat, try creating a virtual switch, add it to the Alexa Echo Skill App in Hubitat. Then add the newly created virtual skill to Alexa. You can then set this up to fire a new rule in the rule machine.

@baber9 I see what you are saying. I created the virtual garage switch and labeled it Garage Door v. I added it Alexa and placed it into the group that I wanted it in. I am now confused on how to make the rule in the rule machine so that the virtual switch operates the garage door through Alexa.

@baber9 I was able to create the rule and it works to open (On) and close (Off) the garage through the HE device menu. The switch toggles in the Alexa app, but using the Alexa app the rule doesn't work. I am dumb founded by this.

RM takes a little different mind set. I'm not the best teacher but the concept is:

Create a rule that will the "Select Conditions" to include your Virtual button.
The Define rule should be filled out automatically as the above conditions represents a trivial configuration.

I the "Select Actions for True" add the action of closing the door
I the "Select Actions for False" add the action of opening the door

"Done" and "Done" until your are back at the apps page.

As I said, I'm not the best teacher but this should get you close.

John

1 Like

I do this to ensure my front door is closed so the bolt doesn’t jam. This simple rule will not allow the door to lock unless the contact sensor is engaged. The virtual switch “HE Auto Lock” on my hub turns on for 1 second, then back off. If both conditions are not true, nothing happens.

The HE Auto Lock virtual switch is repurposed for Alexa routines, and physical buttons around the house. Works perfectly.

1 Like

@Stat, now that you have the virtual device added to Alexa, you will use that device to actually control your real devices.

In other words, create a new rule in Hubitat that says when the virtual switch turns on, turn on the device that opens the garage door.

So, as an overview:
“Alexa, open (or close) the garage door” - this actuates the virtual switch
Rule Machine

  • When virtual switch turns on, tell actual device (in Hubitat) to open the garage door.

The way I have mine setup is the same way, but I have an additional rule set to make sure the contact sensor is open before attempting to close the garage door, otherwise do nothing. Reason for this, is that I only want to be able to close my garage door with Alexa, but when I try to “close the garage door” it will try to engage the relay which can open and close, so I needed to make sure it was actually open before engaging the relay.

Hope this helps!

Thanks for all the help! I finally got it to work😁. The only thing is I need to remember to say "Alexa turn garage door off" instead of close garage door. And that is because it is a switch not a door, but hey it works. Thank you @baber9, @JohnRob and @SmartHomePrimer for all of your help!

2 Likes

Assign the switch to an Alexa Routine and you should be able to say whatever you want.

2 Likes

@SmartHomePrimer thank you! That is awesome!

2 Likes

If you want to say instead open and close, use a virtual shade device and create a rule on opening event, open the garage. I am doing this for my awning. The only problem is sometimes Alexa doesn't know the state as it can be opened w a remote directly and it sometimes messes it up. I am trying to figure out how to purely override the open and close commands and not rely on events, of anyone knows how, let me know.