Alternate to Alexa Switches for hubless locations

I am trying to create an alternate to an Alexa Switch for my hubless location. My thought was to create a virtual switch and a virtual contact sensor using Simple Device Viewer or the beta API Browser+. Then use the virtual switch to change the state of the virtual contact sensor using the RuleAPI.

Then a SmartThings routine could trigger the virtual switch and the virtual contact sensor can trigger an Alexa Routine.

My problem is that I am not a coder and I am only a cut and paster. Based on some of the Sample-RulesAPI drafted a simple rule, but when I try to upload the rule I get and “422 Error, The request is malformed”. I tired about 20 variations with no luck.

I know the “IF” part works because I wrote a rule to use the IF statement to turn a switch on and off and that works. So I know the problem is in the “Then”, “Else” section.

The following is the rule.

{
“name”: “Test Switch 1 controls Test Test Contact 1”,
“actions”: [
{
“if”: {
“equals”: {
“left”: {
“string”: “on”
},
“right”: {
“device”: {
“devices”: [
“f32932b1-c25b-47ac-8192-4aaec85d208f”
],
“component”: “main”,
“capability”: “switch”,
“attribute”: “switch”
}
}
},
“then”: [
{
“command”: {
“devices”: [
“7fd79c24-ce91-48b0-b308-d76d1df2e5f1”
],
“commands”: [
{
“component”: “main”,
“capability”: “contactSensor”,
“command”: “open”
}
]
}
}
],
“else”: [
{
“command”: {
“devices”: [
“7fd79c24-ce91-48b0-b308-d76d1df2e5f1”
],
“commands”: [
{
“component”: “main”,
“capability”: “contactSensor”,
“command”: “closed”
}
]
}
}
]
}
}
]
}

I am able to change the state of the virtual contact sensor using Tasker to make API call. So I know it can be done, but I don’t know how. The Tasker route gets convoluted and is unreliable because I need an Android device as an intermediary. The following are my Tasker “Tasks”.

Any help would be appreciated.

Tagging @orangebucket , @Jake_Mohl , @DaWeav

The problem you are hitting is that capabilities such as contactSensor don’t have commands. Something like switch has on and off commands but there aren’t open and close commands so the contactSensor state can’t be set in Routines and Rules. Typically custom virtual devices either implement custom capabilities to provide the missing commands or add a switch to the device. The latter is great for Alexa but can be a nuisance in other ways.

The Virtual Devices API does support commands. Commands like on and off are defined in the capability as intended to turn the switch attribute on or off, and setter commands are defined for changing other attributes. So they can be implemented automatically. Similarly custom virtual devices can have command mappings that say what the effect of other commands is on attributes. However this still relies on the capability having commands to start with.

For capabilities without commands, the Virtual Devices API allows the attributes of the created virtual devices to be set directly. It is the same mechanism used by SmartApp owned devices - the equivalent of emitting an event in Edge drivers. All very well if you are using a SmartApp written to support them (or Tasker) but not currently much use in Routines and Rules.

What isn’t clear yet is how these virtual devices, which to be fair have not actually been formally announced yet, are supposed to be used if you can’t set them.

3 Likes

Thanks for looking at this and replying.

1 Like

As a temporary alternative until we get something native, voice monkey is quite popular. No hub required. It creates virtual doorbells which can trigger Alexa routines. You can find some discussion in the forum. People originally used it as a dynamic text to speech substitute for Alexa Speaks, but you can also use it just as a virtual device to trigger an Alexa routine.

In order to make the web request to voice monkey without a hub, you might have to use Ifttt. I don’t know if there’s a native way to do that in a hubless configuration, but someone else might know. :thinking:

I know this is all getting pretty clunky, it’s just something that might work for now until a better solution is devised.

A suitable hubless Alexa Switch had been sitting under our noses for a few weeks.

It is called the “Virtual Lock” which can be easily created using the Simple Device Viewer or the beta API Browser+.

The lock can be manually operated in the ST App, and/or it can be controlled by ST Routines. On the Alexa side it can be used as a trigger in Alexa routines.

Two minor problem are the Lock Icon and it says locked/unlocked vs on/off which can’t be changed.

@JDRoberts @orangebucket @DaWeav @Jake_Mohl

1 Like

Nice!

For those not familiar, both the simple device viewer and the API browser plus are community creations which are reached through a browser page. You do not need to have a PC or a hub to use them. :sunglasses:

@JDRoberts I’m going to be looking into if I can add creation of VR devices to my Tasker tasks as well.

1 Like

The other minor issue as opposed to a sensor/switch is that if you want to voice activate a lock you will need to set it up with a pin code, which is harder to remember.

1 Like

The typical use of an Alexa switch is for ST to trigger Alexa Routines. In that use case no pin is needed since the device is operated by ST. This was confirmed by my testing tonight.

If you were going to use Alexa to control the Alexa Switch (Virtual Lock) a pin would be needed for the unlocking (on) command. This was also confirmed by my testing tonight.

Yes, as I said, if you want to start the routine by voice occasionally then you will need a pin to unlock the virtual lock, which you don’t with the virtual dual capability sensor/switch.

Although the primary purpose of these kinds of devices is to allow smart pthings to trigger an Alexa routine, once you’ve set up that routine, you might also want to use it by voice, particularly since there is a limit on the total number of Alexa routines you can have.