Skip to content

Instantly share code, notes, and snippets.

@danlieberman
Last active December 17, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danlieberman/5623547 to your computer and use it in GitHub Desktop.
Save danlieberman/5623547 to your computer and use it in GitHub Desktop.
Read contact sensor state when processing an acceleration event
/**
* Vibration Active When Closed
*
* Author: dan@smartthings.com
* Date: 2013-04-02
*/
preferences {
section( "When there is vibration on this sensor..." ) {
input "sensor1", "capability.accelerationSensor"
}
section( "And the state is..." ) {
input "contactState", "enum",
title:"Which State?",
multiple: false,
metadata: [ values: [ "open", "closed" ] ]
}
}
def installed() {
subscribe( sensor1, "acceleration", accelerationHandler )
}
def updated() {
unsubscribe()
subscribe( sensor1, "acceleration", accelerationHandler )
}
def accelerationHandler( evt ) {
if ( evt.value == "active" ) {
log.debug( "Acceleration Active" );
def latestContactValue = sensor1.latestValue( "contact" )
log.debug( "Latest Contact Value: " + latestContactValue )
if ( latestContactValue == contactState ) {
log.debug( "There was vibration on ${sensor1.name} when it was ${contactState}" )
}
} else if ( evt.value == "inactive" ) {
log.debug( "Acceleration Inactive" )
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment