Virtual Devices are Broken?

I have not seen anything like this on the boards, so here goes:

Has anyone noticed that Virtual Device events are not working with SmartApps? I have written a SmartApp that subscribes to a Virtual Switch (Simulated Switch). The Handler function never triggers (although I see the “PUBLISHED on()” message in the log).

As a further test, I instead subscribed to a Physical Switch. The Handler function triggers just fine.

Is this a change in the API/functionality or a bug?

Any help?

Simulated Switches work fine in webCoRE, I use them all the time. So it definitely can be done.

Though, I don’t know how you’d add them to your own app…

Unfortunately, I am not trying to do a webCoRE piston. I am trying to implement a Message Handler for a Denon AVR receiver. I tried using a Composite Device Handler, but the sendEvent functionality from a Device Handler is unreliable (i.e. any commands after the sendEvent command are lost, and multiple sendEvent commands from a Handler method do not seem to be reliable). I was hoping a Smart App would do better.

This is frustrating because it all works otherwise. Including feedback and current status (much like the IOS Denon App). I can see all the correct messages and control working, but the sendEvents seem to be completely broken/delayed/dropped…

Yeah, my point was more to say that others are making them work, so perhaps there’s hope that you can get them going too.

This was not always the case with Composite DTH’s. A few of us have been seeing this unreliable event handling but this only started recently. May be related to your smarApp issue as well.

See threads below:

1 Like

Also, forgot to mention…I don’t know if you can use the Simulated Switch for that function. I’ve always created my own Virtual Switches and Momentary buttons. Mine are highly customized but I know there are a few that have been created. Try this one and see if you get better luck.

https://raw.githubusercontent.com/MichaelStruck/SmartThingsPublic/master/devicetypes/michaelstruck/alexa-switch.src/alexa-switch.groovy

Details in this post:

1 Like

Thanks. Interestingly enough, this did not work. I think that somethings else is breaking (although I don’t know what.) Is there a way to turn up debug that anyone knows?

Another interesting symptom. When I press the button in the app using the following code:

def on() {
log.debug(“Switch ON”);
sendEvent(name: “switch”, value: “on”, isStateChange: true)
}

I get the print in the Log, but the button immediately switches back to OFF in the APP

When I use the following code

def on() {
sendEvent(name: “switch”, value: “on”, isStateChange: true)
log.debug(“Switch ON”);
}

I see no prints in the Log and the button immediately switches back to OFF in the APP

VERY weird behavior.

I think you might need to post the complete code to your switch DTH. This sounds like a momentary button.

metadata {
definition (name: “Denon AVR Input”, namespace: “denonAVR”, author: “Thomas Howard”) {
capability "Switch"
capability “Actuator” //included to give compatibility with ActionTiles
}

tiles {
standardTile(“input”, “device.switch”, width: 2, height: 2, decoration: “flat”) {
state “off”, label: ‘Off’, action: “switch.on”, icon: “st.Electronics.electronics12”, backgroundColor: “#ffffff”, nextState:"on"
state “on”, label: ‘On’, action: “switch.off”, icon: “st.Electronics.electronics12”, backgroundColor: “#00a0dc”, nextState: “off”
}
main: "input"
details([“switch”,“on”,“off”])
}
}

def installed() {
log.debug “Installed Denon Input Child”
}

def parse(String description) {
}

//ACTIONS
def on() {
log.debug(“Switch ON”);
sendEvent(name: “switch”, value: “on”, isStateChange: true)
}

def off() {
sendEvent(name: “switch”, value: “off”, isStateChange: true)
log.debug(“Switch OFF”);
}

So…a few things that cause problems.
First there seems to be some strange characters in your code. Your quotation marks are inverted somehow. I’m not sure if you are translating from another language but it copies and pastes strangley and causes errors in IDE.

Secondly you log statements should be more like
log.debug "Switch ON"

No brackets and no semicolon.
There are a few other things but I’ll just give you some updated code below for you to test.

metadata {
definition (name: "Denon AVR Input", namespace: "denonAVR", author: "Thomas Howard") {
capability "Switch"
capability "Actuator"	//included to give compatibility with ActionTiles
}

tiles {
standardTile("input", "device.switch", width: 2, height: 2, decoration: "flat") {
state "off", label: "Off", action: "switch.on", icon: "st.Electronics.electronics12", backgroundColor: "#ffffff", nextState:"on"
state "on", label: "On", action: "switch.off", icon: "st.Electronics.electronics12", backgroundColor: "#00a0dc", nextState: "off"
}
main: "input"
details(["input"])
}	
}

def installed() {
log.debug "Installed Denon Input Child"
}

def parse(String description) {
}

//ACTIONS
def on() {
log.debug"Switch ON"
sendEvent(name: "switch", value: "on", isStateChange: true)
}

def off() {
sendEvent(name: "switch", value: "off", isStateChange: true)
log.debug "Switch OFF"
}

Yep; this did not change anything. Thanks for taking a look. Something on the hub must seriously messed up.