Last active
December 17, 2015 14:19
-
-
Save danlieberman/5623547 to your computer and use it in GitHub Desktop.
Read contact sensor state when processing an acceleration event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Vibration Active When Closed | |
* | |
* Author: [email protected] | |
* 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