Skip to content

Instantly share code, notes, and snippets.

@kacole2
Last active February 21, 2016 20:23
Show Gist options
  • Save kacole2/3f6cb03186156b38e098 to your computer and use it in GitHub Desktop.
Save kacole2/3f6cb03186156b38e098 to your computer and use it in GitHub Desktop.
ST_Anything_Door Contact Sensors
/**
* ST_Anything_Doors Device Type - ST_Anything_Doors.device.groovy
*
* Copyright 2015 Daniel Ogorchock
*
* 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.
*
* Change History:
*
* Date Who What
* ---- --- ----
* 2015-01-10 Dan Ogorchock Original Creation
*
*
*/
metadata {
definition (name: "ST_Anything_Doors_570", namespace: "ogiewon", author: "Daniel Ogorchock") {
capability "Contact Sensor"
capability "Sensor"
attribute "frontDoor", "string"
attribute "backDoor", "string"
attribute "kitchenDoor", "string"
attribute "familyRoomRearDoor", "string"
attribute "familyRoomPatioDoors", "string"
attribute "basementWindows", "string"
}
simulator {
status "on": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6E"
status "off": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6666"
// reply messages
reply "raw 0x0 { 00 00 0a 0a 6f 6e }": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6E"
reply "raw 0x0 { 00 00 0a 0a 6f 66 66 }": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6666"
}
// tile definitions
tiles {
standardTile("frontDoor", "device.frontDoor", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
}
standardTile("backDoor", "device.backDoor", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
}
standardTile("kitchenDoor", "device.kitchenDoor", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
}
standardTile("familyRoomRearDoor", "device.familyRoomRearDoor", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
}
standardTile("familyRoomPatioDoors", "device.familyRoomPatioDoors", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
}
standardTile("basementWindows", "device.basementWindows", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
}
main (["frontDoor"])
details(["frontDoor","backDoor","kitchenDoor","familyRoomRearDoor","familyRoomPatioDoors","basementWindows","configure"])
}
}
//Map parse(String description) {
def parse(String description) {
def msg = zigbee.parse(description)?.text
log.debug "Parse got '${msg}'"
def parts = msg.split(" ")
def name = parts.length>0?parts[0].trim():null
def value = parts.length>1?parts[1].trim():null
name = value != "ping" ? name : null
def result = createEvent(name: name, value: value)
log.debug result
return result
}
//******************************************************************************************
// File: ST_Anything_Doors.ino
// Authors: Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//
// Summary: This Arduino Sketch, along with the ST_Anything library and the revised SmartThings
// library, demonstrates the ability of one Arduino + SmartThings Shield to
// implement a multi input/output custom device for integration into SmartThings.
// The ST_Anything library takes care of all of the work to schedule device updates
// as well as all communications with the SmartThings Shield.
//
// ST_Anything_Doors implements the following:
// - 2 x Door Control devices (used as Garage Doors)
// - 4 x Contact Sensor devices (used to monitor magnetic door sensors)
// - 1 x Motion device (used to detect motion in the garage)
// - 1 x Temperature/Humidity device (unsed to monitor temp & humidity in the garage)
//
// During the development of this re-usable library, it became apparent that the
// Arduino UNO R3's very limited 2K of SRAM was very limiting in the number of
// devices that could be implemented simultaneously. A tremendous amount of effort
// has gone into reducing the SRAM usage, including siginificant improvements to
// the SmartThings Arduino library. The SmartThings library was also modified to
// include support for using Hardware Serial port(s) on the UNO, MEGA, and Leonardo.
// During testing, it was determined that the Hardware Serial ports provide much
// better performance and reliability versus the SoftwareSerial library. Also, the
// MEGA 2560's 8K of SRAM is well worth the few extra dollars to save your sanity
// versus always running out of SRAM on the UNO R3. The MEGA 2560 also has 4 Hardware
// serial ports (i.e. UARTS) which makes it very easy to use Hardware Serial instead
// of SoftwareSerial, while still being able to see debug data on the USB serial
// console port (pins 0 & 1).
//
// Note: We did not have a Leonardo for testing, but did fully test on UNO R3 and
// MEGA 2560 using both SoftwareSerial and Hardware Serial communications to the
// Thing Shield.
//
// Change History:
//
// Date Who What
// ---- --- ----
// 2015-01-03 Dan & Daniel Original Creation
// 2015-01-07 Dan Ogorchock Modified for Door Monitoring and Garage Door Control
// 2015-03-28 Dan Ogorchock Removed RCSwitch #include now that the libraries are split up
// 2015-03-31 Daniel O. Memory optimizations utilizing progmem
//
//******************************************************************************************
//******************************************************************************************
// SmartThings Library for Arduino Shield
//******************************************************************************************
#include <SoftwareSerial.h> //Arduino UNO/Leonardo uses SoftwareSerial for the SmartThings Library
#include <SmartThings.h> //Library to provide API to the SmartThings Shield
#include <avr/pgmspace.h>
//******************************************************************************************
// ST_Anything Library
//******************************************************************************************
#include <Constants.h> //Constants.h is designed to be modified by the end user to adjust behavior of the ST_Anything library
#include <Device.h> //Generic Device Class, inherited by Sensor and Executor classes
#include <Sensor.h> //Generic Sensor Class, typically provides data to ST Cloud (e.g. Temperature, Motion, etc...)
#include <InterruptSensor.h> //Generic Interrupt "Sensor" Class, waits for change of state on digital input
#include <Everything.h> //Master Brain of ST_Anything library that ties everything together and performs ST Shield communications
#include <IS_Contact.h> //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
//******************************************************************************************
//Define which Arduino Pins will be used for each device
// Notes: -Serial Communications Pins are defined in Constants.h (avoid pins 0,1,2,3
// for inputs and output devices below as they may be used for communications)
// -Always avoid Pin 6 as it is reserved by the SmartThings Shield
//
//******************************************************************************************
//"RESERVED" pins for SmartThings ThingShield - best to avoid
#define PIN_O_RESERVED 0 //reserved by ThingShield for Serial communications OR USB Serial Monitor
#define PIN_1_RESERVED 1 //reserved by ThingShield for Serial communications OR USB Serial Monitor
#define PIN_2_RESERVED 2 //reserved by ThingShield for Serial communications
#define PIN_3_RESERVED 3 //reserved by ThingShield for Serial communications
#define PIN_6_RESERVED 6 //reserved by ThingShield (possible future use?)
//Motion and Temperature/Humidity Pins (Note: using Analog pins as Digital inputs)
//#define PIN_MOTION A0
//#define PIN_TEMPERATUREHUMIDITY A1
//House Door Pins
#define PIN_CONTACT_FRONT_DOOR 5
#define PIN_CONTACT_BACK_DOOR 7
#define PIN_CONTACT_KITCHEN_DOOR 8
#define PIN_CONTACT_FAMILY_ROOM_REAR_DOOR 9
#define PIN_CONTACT_FAMILY_ROOM_PATIO_DOORS 10
//Window Pins
#define PIN_CONTACT_BASEMENT_WINDOWS 11
//House Door Pins
//#define PIN_CONTACT_FRONT_DOOR 10
//#define PIN_CONTACT_BACK_DOOR 11
//#define PIN_CONTACT_KITCHEN_DOOR 12
//#define PIN_CONTACT_SIDEGARAGE_DOOR 13
//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
//******************************************************************************************
//Declare each Device that is attached to the Arduino
// Notes: - For each device, there is typically a corresponding "tile" defined in your
// SmartThings DeviceType Groovy code
// - For details on each device's constructor arguments below, please refer to the
// corresponding header (.h) and program (.cpp) files.
// - The name assigned to each device (1st argument below) must match the Groovy
// DeviceType Tile name. (Note: "temphumid" below is the exception to this rule
// as the DHT sensors produce both "temperature" and "humidity". Data from that
// particular sensor is sent to the ST Shield in two separate updates, one for
// "temperature" and one for "humidity")
//******************************************************************************************
//Interrupt Sensors
static st::IS_Contact sensor1(F("frontDoor"), PIN_CONTACT_FRONT_DOOR, LOW, true);
static st::IS_Contact sensor2(F("backDoor"), PIN_CONTACT_BACK_DOOR, LOW, true);
static st::IS_Contact sensor3(F("kitchenDoor"), PIN_CONTACT_KITCHEN_DOOR, LOW, true);
static st::IS_Contact sensor4(F("familyRoomRearDoor"), PIN_CONTACT_FAMILY_ROOM_REAR_DOOR, LOW, true);
static st::IS_Contact sensor5(F("familyRoomPatioDoors"), PIN_CONTACT_FAMILY_ROOM_PATIO_DOORS, LOW, true);
static st::IS_Contact sensor6(F("basementWindows"), PIN_CONTACT_BASEMENT_WINDOWS, LOW, true);
//*****************************************************************************
// Configure debug print output from each main class
// -Note: Set these to "false" if using Hardware Serial on pins 0 & 1
// to prevent communication conflicts with the ST Shield communications
//*****************************************************************************
st::Everything::debug=true;
st::Device::debug=true;
st::InterruptSensor::debug=true;
//*****************************************************************************
//Initialize the "Everything" Class
//*****************************************************************************
st::Everything::init();
//*****************************************************************************
//Add each sensor to the "Everything" Class
//*****************************************************************************
st::Everything::addSensor(&sensor1);
st::Everything::addSensor(&sensor2);
st::Everything::addSensor(&sensor3);
st::Everything::addSensor(&sensor4);
st::Everything::addSensor(&sensor5);
st::Everything::addSensor(&sensor6);
//*****************************************************************************
//Add each executor to the "Everything" Class
//*****************************************************************************
//st::Everything::addExecutor(&executor1);
//*****************************************************************************
//Initialize each of the devices which were added to the Everything Class
st::Everything::initDevices();
//*****************************************************************************
}
//******************************************************************************************
//Arduino Loop() routine
//******************************************************************************************
void loop()
{
//*****************************************************************************
//Execute the Everything run method which takes care of "Everything"
//*****************************************************************************
st::Everything::run();
}
/**
* ST_Anything Doors Multiplexer - ST_Anything_Doors_Multiplexer.smartapp.groovy
*
* Copyright 2015 Daniel Ogorchock
*
* 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.
*
* Change History:
*
* Date Who What
* ---- --- ----
* 2015-01-10 Dan Ogorchock Original Creation
* 2015-01-11 Dan Ogorchock Reduced unnecessary chatter to the virtual devices
* 2015-01-18 Dan Ogorchock Added support for Virtual Temperature/Humidity Device
*
*/
definition(
name: "ST_Anything Doors Multiplexer",
namespace: "ogiewon",
author: "Daniel Ogorchock",
description: "Connects single Arduino with multiple DoorControl and ContactSensor devices to their virtual device counterparts.",
category: "My Apps",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
preferences {
section("Select the House Doors (Virtual Contact Sensor devices)") {
input "frontdoor", title: "Virtual Contact Sensor for Front Door", "capability.contactSensor"
input "backdoor", title: "Virtual Contact Sensor for Back Door", "capability.contactSensor"
input "kitchendoor", title: "Virtual Contact Sensor for Kitchen Door", "capability.contactSensor"
input "familyRoomRearDoor", title: "Virtual Contact Sensor for Family Room Read Door", "capability.contactSensor"
input "familyRoomPatioDoors", title: "Virtual Contact Sensor for Family Room Patio Doors", "capability.contactSensor"
}
section("Select the House Windows (Virtual Contact Sensor devices)") {
input "basementWindows", title: "Virtual Contact Sensor for Basement Windows", "capability.contactSensor"
}
section("Select the Arduino ST_Anything_Doors device") {
input "arduino", "capability.contactSensor"
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
subscribe()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
subscribe()
}
def subscribe() {
subscribe(arduino, "frontDoor.open", frontDoorOpen)
subscribe(arduino, "frontDoor.closed", frontDoorClosed)
subscribe(arduino, "backDoor.open", backDoorOpen)
subscribe(arduino, "backDoor.closed", backDoorClosed)
subscribe(arduino, "kitchenDoor.open", kitchenDoorOpen)
subscribe(arduino, "kitchenDoor.closed", kitchenDoorClosed)
subscribe(arduino, "familyRoomRearDoor.open", familyRoomRearDoorOpen)
subscribe(arduino, "familyRoomRearDoor.closed", familyRoomRearDoorClosed)
subscribe(arduino, "familyRoomPatioDoors.open", familyRoomPatioDoorsOpen)
subscribe(arduino, "familyRoomPatioDoors.closed", familyRoomPatioDoorsClosed)
subscribe(arduino, "basementWindows.open", basementWindowsOpen)
subscribe(arduino, "basementWindows.closed", basementWindowsClosed)
}
// --- Front Door ---
def frontDoorOpen(evt)
{
if (frontdoor.currentValue("contact") != "open") {
log.debug "arduinoevent($evt.name: $evt.value: $evt.deviceId)"
frontdoor.openme()
}
}
def frontDoorClosed(evt)
{
if (frontdoor.currentValue("contact") != "closed") {
log.debug "arduinoevent($evt.name: $evt.value: $evt.deviceId)"
frontdoor.closeme()
}
}
// --- back Door ---
def backDoorOpen(evt)
{
if (backdoor.currentValue("contact") != "open") {
log.debug "arduinoevent($evt.name: $evt.value: $evt.deviceId)"
backdoor.openme()
}
}
def backDoorClosed(evt)
{
if (backdoor.currentValue("contact") != "closed") {
log.debug "arduinoevent($evt.name: $evt.value: $evt.deviceId)"
backdoor.closeme()
}
}
// --- Kitchen Door ---
def kitchenDoorOpen(evt)
{
if (kitchendoor.currentValue("contact") != "open") {
log.debug "arduinoevent($evt.name: $evt.value: $evt.deviceId)"
kitchendoor.openme()
}
}
def kitchenDoorClosed(evt)
{
if (kitchendoor.currentValue("contact") != "closed") {
log.debug "arduinoevent($evt.name: $evt.value: $evt.deviceId)"
kitchendoor.closeme()
}
}
// --- Family Room Rear Door ---
def familyRoomRearDoorOpen(evt)
{
if (familyRoomRearDoor.currentValue("contact") != "open") {
log.debug "arduinoevent($evt.name: $evt.value: $evt.deviceId)"
familyRoomRearDoor.openme()
}
}
def familyRoomRearDoorClosed(evt)
{
if (familyRoomRearDoor.currentValue("contact") != "closed") {
log.debug "arduinoevent($evt.name: $evt.value: $evt.deviceId)"
familyRoomRearDoor.closeme()
}
}
// --- familyRoomPatioDoors ---
def familyRoomPatioDoorsOpen(evt)
{
if (familyRoomPatioDoors.currentValue("contact") != "open") {
log.debug "arduinoevent($evt.name: $evt.value: $evt.deviceId)"
familyRoomPatioDoors.openme()
}
}
def familyRoomPatioDoorsClosed(evt)
{
if (familyRoomPatioDoors.currentValue("contact") != "closed") {
log.debug "arduinoevent($evt.name: $evt.value: $evt.deviceId)"
familyRoomPatioDoors.closeme()
}
}
// --- basementWindows ---
def basementWindowsOpen(evt)
{
if (basementWindows.currentValue("contact") != "open") {
log.debug "arduinoevent($evt.name: $evt.value: $evt.deviceId)"
basementWindows.openme()
}
}
def basementWindowsClosed(evt)
{
if (basementWindows.currentValue("contact") != "closed") {
log.debug "arduinoevent($evt.name: $evt.value: $evt.deviceId)"
basementWindows.closeme()
}
}
def initialize() {
// TODO: subscribe to attributes, devices, locations, etc.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment