Trigger Alexa Routine on Virtual Switch - not working

This could be be me missing something, as I have also found some similiar discussion here

Im trying to have Alexa trigger a routine when a Virtual Switch changes state. It just doesnt work. I need it to be a switch and not button (ie Virtual Alexa Button) as I need to know the state.

The switch is selectable as a WHEN action as well as On/Off state. It just doesnt trigger.

Verified that Alexa Routine doesnt honor the switch change via either Alexa UI or HE.

What Ive tried

  • Both on/off Triggers
  • Routine works manually activating it
  • The switch is controllable via Alexa UI, HE sees it change.
  • Alexa sees the change of state when changed in HE

Ive also added the switch the an Alexa Group (link above), but that doesnt appear as a WHEN action in the Alexa Routine. What I havent done yet is add the switch to a HE group and trigger off that.

Am I missing something?

There was a similar discussion SmartThings

Alexa routines cannot be triggered by a switch. The trick is to use a virtual device that has both contact and switch capabilities. Then you can treat that same device as a contact when you want to (in your Alexa routine), and as a switch when you want to (everywhere else).

Hubitat/Virtual Contact Sensor with Switch.groovy at master · stephack/Hubitat · GitHub

3 Likes

This also works. It's a virtual contact sensor that acts a switch on hubitat. I use it quite often

/**

  • Virtual Motion Sensor with Switch
  • Copyright 2020 Ernie Miller
  • Permission is hereby granted, free of charge, to any person obtaining a copy
  • of this software and associated documentation files (the "Software"), to deal
  • in the Software without restriction, including without limitation the rights
  • to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  • copies of the Software, and to permit persons to whom the Software is
  • furnished to do so, subject to the following conditions:
  • The above copyright notice and this permission notice shall be included in
  • all copies or substantial portions of the Software.
  • THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  • IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  • FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  • AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  • LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  • OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  • SOFTWARE.
    */

metadata {
definition(name: "Virtual Motion Sensor with Switch", namespace: "ernie",
author: "Ernie Miller") {
capability "Actuator"
capability "Motion Sensor"
capability "Sensor"
capability "Switch"
}

preferences {
input name: "inactiveSeconds", type: "number",
title: "Inactive Delay",
description: "Seconds until switch/motion toggles off (1 - 120, 0 = disable)",
range: "0..120", defaultValue: 10, required: true
input name: "logEnable", type: "bool", title: "Enable Logging",
defaultValue: false
}
}

def installed() {
off()
}

def on() {
if (logEnable) { log.info "$device.displayName active" }
sendEvent(name: "motion", value: "active")
sendEvent(name: "switch", value: "on")
if (inactiveSeconds > 0) { runIn(inactiveSeconds, "off") }
}

def off() {
if (logEnable) { log.info "$device.displayName inactive" }
sendEvent(name: "motion", value: "inactive")
sendEvent(name: "switch", value: "off")
}

Thanks this makes sense !

copy and paste it into user driver

Download the Hubitat app