Virtual Device: Setting Attributes via Commands without Ping-Ponging

I think I read every thread and the docs related to this and I am stuck. There are a lot.
@tgauchat talked about the subtleties… Oh, the subtleties… and, the documentation.
The docs are much better these days, but not complete.
It took me over six different threads to get to this point – all Hail the Weary ST hackers whose shoulders I stand on

The Pattern provides a Virtual Device Handler exposed as a Device in the App & addressable by other Apps as ONE.
Two particular Use Cases are a Garage Door and a Regular Door.
Both have at least two related Devices: A Relay & Contact. A Lock & Contact.

So, the pattern necessarily includes those two devices, a Controller App that mediates to the Virtual Device.

Ignore the light - it gets its own async SmartLighting instance.
Pressing the Device opens the door via the Relay: The App gets that Event & calls the Relay
The Device button changes Image/State based on the Contact: The App gets that Event and invokes a Command
I got this far, but invoking that Command through a method that createsEvent causes ping-ponging…
I.e. Since the Open/Close Actions are really just button presses this happens:
Press Open:Door starts opening, Contact opens:Sends Event, App sends to Virtual device.
Device receives Opened Event: Attribute State Changed: Action taken… Relay re-engaged. Oops.
Code may be accessible here: https://github.com/gtc100gh/SmartThingsPublic

1 Like

@Lgkahn Larry, Great minds think alike? Coincidence? Or, an illustration of how hard it is to really find something in these forums. I’ve been working on this for awhile. You put up a solution 16 days ago;

I just found it. But, you use the existing Virtual Garage Device and two contacts… Any thoughts or insights to help or steer me to finish this or abandon it and buy and other contact sensor?

2 Likes

Not sure what you mean there is only 1 contact sensor required.

OH! When I looked at yours (quickly) it was asking for the Contact to define Closed and the Contact to define fully Open?

No it asks for 4 things.

  1. The physical switch or relay that controls the door
    2 the physical door open/ close sensor
    And the virtual door device twice because you have to treat it like both a switch and an open close sensor.

Oh and also a timeout to check if it really closed and tune it depending on how quick your Sensor shows a change in state.

okay, going to look harder at that simulated device - my device is the problem in accepting a command and not re-sending the events. Thank you