@jake1164
Jake,
I have it all working now… It did take some tweaking on names, which I did not expect, but in hindsight, I’m not surprised.
Here is the Arduino sketch (change the pin assignments as you see fit:
//******************************************************************************************
// File: Jason_Jackson_ST_Anything.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 <dht.h> //DHT Temperature and Humidity Library
#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 <PollingSensor.h> //Generic Polling "Sensor" Class, polls Arduino pins periodically
#include <Everything.h> //Master Brain of ST_Anything library that ties everything together and performs ST Shield communications
#include <PS_TemperatureHumidity.h> //Implements a Polling Sensor (PS) to measure Temperature and Humidity via DHT library
#include <IS_Motion.h> //Implements an Interrupt Sensor (IS) to detect motion via a PIR sensor
#include <IS_Contact.h> //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_DoorControl.h> //Implements an Interrupt Sensor (IS) and Executor to monitor the status of a digital input pin and control a digital output 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_TEMPERATUREHUMIDITY 5
//Garage Door Pins
#define PIN_RELAY_GARAGE_DOOR 9
#define PIN_CONTACT_GARAGE_DOOR 11
//House Door Pins
#define PIN_CONTACT_GARAGE_SIDE_DOOR 10
//******************************************************************************************
//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")
//******************************************************************************************
//Polling Sensors
static st::PS_TemperatureHumidity sensor2(F("temphumid"), 120, 10, PIN_TEMPERATUREHUMIDITY, st::PS_TemperatureHumidity::DHT11);
//Interrupt Sensors
static st::IS_Contact sensor1(F("contact"), PIN_CONTACT_GARAGE_SIDE_DOOR, LOW, true, 500);
static st::IS_DoorControl sensor3(F("door"), PIN_CONTACT_GARAGE_DOOR, LOW, true, PIN_RELAY_GARAGE_DOOR, LOW, true, 1000);
//*****************************************************************************
// 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::Executor::debug=true;
st::Device::debug=true;
st::PollingSensor::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);
//*****************************************************************************
//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();
}
And here is the Groovy Device Handler code
/**
* ST_AnyThing.groovy
*
* Copyright 2014 Dan G Ogorchock & Daniel J 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-03 Dan & Daniel Original Creation
* 2016-02-23 Dan Ogorchock Modifed for Jason Jackson's use case
*
*/
metadata {
definition (name: "Jason_Jackson_ST_AnyThing", namespace: "ogiewon", author: "Daniel Ogorchock") {
capability "Configuration"
capability "Temperature Measurement"
capability "Relative Humidity Measurement"
capability "Switch"
capability "Sensor"
capability "Contact Sensor"
capability "Polling"
capability "Door Control"
capability "Garage Door Control"
command "pushGarage"
//attribute "garagesidedoor", "string"
//attribute "garagedoor", "string"
}
simulator {
}
// Preferences
preferences {
input "temphumidSampleRate", "number", title: "Temperature/Humidity Sensor Sampling Interval (seconds)", description: "Sampling Interval (seconds)", defaultValue: 30, required: true, displayDuringSetup: true
}
// Tile Definitions
tiles {
standardTile("door", "device.door", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
state "closed", label: 'Closed', action: "pushGarage", icon: "st.doors.garage.garage-closed", backgroundColor: "#79b821", nextState: "closed"
state "open", label: 'Open', action: "pushGarage", icon: "st.doors.garage.garage-open", backgroundColor: "#ffa81e", nextState: "open"
state "opening", label: 'Opening', action: "pushGarage", icon: "st.doors.garage.garage-opening", backgroundColor: "89C2E8", nextState: "opening"
state "closing", label: 'Closing', action: "pushGarage", icon: "st.doors.garage.garage-closing", backgroundColor: "89C2E8", nextState: "closing"
}
standardTile("contact", "device.contact", 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")
}
valueTile("temperature", "device.temperature", width: 1, height: 1) {
state("temperature", label:'${currentValue}°',
backgroundColors:[
[value: 31, color: "#153591"],
[value: 44, color: "#1e9cbb"],
[value: 59, color: "#90d2a7"],
[value: 74, color: "#44b621"],
[value: 84, color: "#f1d801"],
[value: 95, color: "#d04e00"],
[value: 96, color: "#bc2323"]
]
)
}
valueTile("humidity", "device.humidity", inactiveLabel: false) {
state "humidity", label:'${currentValue}% humidity', unit:""
}
standardTile("configure", "device.configure", inactiveLabel: false, decoration: "flat") {
state "configure", label:'', action:"configuration.configure", icon:"st.secondary.configure"
}
main(["temperature","humidity"])
details(["door","contact","temperature","humidity","configure"])
}
}
// parse events into attributes
def parse(String description) {
log.debug "Parsing '${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
}
// handle commands
def pushGarage() {
log.debug "Executing 'pushGarage' = 'door on'"
zigbee.smartShield(text: "door on").format()
}
def open() {
pushGarage()
}
def close() {
pushGarage()
}
def poll() {
//temporarily implement poll() to issue a configure() command to send the polling interval settings to the arduino
configure()
}
def configure() {
log.debug "Executing 'configure'"
log.debug "temphumid " + temphumidSampleRate
[
zigbee.smartShield(text: "temphumid " + temphumidSampleRate).format()
]
}