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