Controlling an Alexa device from Hubitat

Yes, you can use a Virtual Driver that supports both the Contact Sensor and Switch Capabilities. This allows for a simple method on Hubitat to simply turn on and off the switch portion, while the same device on Alexa can use the Contact Sensor portion as an Alexa Routine Trigger.

1 Like

Thanks. Victory! I created an Alexa routing that responds to the contact closure! The virtual device was discovered automatically.

I didn't see a virtual device that does both -- do I need to create one? How? It's not important though becuase I can separate the functions.

FYI -- changing the device type does seem to automatially be reflected in Alexa but I should do more extensive testing at some point.

Rube Goldberg would be impressed.

1 Like

I knew that this might be your next question... :wink: I am working on an enhanced "Virtual Contact Sensor with Switch" driver and will post it in my GitHub once it is done. There are a few other ones floating around the Community if you're in a rush.

3 Likes

You can add a custom driver - I have just added this one to my GitHub repository that combines a Switch and Contact Sensor in one device. It also supports reverse logic if desired (e.g. flipping whether 'on' = 'open' or 'on' = 'closed') as well as an optional Automatic Off Feature. I also have a very similar driver that combines a Switch amd Motion Sensor in one device, with the same feature set.

The basic idea behind this combined drivers is that it is often more 'natural' on the Hubitat side of things to turn on and off a switch. But, if that switch needs to be able to Trigger an Alexa Routine, we have a problem (see aforementioned posts :wink: ) Thus, these drivers allow Hubitat to 'turn on' a switch, yet Alexa will see it also as a Contact sensor changing state, and thus it can be used to Trigger an Alexa Routine.

Likewise, Alexa cannot change the state of a Hubitat virtual Contact Sensor or Motion Sensor. But Alexa can turn on and off a switch device. Thus, you can also use this same driver for the reverse logic. For example, I have a Ring Doorbell that cannot be natively integrated with Hubitat. So, I created a Virtual Hubitat Device using my "Virtual Motion Sensor and Switch" driver. I then share this with Alexa. I created an Alexa Routine that is triggered by my Ring Doorbell sensing motion (using the Ring Alexa Skill integration.) As an Action of that Alexa Routine, I turn on the Hubitat Virtual Motion Sensor and Switch device. I have that Hubitat device configured to automatically turn back off so that it is ready for the next time Alexa needs to turn it back on. I then use standard Hubitat Apps to build automations based on the 'Ring Motion' sensor going active, like any other motion sensor.

With these device drivers, you can see how it is fairly straightforward to link Hubitat and Alexa together, where each can trigger each other as needed.

Hope this helps. Here is the Virtual Motion Sensor and Switch driver as well...

5 Likes

Wow, that is awesome! Not that I have Alexa only devices, but it sure will help a lot of people who do.

1 Like

Thanks! I'll look at it tomorrow and try to learn.

BTW, I notice that these post tend to have URLs. Use be nice to have a standard so I could just say "update" rather than having to copy each over manually -- unless there already is such a capability.

Are you talking about getting the code above into your hub?

If it’s a github URL:

2 Likes

OK, installed.

Each time I understand a little more about the platform. At least there is more native capability than when I had to program around SmartThings (before they were Samsung).

Okay - brand new to this, so go easy on me!

I just installed both the virtual motion sensor and contact sensor with switch, and that went as expected. The problem I have is that Alexa sees the device as a switch and not a motion or contact sensor as it should. Am I doing something wrong?

Ed

Probably not. You'll only see them available as motion or contact sensors when you create an Alexa routine and select a trigger.

1 Like

Okay - So I go to create the routine and add the new virtual contact with switch and it thinks it a switch, not a contact, and kicks out "ERROR: This device is not currently supported."

So, I take a step back and just create a virtual contact switch only to see if I can back into this by creating some rules to link a virtual contact to a virtual switch separately. When I add the new virtual contact device to the Echo Skill, it shows up in Amazon as a contact sensor, but when I go to add it to a skill, it kicks out the same "ERROR: This device is not currently supported."

:confused:

Have you manually cycled the virtual contact sensor from open to closed in the Hubitat UI? Need to make sure it has a value that displays correctly in the Amazon Alexa app on your phone.

Once you get it working in Alexa, you should be able to change the driver type of the virtual contact sensor to a driver that supports both contact sensor and switch capabilities.

1 Like

I did try that - but no luck.

Having said that I did create a virtual motion sensor and Amazon DID see it appropriately. I then was able to create a Echo routine that locked my WiFi Schlage lock when it "detected motion" by using the voice action of, "Alexa, set volume to 0 and lock my front door". Conversely I created a routine that would unlock the door with the voice action of, "Alexa, set the volume to 0 and unlock my front door with pin 123456".

So - this is a step in the right direction, however to really make it work I would need to create a separate virtual switch and fab up some rules that would toggle the motion sensor when the switch is toggled.

Ideally, I'd like to have the motion sensor with switch combo functioning to avoid the extra overhead but every time I try to use the driver above, it shows up as a switch, not a motion sensor. I'm not strong in terms of coding, but I couldn't see an obvious priority for the virtual device to present itself as a motion sensor only.

Thoughts?

Virtual Locks work in Alexa as well, as triggers for Alexa Routines. That may simplify things.

Ah! I did not know that. I thought that you could only use virtual contacts or virtual motion detectors.

I will try that next!

Thanks for the tip.

1 Like

Alright - That did the trick!

  • Created a virtual lock
  • Added virtual lock to Echo Skill App
  • Created Amazon lock routine with voice command, "Alexa, set volume to 0 and lock my front door" when virtual lock is set to lock.
  • Created Amazon unlock routine with voice command, "Alexa, set the volume to 0 and unlock my front door with pin 123456" when virtual lock is set to unlock.

All is well and now I can activate my WiFi Schlage from HE using Alexa. In fact - it is the ONLY think I am using Alexa for.

Thanks for the guidance!

Ed

2 Likes

After reading this again (I must have started on a similar thread a couple years ago, I finally understand these hybrid devices of ogiewans. I'll say my understanding, which is only useful if it helps someone else "get" this.

Alexa mostly deal with controlling devices (we'll call them the output) based on input by voice or a few other things. So for example, a "switch" is an output device to Alexa. Alexa can turn a switch on, but a switch can not cause Alexa to do something.

An example if the "few other things" that can be input to Alexa are contact sensors and motion sensors. HOWEVER, a contact sensor or motion sensor can't be used as a device activated by a Hubitat scene or whatever. So the magic contact sensor with switch is a two-ended device. It looks like a switch to Hubitat so H can control it with a scene, but it looks like a contact sensor to Alexa, so it can trigger a routine in Alexa. COOL!

BTW, there seemed to be a lot of trouble earlier explaining what we wanted to do. I think I can say it simply: We have a device like an APC power strip or any number of other "hubless" devices that work with Alexa and their own app but nothing else. We want to control them with a hubitat scene or simple automation. So we have to be able to hit a hubitat switch and have it run a routine on Alexa.

I hope this helps someone else, and I thank everyone who worked on these drivers and made it happen!

6 Likes

Here is a Universal Virtual Switch Device Type, made for Alexa, IFTTT, and other integrations. It is similar to the UDTh from SmartThings. It is a Virtual Switch that can also be a motion, contact, presence, smoke, water, shock, battery, sleep, and valve. Just select the features you want. Also has the ability to automatically turn off after a certain period (good for virtual motion sensors).
For Alexa Integration, you would select either Contact and/or Motion sensors as those are the only Triggers in Alexa Routines. You can then Open/Close or set Motion/No Motion in Hubitat by turning the Switch On or Off.