Wyze Contact Sensor, transform into Smartthings Virtual Sensor

I have tried to use the Simulated Contact Sensor, but can’t seem to get it to have a status.
I am using IFTTT applets to switch on and off for tile utilization in Actiontiles. Delay of updating the tiles usually about 2-3 seconds, but they work. So the tile shows on or off, not Open or closed.
I am a webcore user but have not been able to get the virtual contact sensor to do anything.
In IFTTT when you use the wyze sense contact sensor, and then try to use Smartthings Virtual contact Sensor the only Action option is on or off, not open or close, so that’s where I am unable to get the action of open close that I want

1 Like

In Ifttt, when the Wyze contact sensor opens (or closes) have Ifttt send a Webhook to WebCore. When Webcore receives the Webhook, it can set the Simulated Contact Sensor to open or closed.

2 Likes

I looked at Webhook, I think that appears to be a bit too complicated and techy for my limited background. Thanks for the advice

1 Like

You’re missing @TonyFleisher’s point. The combined Switch/Contact DTH he pointed you to, will allow you to manually create a virtual switch/contact sensor device using the following DTH. Once that virtual device is created, you can expose it to IFTTT and then use it in your IFTTT automations - one to turn on the new virtual device when Wyze senses contact open, and a second one to turn off the new virtual device when Wyze senses contact closed.

Within ST, this virtual device will be seen by SmartApps as both a switch (just ignore that) and as a contact sensor with open and closed values. Use it like any other contact sensor.

Hope this helps to clear things up. Alexa is also only able to turn on and off devices, so this technique works for Alexa Routines as well.

/**
 *  Copyright 2015 SmartThings
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 */
metadata {

    definition (name: "Alexa Switch", namespace: "bjpierron", author: "bjpierron", runLocally: false, mnmn: "SmartThings", vid: "generic-switch") {
        capability "Switch"
        capability "Relay Switch"
        capability "Sensor"
        capability "Actuator"
        capability "Health Check"
        
        capability "Contact Sensor"

        command    "markDeviceOnline"
        command    "markDeviceOffline"
    }
    
    simulator {
		status "open": "contact:open"
		status "closed": "contact:closed"
	}

    tiles {
        standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
            state "off", label: '${currentValue}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
            state "on", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00A0DC"
        }
        standardTile("deviceHealthControl", "device.healthStatus", decoration: "flat", width: 1, height: 1, inactiveLabel: false) {
            state "online",  label: "ONLINE", backgroundColor: "#00A0DC", action: "markDeviceOffline", icon: "st.Health & Wellness.health9", nextState: "goingOffline", defaultState: true
            state "offline", label: "OFFLINE", backgroundColor: "#E86D13", action: "markDeviceOnline", icon: "st.Health & Wellness.health9", nextState: "goingOnline"
            state "goingOnline", label: "Going ONLINE", backgroundColor: "#FFFFFF", icon: "st.Health & Wellness.health9"
            state "goingOffline", label: "Going OFFLINE", backgroundColor: "#FFFFFF", icon: "st.Health & Wellness.health9"
        }
        main "switch"
        details(["switch","on","off","deviceHealthControl"])
    }
}

def installed() {
    log.trace "Executing 'installed'"
    markDeviceOnline()
    off()
    initialize()
}

def updated() {
    log.trace "Executing 'updated'"
    initialize()
}

def markDeviceOnline() {
    setDeviceHealth("online")
}

def markDeviceOffline() {
    setDeviceHealth("offline")
}

private setDeviceHealth(String healthState) {
    log.debug("healthStatus: ${device.currentValue('healthStatus')}; DeviceWatch-DeviceStatus: ${device.currentValue('DeviceWatch-DeviceStatus')}")
    // ensure healthState is valid
    List validHealthStates = ["online", "offline"]
    healthState = validHealthStates.contains(healthState) ? healthState : device.currentValue("healthStatus")
    // set the healthState
    sendEvent(name: "DeviceWatch-DeviceStatus", value: healthState)
    sendEvent(name: "healthStatus", value: healthState)
}

private initialize() {
    log.trace "Executing 'initialize'"
    sendEvent(name: "DeviceWatch-Enroll", value: [protocol: "cloud", scheme:"untracked"].encodeAsJson(), displayed: false)
}

def parse(description) {
}

def on() {
    log.debug "$version on()"
    sendEvent(name: "switch", value: "on")
    sendEvent(name: "contact", value: "open")
}

def off() {
    log.debug "$version off()"
    sendEvent(name: "switch", value: "off")
    sendEvent(name: "contact", value: "closed")
}



private getVersion() {
    "PUBLISHED"
}
3 Likes

OK I downloaded the code into my Device Handlers, now what is the next step? Is it create a new device? and if so how do I integrate the Device Handler into that device to make it perform as the virtual contact sensor? Sorry if I seem clueless, but I am new to using virtual switches.

Thanks for any help you can render.

1 Like

Here you go! This should explain the process of creating a virtual device.

1 Like

Yes, I have set up virtual devices, but still don’t see how where the Device Handler is a choice to be the Device, nor how the device is tied to the Device Handler.
Sorry for my vast lack of knowledge.

1 Like

When I try to do a IFTTT applet with Wyze Contact Sensor as the trigger and Smartthings as the Action, the virtual contact sensors that I have set up as Contact Sensor Capability, the Virtual Contact Sensor is not a choice in the drop down box.

Also, in the Device itself in the description area I get:

Data
No data found for device
Current States

No states found

1 Like

In the list of steps below Select a “Type” from the dropdown, this should be “Alexa Switch” is the critical step to change the DTH (or Type) of a virtual device.

  • Login to the IDE @ https://account.smartthings.com/
  • Click “My Devices”
  • Click the “New Device” Button
  • Enter a “Name” for the device, this can be whatever you want.
  • Enter a “Label” for the device, this is optional and can be whatever you want.
  • Enter a “Device Network Id” This can be anything you want. I recommend short and sweet but it cannot duplicate other device ID’s. Lets say it was a virtual switch for your living room lights, maybe call it LRVD01
  • “Zigbee” Id should be left blank
  • Select a “Type” from the dropdown, this should be "Alexa Switch"
  • “Version” should be published
  • “Location” should be your hub location, probably “Home”
  • “Hub” should be your hub name.
  • “Group” you won’t be able to select when creating, but these are Groups you’ve created in the Things page in the SmartThings app.
  • Click Create
2 Likes

Correct - we’re not wanting to use a Virtual Contact Sensor device - we want to use the “Alexa Switch” device. That way it can show up in IFTTT.

2 Likes

The Alexa Switch is not populating in the Type drop down.

1 Like

Did you remember to Publish it after Saving it in your list of custom Device Handlers?

1 Like

It had appeared as it was published, but I realized that the Alexa Switch was not in alpha order, forgot to scroll all the way down the drop down. Found it! Thanks sooo much. Will try it out today.

2 Likes

Just wanted to let you know that I got the Virtual Devices up and running and integrated into Actiontiles. I plan to try and use them in some Webcore pistons. I was a heavy user of stringify which was so easy to use, but alas Stringify is ending service soon.

Again, thanks so very much for all your help and patience today, it is deeply appreciated.

4 Likes

Great job with this. Using your (and predessors) work, I did the same for the motion sensor. If anyone is interested, I can post the changes later, but basically replace the contact commands and status to those from a motion sensor. Thanks again!

1 Like

I don’t see the DTH you mentioned in your reply

1 Like

I’ve looked 10 times and still cant find Alexa Switch. Any ideas??

1 Like

Just sent you a reply, if you didn’t get it, here is the link to try:

https://github.com/SmartThingsCommunity/SmartThingsPublic/blob/production/devicetypes/smartthings/testing/simulated-switch.src/simulated-switch.groovy

1 Like

These are the steps to do AFTER you publish the Device type for the Alexa Switch from Github:

In the list of steps below Select a “Type” from the dropdown, this should be “Alexa Switch” is the critical step to change the DTH (or Type) of a virtual device.

  • Login to the IDE @ https://account.smartthings.com/
  • Click “My Devices”
  • Click the “New Device” Button
  • Enter a “Name” for the device, this can be whatever you want.
  • Enter a “Label” for the device, this is optional and can be whatever you want.
  • Enter a “Device Network Id” This can be
    anything you want. I recommend short and sweet but it cannot duplicate other device ID’s. Lets say it was a virtual switch for your living room
    lights, maybe call it LRVD01
  • “Zigbee” Id should be left blank
  • Select a “Type” from the dropdown, this should be “Alexa Switch” (don’t expect the dropdown list to be in alphabetical order, the Alexa switch option might be at the bottom of the list)
  • “Version” should be published
  • “Location” should be your hub location, probably “Home”
  • “Hub” should be your hub name.
  • “Group” you won’t be able to select when creating, but these are Groups you’ve created in the Things page in
    the SmartThings app.
  • Click Create
1 Like

I think you want to use the DTH I listed in this earlier post, assuming you want the device to have the Contact Sensor Capability, as well as the Switch Capability.

1 Like