├── AlarmThing.groovy ├── AlarmThingManager.groovy ├── Arduino ├── HomeAlarm │ └── HomeAlarm.ino └── libraries │ ├── SmartThingsMega │ ├── SmartThingsMega.cpp │ └── SmartThingsMega.h │ ├── Timer │ ├── Event.cpp │ ├── Event.h │ ├── Timer.cpp │ ├── Timer.h │ ├── examples │ │ ├── kitchen_sink │ │ │ └── kitchen_sink.pde │ │ ├── pin_high_10_mins │ │ │ └── pin_high_10_mins.pde │ │ └── read_A0_flashLED │ │ │ └── read_A0_flashLED.pde │ └── keywords.txt │ └── readme.txt ├── LICENSE ├── Photos ├── IMG_20140105_204502.jpg ├── IMG_20140105_204512.jpg ├── IMG_20140105_204600.jpg ├── IMG_20140105_204606.jpg ├── IMG_20140105_204627.jpg ├── IMG_4266.JPG ├── IMG_4267.JPG ├── IMG_4268.JPG ├── IMG_4269.JPG ├── IMG_4805.JPG └── IMG_4806.JPG ├── README.md ├── VirtualContact.groovy ├── VirtualGlassBreak.groovy └── VirtualMotion.groovy /AlarmThing.groovy: -------------------------------------------------------------------------------- 1 | /** 2 | * AlarmThing 3 | * 4 | * Author: obycode 5 | * based on work by Josh Foshee and vassilisv 6 | * Date: 2015-01-18 7 | * Copyright 2014 obycode 8 | * 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 10 | * in compliance with the License. You may obtain a copy of the License at: 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed 15 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License 16 | * for the specific language governing permissions and limitations under the License. 17 | * 18 | */ 19 | 20 | metadata { 21 | // Automatically generated. Make future change here. 22 | definition (name: "AlarmThing", namespace: "com.obycode", author: "obycode") { 23 | capability "Alarm" 24 | capability "Switch" 25 | 26 | attribute "alarmStatus", "string" 27 | attribute "zoneChanged", "string" 28 | 29 | command "armAway" 30 | command "armStay" 31 | command "disarm" 32 | command "clear" 33 | command "update" 34 | command "chimeToggle" 35 | command "panic" 36 | } 37 | 38 | // Simulator metadata 39 | simulator { 40 | // status messages 41 | status "ping": "catchall: 0104 0000 01 01 0040 00 6A67 00 00 0000 0A 00 0A70696E67" 42 | status "hello": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A48656c6c6f20576f726c6421" 43 | } 44 | 45 | // UI tile definitions 46 | tiles { 47 | standardTile("alarmStatus", "device.alarmStatus", width: 2, height: 2, canChangeIcon: false, canChangeBackground: false) { 48 | state "ready", label: 'Ready', action: "armAway", icon: "st.Home.home2", backgroundColor: "#ffffff" 49 | state "disarmed", label: 'Ready', action: "armAway", icon: "st.Home.home2", backgroundColor: "#ffffff" 50 | state "notready", label: 'Not Ready', icon: "st.Home.home2", backgroundColor: "#ffa81e" 51 | state "away", label: 'Away', action: "disarm", icon: "st.Home.home3", backgroundColor: "#add8e6" 52 | state "stay", label: 'Stay', action: "disarm", icon: "st.Home.home4", backgroundColor: "#0000ff" 53 | state "arming", label: 'Arming', action: "disarm", icon: "st.Home.home2", backgroundColor: "#B8B8B8" 54 | state "alarm", label: 'Alarm', action: "clear", icon: "st.Home.home2", backgroundColor: "#ff0000" 55 | } 56 | standardTile("away", "device.switchAway", width: 1, height: 1, canChangeIcon: false, canChangeBackground: false) { 57 | state "on", label: "Away", action: "armAway", icon: "st.Home.home3", backgroundColor: "#add8e6" 58 | state "off", label: "Away", icon: "st.Home.home3", backgroundColor: "#ffffff" 59 | } 60 | standardTile("stay", "device.switchStay", width: 1, height: 1, canChangeIcon: false, canChangeBackground: false) { 61 | state "on", label: "Stay", action: "armStay", icon: "st.Home.home4", backgroundColor: "#0000ff" 62 | state "off", label: "Stay", icon: "st.Home.home4", backgroundColor: "#ffffff" 63 | } 64 | standardTile("chime", "device.chime", width:1, height: 1, canChangeIcon: false, canChangeBackground: false) { 65 | state "chimeOff", label:'Chime', action:'chimeToggle', icon:"st.secondary.off", backgroundColor: "#ffffff" 66 | state "chimeOn", label:'', action:'chimeToggle', icon:"st.secondary.beep", backgroundColor: "#ffffff" 67 | } 68 | standardTile("panic", "device.panic", width: 1, height: 1, canChangeIcon: false, canChangeBackground: true) { 69 | state "panic", label:'Panic', action:"panic", icon:"st.alarm.alarm.alarm", backgroundColor:"#ff0000" 70 | //state "confirm", label:'Confirm', action: "panic", icond:"st.alarm.alarm.alarm", backgroundColor:"#ff6600" 71 | //state "cancel", label:'Cancel', action: "disarm", icond:"st.alarm.alarm.alarm", backgroundColor:"#ff6600" 72 | } 73 | standardTile("refresh", "device.refresh", inactiveLabel: false, width: 1, height: 1, canChangeIcon: false, canChangeBackground: false) { 74 | state "default", action:"update", icon:"st.secondary.refresh" 75 | } 76 | main(["alarmStatus"]) 77 | details(["alarmStatus","away","stay","chime","refresh","panic"]) 78 | } 79 | } 80 | 81 | // Parse incoming device messages to generate events 82 | def parse(String description) { 83 | log.debug description 84 | def msg = zigbee.parse(description)?.text 85 | log.debug "Received ${msg}" 86 | def result = [] 87 | if (!msg || msg == "ping") { 88 | result += createEvent(name: null, value: msg) 89 | } else if ( msg.length() >= 4 ) { 90 | if ( msg.substring(0, 2) == "RD" ) { 91 | if (msg[3] == "0") { 92 | result += createEvent(name: "alarmStatus", value: "notready") 93 | // When status is "Not Ready" we cannot arm 94 | result += createEvent(name: "switchAway", value: "off") 95 | result += createEvent(name: "switchStay", value: "off") 96 | } 97 | else { 98 | result += createEvent(name: "alarmStatus", value: "ready") 99 | // When status is "Ready" we can arm 100 | result += createEvent(name: "switchAway", value: "on") 101 | result += createEvent(name: "switchStay", value: "on") 102 | result += createEvent(name: "switch", value: "off") 103 | result += createEvent(name: "panic", value: "off") 104 | } 105 | // Process arm update 106 | } else if ( msg.substring(0, 2) == "AR" ) { 107 | if (msg[3] == "0") { 108 | result += createEvent(name: "alarmStatus", value: "disarmed") 109 | result += createEvent(name: "switch", value: "off") 110 | } 111 | else if (msg[3] == "1") { 112 | if (msg[4] == "0" | msg[4] == "2") { 113 | result += createEvent(name: "alarmStatus", value: "away") 114 | result += createEvent(name: "switch", value: "on") 115 | } 116 | else if (msg[4] == "1" | msg[4] == "3") { 117 | result += createEvent(name: "alarmStatus", value: "stay") 118 | result += createEvent(name: "switch", value: "on") 119 | } 120 | } 121 | else if (msg[3] == "2") { 122 | result += createEvent(name: "alarmStatus", value: "arming") 123 | result += createEvent(name: "switch", value: "on") 124 | } 125 | // Process alarm update 126 | } else if ( msg.substring(0, 2) == "AL" ) { 127 | if (msg[3] == "1") { 128 | result += createEvent(name: "alarmStatus", value: "alarm") 129 | } 130 | // Process chime update 131 | } else if ( msg.substring(0, 2) == "CH" ) { 132 | if (msg[3] == "1") 133 | result += createEvent(name: "chime", value: "chimeOn") 134 | else 135 | result += createEvent(name: "chime", value: "chimeOff") 136 | // Process zone update 137 | } else if ( msg.substring(0, 2) == "ZN" ) { 138 | if (msg.substring(3, 6) == "609") { 139 | log.debug "sending zone opened ${msg.substring(6, 9)}" 140 | result += createEvent(name: "zoneChanged", value: "${msg.substring(6, 9)}.open") 141 | } 142 | else if (msg.substring(3, 6) == "610") { 143 | log.debug "sending zone closed ${msg.substring(6, 9)}" 144 | result += createEvent(name: "zoneChanged", value: "${msg.substring(6, 9)}.close") 145 | } 146 | } 147 | 148 | } 149 | 150 | log.debug "Parse returned:" 151 | result.each { 152 | log.debug " ${it.descriptionText}" 153 | } 154 | return result 155 | } 156 | 157 | // Implement "switch" (turn alarm on/off) 158 | def on() { 159 | armStay() 160 | } 161 | 162 | def off() { 163 | disarm() 164 | } 165 | 166 | // Commands sent to the device 167 | def armAway() { 168 | log.debug "Sending arm command" 169 | zigbee.smartShield(text: "armAway").format() 170 | } 171 | 172 | def armStay() { 173 | log.debug "Sending arm stay command" 174 | zigbee.smartShield(text: "armStay").format() 175 | } 176 | 177 | def disarm() { 178 | log.debug "Sending disarm command" 179 | zigbee.smartShield(text: "disarm").format() 180 | } 181 | 182 | def strobe() { 183 | panic() 184 | } 185 | 186 | def siren() { 187 | panic() 188 | } 189 | 190 | def both() { 191 | panic() 192 | } 193 | 194 | def chimeToggle() { 195 | log.debug "Toggling chime" 196 | zigbee.smartShield(text: "chimeOn").format() 197 | } 198 | 199 | def panic() { 200 | log.debug "Sending panic command" 201 | zigbee.smartShield(text: "panic").format() 202 | } 203 | 204 | // TODO: Need to send off, on, off with a few secs in between to stop and clear the alarm 205 | def clear() { 206 | disarm() 207 | } 208 | 209 | def update() { 210 | log.debug "Sending update command" 211 | zigbee.smartShield(text: "update").format() 212 | } 213 | 214 | def configure() { 215 | update() 216 | } 217 | -------------------------------------------------------------------------------- /AlarmThingManager.groovy: -------------------------------------------------------------------------------- 1 | /** 2 | * AlarmThing 3 | * 4 | * Copyright 2014 obycode 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed 12 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing permissions and limitations under the License. 14 | * 15 | */ 16 | definition( 17 | name: "AlarmThing Manager", 18 | namespace: "com.obycode", 19 | author: "obycode", 20 | description: "Connect your alarm with a SmartShield and make SmartThings see each sensor as an individual thing.", 21 | category: "Safety & Security", 22 | iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png", 23 | iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png", 24 | iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png") 25 | 26 | 27 | preferences { 28 | section("Connect to the alarm...") { 29 | input "theAlarm", "capability.alarm", title: "Which?", multiple: false, required: true 30 | input "theHub", "hub", title: "On which hub?", multiple: false, required: true 31 | } 32 | section("Zones Setup") { 33 | input "zoneName1", "text", title: "Zone 1 Name", required:false 34 | input "zoneType1", "enum", title: "Zone 1 Kind", required:false, metadata: [ values: ['Motion Sensor','Contact Sensor','Glass Break Sensor'] ] 35 | input "zoneName2", "text", title: "Zone 2 Name", required:false 36 | input "zoneType2", "enum", title: "Zone 2 Kind", required:false, metadata: [ values: ['Motion Sensor','Contact Sensor','Glass Break Sensor'] ] 37 | input "zoneName3", "text", title: "Zone 3 Name", required:false 38 | input "zoneType3", "enum", title: "Zone 3 Kind", required:false, metadata: [ values: ['Motion Sensor','Contact Sensor','Glass Break Sensor'] ] 39 | input "zoneName4", "text", title: "Zone 4 Name", required:false 40 | input "zoneType4", "enum", title: "Zone 4 Kind", required:false, metadata: [ values: ['Motion Sensor','Contact Sensor','Glass Break Sensor'] ] 41 | input "zoneName5", "text", title: "Zone 5 Name", required:false 42 | input "zoneType5", "enum", title: "Zone 5 Kind", required:false, metadata: [ values: ['Motion Sensor','Contact Sensor','Glass Break Sensor'] ] 43 | input "zoneName6", "text", title: "Zone 6 Name", required:false 44 | input "zoneType6", "enum", title: "Zone 6 Kind", required:false, metadata: [ values: ['Motion Sensor','Contact Sensor','Glass Break Sensor'] ] 45 | input "zoneName7", "text", title: "Zone 7 Name", required:false 46 | input "zoneType7", "enum", title: "Zone 7 Kind", required:false, metadata: [ values: ['Motion Sensor','Contact Sensor','Glass Break Sensor'] ] 47 | input "zoneName8", "text", title: "Zone 8 Name", required:false 48 | input "zoneType8", "enum", title: "Zone 8 Kind", required:false, metadata: [ values: ['Motion Sensor','Contact Sensor','Glass Break Sensor'] ] 49 | input "zoneName9", "text", title: "Zone 9 Name", required:false 50 | input "zoneType9", "enum", title: "Zone 9 Kind", required:false, metadata: [ values: ['Motion Sensor','Contact Sensor','Glass Break Sensor'] ] 51 | input "zoneName10", "text", title: "Zone 10 Name", required:false 52 | input "zoneType10", "enum", title: "Zone 10 Kind", required:false, metadata: [ values: ['Motion Sensor','Contact Sensor','Glass Break Sensor'] ] 53 | input "zoneName11", "text", title: "Zone 11 Name", required:false 54 | input "zoneType11", "enum", title: "Zone 11 Kind", required:false, metadata: [ values: ['Motion Sensor','Contact Sensor','Glass Break Sensor'] ] 55 | input "zoneName12", "text", title: "Zone 12 Name", required:false 56 | input "zoneType12", "enum", title: "Zone 12 Kind", required:false, metadata: [ values: ['Motion Sensor','Contact Sensor','Glass Break Sensor'] ] 57 | input "zoneName13", "text", title: "Zone 13 Name", required:false 58 | input "zoneType13", "enum", title: "Zone 13 Kind", required:false, metadata: [ values: ['Motion Sensor','Contact Sensor','Glass Break Sensor'] ] 59 | input "zoneName14", "text", title: "Zone 14 Name", required:false 60 | input "zoneType14", "enum", title: "Zone 14 Kind", required:false, metadata: [ values: ['Motion Sensor','Contact Sensor','Glass Break Sensor'] ] 61 | input "zoneName15", "text", title: "Zone 15 Name", required:false 62 | input "zoneType15", "enum", title: "Zone 15 Kind", required:false, metadata: [ values: ['Motion Sensor','Contact Sensor','Glass Break Sensor'] ] 63 | input "zoneName16", "text", title: "Zone 16 Name", required:false 64 | input "zoneType16", "enum", title: "Zone 16 Kind", required:false, metadata: [ values: ['Motion Sensor','Contact Sensor','Glass Break Sensor'] ] 65 | } 66 | } 67 | 68 | def installed() { 69 | log.debug "Installed with settings: ${settings}" 70 | 71 | initialize() 72 | } 73 | 74 | def updated() { 75 | log.debug "Updated with settings: ${settings}" 76 | 77 | //uninstalled() 78 | //initialize() 79 | } 80 | 81 | def initialize() { 82 | subscribe(theAlarm, "zoneChanged", zoneChanged) 83 | if (zoneName1 && zoneType1) { 84 | log.debug "create a $zoneType1 named $zoneName1" 85 | def d = addChildDevice("com.obycode", "Virtual " + zoneType1, "zone001", theHub.id, [label:zoneName1, name:zoneType1]) 86 | } 87 | if (zoneName2 && zoneType2) { 88 | log.debug "create a $zoneType2 named $zoneName2" 89 | def d = addChildDevice("com.obycode", "Virtual " + zoneType2, "zone002", theHub.id, [label:zoneName2, name:zoneType2]) 90 | } 91 | if (zoneName3 && zoneType3) { 92 | log.debug "create a $zoneType3 named $zoneName3" 93 | def d = addChildDevice("com.obycode", "Virtual " + zoneType3, "zone003", theHub.id, [label:zoneName3, name:zoneType3]) 94 | } 95 | if (zoneName4 && zoneType4) { 96 | log.debug "create a $zoneType4 named $zoneName4" 97 | def d = addChildDevice("com.obycode", "Virtual " + zoneType4, "zone004", theHub.id, [label:zoneName4, name:zoneType4]) 98 | } 99 | if (zoneName5 && zoneType5) { 100 | log.debug "create a $zoneType5 named $zoneName5" 101 | def d = addChildDevice("com.obycode", "Virtual " + zoneType5, "zone005", theHub.id, [label:zoneName5, name:zoneType5]) 102 | } 103 | if (zoneName6 && zoneType6) { 104 | log.debug "create a $zoneType6 named $zoneName6" 105 | def d = addChildDevice("com.obycode", "Virtual " + zoneType6, "zone006", theHub.id, [label:zoneName6, name:zoneType6]) 106 | } 107 | if (zoneName7 && zoneType7) { 108 | log.debug "create a $zoneType7 named $zoneName7" 109 | def d = addChildDevice("com.obycode", "Virtual " + zoneType7, "zone007", theHub.id, [label:zoneName7, name:zoneType7]) 110 | } 111 | if (zoneName8 && zoneType8) { 112 | log.debug "create a $zoneType8 named $zoneName8" 113 | def d = addChildDevice("com.obycode", "Virtual " + zoneType8, "zone008", theHub.id, [label:zoneName8, name:zoneType8]) 114 | } 115 | if (zoneName9 && zoneType9) { 116 | log.debug "create a $zoneType9 named $zoneName9" 117 | def d = addChildDevice("com.obycode", "Virtual " + zoneType9, "zone009", theHub.id, [label:zoneName9, name:zoneType9]) 118 | } 119 | if (zoneName10 && zoneType10) { 120 | log.debug "create a $zoneType10 named $zoneName10" 121 | def d = addChildDevice("com.obycode", "Virtual " + zoneType10, "zone010", theHub.id, [label:zoneName10, name:zoneType10]) 122 | } 123 | if (zoneName11 && zoneType11) { 124 | log.debug "create a $zoneType11 named $zoneName11" 125 | def d = addChildDevice("com.obycode", "Virtual " + zoneType11, "zone011", theHub.id, [label:zoneName11, name:zoneType11]) 126 | } 127 | if (zoneName12 && zoneType12) { 128 | log.debug "create a $zoneType12 named $zoneName12" 129 | def d = addChildDevice("com.obycode", "Virtual " + zoneType12, "zone012", theHub.id, [label:zoneName12, name:zoneType12]) 130 | } 131 | if (zoneName13 && zoneType13) { 132 | log.debug "create a $zoneType13 named $zoneName13" 133 | def d = addChildDevice("com.obycode", "Virtual " + zoneType13, "zone013", theHub.id, [label:zoneName13, name:zoneType13]) 134 | } 135 | if (zoneName14 && zoneType14) { 136 | log.debug "create a $zoneType14 named $zoneName14" 137 | def d = addChildDevice("com.obycode", "Virtual " + zoneType14, "zone014", theHub.id, [label:zoneName14, name:zoneType14]) 138 | } 139 | if (zoneName15 && zoneType15) { 140 | log.debug "create a $zoneType15 named $zoneName15" 141 | def d = addChildDevice("com.obycode", "Virtual " + zoneType15, "zone015", theHub.id, [label:zoneName15, name:zoneType15]) 142 | } 143 | if (zoneName16 && zoneType16) { 144 | log.debug "create a $zoneType16 named $zoneName16" 145 | def d = addChildDevice("com.obycode", "Virtual " + zoneType16, "zone016", theHub.id, [label:zoneName16, name:zoneType16]) 146 | } 147 | } 148 | 149 | def uninstalled() { 150 | unsubscribe() 151 | def delete = getChildDevices() 152 | delete.each { 153 | deleteChildDevice(it.deviceNetworkId) 154 | } 155 | //deleteList(getChildDevices()) 156 | } 157 | 158 | def deleteList(l) { 159 | l.each { 160 | def dni = it.deviceNetworkId 161 | deleteChildDevice(dni) 162 | } 163 | } 164 | 165 | def zoneChanged(evt) { 166 | log.debug "got evt.value: ${evt.value}" 167 | def parts = evt.value.tokenize('.') 168 | log.debug "got parts: $parts" 169 | def zone = parts[0] 170 | log.debug "Zone $zone changed" 171 | def children = getChildDevices() 172 | def sensor = children.find{ d -> d.deviceNetworkId == "zone$zone" } 173 | log.debug "got sensor $sensor" 174 | if (sensor) { 175 | switch(parts[1]) { 176 | case "open": 177 | sensor.open() 178 | break 179 | case "close": 180 | sensor.close() 181 | break 182 | } 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /Arduino/HomeAlarm/HomeAlarm.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | //#define DEBUG_ENABLE 1 6 | 7 | #define PIN_THING_LED 13 8 | 9 | #define BUFFER_SIZE 128 10 | #define MAX_ZONES 64 11 | 12 | #define UPDATE_PERIOD_ARM 25283 13 | #define UPDATE_PERIOD_ALARM 30123 14 | #define UPDATE_PERIOD_ZONE 50234 15 | 16 | SmartThingsCallout_t messageCallout; // call out function forward decalaration 17 | SmartThingsMega smartthing(&Serial2, messageCallout, "GenericShield", false); // constructor 18 | Timer timer; 19 | char buffer[BUFFER_SIZE]; 20 | boolean zones[MAX_ZONES]; 21 | char armed; 22 | char mode; 23 | boolean readyStatus; 24 | boolean alarm; 25 | int bufferIdx; 26 | 27 | void setup() 28 | { 29 | // setup hardware pins 30 | pinMode(PIN_THING_LED, OUTPUT); // define PIN_LED as an output 31 | digitalWrite(PIN_THING_LED, LOW); // set value to LOW (off) to match stateLED=0 32 | smartthing.shieldSetLED(0, 0, 0); 33 | // setup IT-100 serial port 34 | Serial1.begin(9600); 35 | 36 | // setup debug port 37 | #ifdef DEBUG_ENABLE 38 | Serial.begin(9600); 39 | Serial.println("Ready"); 40 | #endif 41 | // initialize variables 42 | bufferIdx = 0; 43 | readyStatus = true; 44 | armed = '0'; 45 | alarm = false; 46 | 47 | // Now increase the baud rate 48 | // alarmSetBaudRate(); 49 | 50 | alarmStatusRequest(); 51 | } 52 | 53 | 54 | void loop() 55 | { 56 | char data; 57 | // update periodic events 58 | timer.update(); 59 | // run smartthing logic 60 | smartthing.run(); 61 | // process IT-100 messages 62 | if (Serial1.available() > 0) 63 | { 64 | data = Serial1.read(); 65 | #ifdef DEBUG_ENABLE 66 | Serial.print(data); 67 | #endif 68 | // if end of message then send to the cloud 69 | if (data == '\r' && bufferIdx > 0) 70 | { 71 | #ifdef DEBUG_ENABLE 72 | Serial.println("processing cmd"); 73 | #endif 74 | // create String object 75 | buffer[bufferIdx] = '\0'; 76 | bufferIdx = 0; 77 | String str(buffer); 78 | // process IT-100 message 79 | if (str.length() > 4) 80 | { 81 | String cmd = str.substring(0,3); 82 | // zone open 83 | if (cmd.equals("609")) 84 | { 85 | String msg = "ZN:" + str.substring(0, 6); 86 | #ifdef DEBUG_ENABLE 87 | Serial.println("Zone " + str.substring(3,6) + " opened"); 88 | #endif 89 | smartthing.send(msg); 90 | } 91 | // zone closed 92 | else if (cmd.equals("610")) 93 | { 94 | String msg = "ZN:" + str.substring(0, 6); 95 | #ifdef DEBUG_ENABLE 96 | Serial.println("Zone " + str.substring(3,6) + " closed"); 97 | #endif 98 | smartthing.send(msg); 99 | } 100 | // ready 101 | else if (cmd.equals("650")) 102 | { 103 | readyStatus = true; 104 | #ifdef DEBUG_ENABLE 105 | Serial.println("Ready"); 106 | #endif 107 | sendReadyStatus(); 108 | } 109 | // not ready 110 | else if (cmd.equals("651")) 111 | { 112 | readyStatus = false; 113 | #ifdef DEBUG_ENABLE 114 | Serial.println("Not Ready"); 115 | #endif 116 | sendReadyStatus(); 117 | } 118 | // exit delay (arming) 119 | else if (cmd.equals("656")) 120 | { 121 | armed = '2'; 122 | #ifdef DEBUG_ENABLE 123 | Serial.println("Arming"); 124 | #endif 125 | sendArmStatus(); 126 | } 127 | // armed 128 | else if (cmd.equals("652")) 129 | { 130 | digitalWrite(PIN_THING_LED, HIGH); // turn LED on 131 | smartthing.shieldSetLED(0, 0, 1); 132 | armed = '1'; 133 | mode = str[4]; 134 | #ifdef DEBUG_ENABLE 135 | Serial.println("Armed " + mode); 136 | #endif 137 | sendArmStatus(); 138 | } 139 | // disarmed (and alarm clear) 140 | else if (cmd.equals("655")) 141 | { 142 | // update status 143 | digitalWrite(PIN_THING_LED, LOW); // turn LED off 144 | smartthing.shieldSetLED(0, 0, 0); 145 | armed = '0'; 146 | alarm = false; 147 | #ifdef DEBUG_ENABLE 148 | Serial.println("Disarmed"); 149 | #endif 150 | sendArmStatus(); 151 | sendAlarmStatus(); 152 | } 153 | // alarm triggered 154 | else if (cmd.equals("654")) 155 | { 156 | alarm = true; 157 | #ifdef DEBUG_ENABLE 158 | Serial.println("Alarming"); 159 | #endif 160 | sendAlarmStatus(); 161 | } 162 | else if (cmd.equals("900")) 163 | { 164 | #ifdef DEBUG_ENABLE 165 | Serial.println("Need code"); 166 | #endif 167 | alarmSendCode(); 168 | } 169 | // LCD Update 170 | else if (cmd.equals("901")) 171 | { 172 | #ifdef DEBUG_ENABLE 173 | Serial.println("LCD update"); 174 | Serial.println(str); 175 | #endif 176 | // See if the chime was turned on or off 177 | if (str.indexOf("Door Chime") >= 0) { 178 | if (str.indexOf("ON") >= 0) 179 | sendChimeStatus(true); 180 | else 181 | sendChimeStatus(false); 182 | } 183 | } 184 | #ifdef DEBUG_ENABLE 185 | else { 186 | Serial.println("unsupported message"); 187 | Serial.println(str); 188 | } 189 | #endif 190 | } 191 | } 192 | // otherwise append to buffer (ignore \n) 193 | else if (data != '\n') 194 | { 195 | buffer[bufferIdx] = data; 196 | bufferIdx++; 197 | // check for buffer overruns 198 | if (bufferIdx >= BUFFER_SIZE) 199 | { 200 | smartthing.send("ER:Buffer overrun"); 201 | bufferIdx = 0; 202 | } 203 | } 204 | } 205 | } 206 | 207 | void sendArmStatus() 208 | { 209 | String msg = String("AR:"); 210 | msg = msg + armed + mode; 211 | smartthing.send(msg); 212 | #ifdef DEBUG_ENABLE 213 | Serial.println(); 214 | Serial.print(msg); 215 | #endif 216 | } 217 | 218 | void sendReadyStatus() 219 | { 220 | String msg = String("RD:"); 221 | if (readyStatus) 222 | { 223 | msg = msg + "1"; 224 | } 225 | else 226 | { 227 | msg = msg + "0"; 228 | } 229 | smartthing.send(msg); 230 | #ifdef DEBUG_ENABLE 231 | Serial.println(); 232 | Serial.print(msg); 233 | #endif 234 | } 235 | 236 | void sendAlarmStatus() 237 | { 238 | String msg = String("AL:"); 239 | if (alarm) 240 | { 241 | msg = msg + "1"; 242 | } 243 | else 244 | { 245 | msg = msg + "0"; 246 | } 247 | smartthing.send(msg); 248 | #ifdef DEBUG_ENABLE 249 | Serial.println(); 250 | Serial.print(msg); 251 | #endif 252 | } 253 | 254 | void sendChimeStatus(boolean state) 255 | { 256 | String msg = String("CH:"); 257 | if (state) 258 | { 259 | msg = msg + "1"; 260 | } 261 | else 262 | { 263 | msg = msg + "0"; 264 | } 265 | smartthing.send(msg); 266 | #ifdef DEBUG_ENABLE 267 | Serial.println(); 268 | Serial.print(msg); 269 | #endif 270 | } 271 | 272 | void sendZoneStatus() 273 | { 274 | String msg = String("ZN:"); 275 | for (int n=0; n 9 | 10 | //***************************************************************************** 11 | void SmartThingsMega::debugPrintBuffer(String prefix, uint8_t * pBuf, uint_fast8_t nBuf) 12 | { 13 | if(_isDebugEnabled) 14 | { 15 | Serial.print(prefix); 16 | for(uint_fast8_t i = 0; i < nBuf; i++) 17 | { 18 | Serial.print(char(pBuf[i])); 19 | } 20 | Serial.println(); 21 | } 22 | } 23 | 24 | //***************************************************************************** 25 | bool SmartThingsMega::isRxLine(uint8_t * pLine) 26 | { 27 | // line starts with "T00000000:RX" 28 | int validRxLineLength = 12; // TODO: What is a real value for this length? 29 | 30 | // return line.length > validRxLineLength && line[0] == 'T' && line[9] = ':' && line[10] == 'R' && line[11] == 'X'; 31 | return ((pLine[0] == 'T') && (pLine[9] == ':') && (pLine[10] == 'R') && (pLine[11] == 'X')); 32 | } 33 | 34 | //******************************************************************************* 35 | bool SmartThingsMega::isAsciiHex(uint8_t ascii) 36 | { 37 | bool retVal = false; 38 | if ( 39 | ((ascii >= 'A') && (ascii <= 'F')) || 40 | ((ascii >= 'a') && (ascii <= 'f')) || 41 | ((ascii >= '0') && (ascii <= '9')) 42 | ) 43 | { 44 | retVal = true; 45 | } 46 | return retVal; 47 | } 48 | 49 | //******************************************************************************* 50 | /// @note this function doesn't check for hex validity before converting 51 | //******************************************************************************* 52 | uint8_t SmartThingsMega::asciiToHexU8(uint8_t pAscii[2]) 53 | { 54 | uint8_t hex; 55 | hex = ((pAscii[0] - (((pAscii[0]>>6) & 0x1) * 0x37)) & 0xF); 56 | hex <<= 4; 57 | hex |= ((pAscii[1] - (((pAscii[1]>>6) & 0x1) * 0x37)) & 0xF); 58 | return hex; 59 | } 60 | 61 | //***************************************************************************** 62 | uint_fast8_t SmartThingsMega::translatePayload(uint8_t *pBuf, uint_fast8_t nBuf, char* payloadString) 63 | { 64 | uint_fast8_t payloadLength = 0; // return value 65 | uint_fast8_t payloadStart = 0; 66 | uint_fast8_t payloadEnd = 0; 67 | 68 | uint_fast8_t i; 69 | 70 | // find [ ] message from the back of the message 71 | for(i = nBuf-1; i > 0; i--) 72 | { 73 | if(pBuf[i] == ']') 74 | { 75 | payloadEnd = i; 76 | } 77 | else if(pBuf[i] == '[') 78 | { 79 | payloadStart = i; 80 | break; 81 | } 82 | } 83 | 84 | if(_isDebugEnabled) 85 | { 86 | Serial.print("payload start: "); 87 | Serial.print(payloadStart); 88 | Serial.print(" end: "); 89 | Serial.print(payloadEnd); 90 | Serial.print(" : "); 91 | for(i = payloadStart+1; i < payloadEnd; i++) 92 | { 93 | Serial.print(pBuf[i]); 94 | Serial.print(' '); 95 | } 96 | Serial.println(); 97 | } 98 | 99 | // int expectedPayloadLength = (payloadEnd - payloadStart) / 3; // TODO: Verify this, but 2 chars for byte and 1 for space char 100 | // char payloadString[expectedPayloadLength]; 101 | if((payloadStart != 0) && (payloadEnd != 0) && (payloadEnd - payloadStart > 4) && (pBuf[payloadStart+1] == '0') && (pBuf[payloadStart+2] == 'A')) 102 | { // if valid message then parse 103 | i = payloadStart+4; // start+3 should be ' ' 104 | while (i < payloadEnd) 105 | { 106 | if(pBuf[i] != ' ') 107 | { 108 | if(isAsciiHex(pBuf[i]) && isAsciiHex(pBuf[i+1]) ) 109 | { 110 | uint8_t hex = asciiToHexU8(&(pBuf[i])); 111 | payloadString[payloadLength++] = hex; 112 | i++; 113 | } 114 | } 115 | i++; 116 | } 117 | } 118 | 119 | payloadString[payloadLength] = 0x0; // null-terminate the string 120 | return payloadLength; 121 | } 122 | 123 | //***************************************************************************** 124 | void SmartThingsMega::_process(void) 125 | { 126 | uint32_t nowMilliseconds = millis(); 127 | 128 | if((nowMilliseconds < _lastShieldMS) || ((nowMilliseconds - _lastShieldMS) > 5000)) 129 | { 130 | _shieldGetNetworkInfo(); 131 | _lastShieldMS = nowMilliseconds; 132 | } 133 | else if((_networkState == STATE_JOINED) && 134 | ((nowMilliseconds < _lastPingMS) || ((nowMilliseconds - _lastPingMS) > 60000))) 135 | { // ping every minutes or on rollover 136 | send("ping"); 137 | _lastPingMS = nowMilliseconds; 138 | } 139 | 140 | // check for return character 141 | } 142 | 143 | //***************************************************************************** 144 | void SmartThingsMega::handleLine(void) 145 | { 146 | if(_nBufRX > 0) 147 | { 148 | if(isRxLine(_pBufRX)) 149 | { 150 | debugPrintBuffer("->| ", _pBufRX, _nBufRX); 151 | { 152 | char messageBuf[255]; // TODO: Figure this out 153 | uint_fast8_t messageBufLength = translatePayload(_pBufRX, _nBufRX, messageBuf); 154 | 155 | if(messageBufLength > 0) 156 | { 157 | debugPrintBuffer("->| payload :: ",(uint8_t *)messageBuf, messageBufLength); 158 | 159 | _calloutFunction(messageBuf); // call out to main application 160 | // that.handleSmartThingMessage(message); 161 | } 162 | else 163 | { 164 | debugPrintBuffer("->| no payload from :: ", _pBufRX, _nBufRX); 165 | } 166 | } 167 | } 168 | else 169 | { //XXX Totally slapped together since this is temp-- will go away with command set change 170 | uint_fast8_t i=0; 171 | bool found = false; 172 | if (_nBufRX >= 32) //netinfo:0022A3000000B675,E30E,02 173 | { 174 | while (i < _nBufRX) 175 | { 176 | if ( 177 | (_pBufRX[i ] == 'n') && 178 | (_pBufRX[i+1] == 'e') && 179 | (_pBufRX[i+2] == 't') && 180 | (_pBufRX[i+3] == 'i') && 181 | (_pBufRX[i+4] == 'n') && 182 | (_pBufRX[i+5] == 'f') && 183 | (_pBufRX[i+6] == 'o') && 184 | (_pBufRX[i+7] == ':') && 185 | (_pBufRX[i+24] == ',') && 186 | (_pBufRX[i+29] == ',') 187 | ) 188 | { 189 | // parse off EUI 190 | if( 191 | isAsciiHex(_pBufRX[i+8]) && 192 | isAsciiHex(_pBufRX[i+9]) && 193 | isAsciiHex(_pBufRX[i+10]) && 194 | isAsciiHex(_pBufRX[i+11]) && 195 | isAsciiHex(_pBufRX[i+12]) && 196 | isAsciiHex(_pBufRX[i+13]) && 197 | isAsciiHex(_pBufRX[i+14]) && 198 | isAsciiHex(_pBufRX[i+15]) && 199 | isAsciiHex(_pBufRX[i+16]) && 200 | isAsciiHex(_pBufRX[i+17]) && 201 | isAsciiHex(_pBufRX[i+18]) && 202 | isAsciiHex(_pBufRX[i+19]) && 203 | isAsciiHex(_pBufRX[i+20]) && 204 | isAsciiHex(_pBufRX[i+21]) && 205 | isAsciiHex(_pBufRX[i+22]) && 206 | isAsciiHex(_pBufRX[i+23]) && 207 | 208 | isAsciiHex(_pBufRX[i+25]) && 209 | isAsciiHex(_pBufRX[i+26]) && 210 | isAsciiHex(_pBufRX[i+27]) && 211 | isAsciiHex(_pBufRX[i+28]) && 212 | 213 | isAsciiHex(_pBufRX[i+30]) && 214 | isAsciiHex(_pBufRX[i+31]) 215 | ) 216 | { 217 | uint8_t tempNetStat = asciiToHexU8(&(_pBufRX[i+30])); 218 | if (tempNetStat <= STATE_LEAVING) // make sure it maps to the enum 219 | { 220 | _networkState = (SmartThingsNetworkState_t)tempNetStat; 221 | 222 | _nodeID = asciiToHexU8(&(_pBufRX[i+25])); 223 | _nodeID <<= 8; 224 | _nodeID |= asciiToHexU8(&(_pBufRX[i+27])); 225 | 226 | _eui64[7] = asciiToHexU8(&(_pBufRX[i+8 ])); 227 | _eui64[6] = asciiToHexU8(&(_pBufRX[i+10])); 228 | _eui64[5] = asciiToHexU8(&(_pBufRX[i+12])); 229 | _eui64[4] = asciiToHexU8(&(_pBufRX[i+14])); 230 | _eui64[3] = asciiToHexU8(&(_pBufRX[i+16])); 231 | _eui64[2] = asciiToHexU8(&(_pBufRX[i+18])); 232 | _eui64[1] = asciiToHexU8(&(_pBufRX[i+20])); 233 | _eui64[0] = asciiToHexU8(&(_pBufRX[i+22])); 234 | 235 | debugPrintBuffer(" |~> ", &(_pBufRX[i]), 32); 236 | found = true; 237 | } 238 | } 239 | } 240 | i++; 241 | } 242 | } 243 | if (found == false) 244 | debugPrintBuffer("->| IGNORING :: ", _pBufRX, _nBufRX); 245 | } 246 | _nBufRX = 0; 247 | } 248 | } 249 | //***************************************************************************** 250 | void SmartThingsMega::_shieldGetNetworkInfo(void) 251 | { 252 | _prt->print("custom netinfo"); 253 | _prt->print('\n'); 254 | 255 | if(_isDebugEnabled) 256 | { 257 | Serial.print(" |<~ "); 258 | Serial.print("custom netinfo"); 259 | Serial.print('\n'); 260 | } 261 | } 262 | 263 | 264 | //***************************************************************************** 265 | // Thing API | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 266 | // V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V V 267 | //***************************************************************************** 268 | SmartThingsMega::SmartThingsMega(HardwareSerial *prt, SmartThingsCallout_t *callout, String shieldType, bool enableDebug) : 269 | _prt(prt), 270 | _calloutFunction(callout), 271 | _isDebugEnabled(enableDebug), 272 | _nBufRX(0), 273 | _lastPingMS(0xFFFFFF00), 274 | _lastShieldMS(0xFFFFFF00), 275 | _networkState(STATE_UNKNOWN) 276 | { 277 | uint_fast8_t i; 278 | 279 | i = shieldType.length(); 280 | if (i > 32) 281 | i = 32; 282 | _shieldTypeLen = i; 283 | 284 | while (i--) 285 | { 286 | _shieldTypeBuf[i] = (uint8_t)shieldType[i]; 287 | } 288 | 289 | _prt->begin(2400); 290 | } 291 | 292 | //***************************************************************************** 293 | //SmartThings::~SmartThings() : ~SoftwareSerial() 294 | SmartThingsMega::~SmartThingsMega() 295 | { 296 | } 297 | 298 | //***************************************************************************** 299 | void SmartThingsMega::run(void) 300 | { 301 | while((_nBufRX < SMARTTHINGS_RX_BUFFER_SIZE) && _prt->available()) 302 | { 303 | #if 0 304 | _pBufRX[_nBufRX++] = read(); 305 | #else 306 | uint8_t readByte = _prt->read(); 307 | if((readByte == 0x0D) || (readByte == 0x0A)) 308 | { // handle data from SmartThing line-by-line 309 | handleLine(); 310 | } 311 | else 312 | { 313 | // keep track of everything that comes in until we reach a newline 314 | // TODO(cwvh): validate bufferlength 1988-10-19 315 | //if (_nBufRX > 200) 316 | // panic("too many characters!"); 317 | _pBufRX[_nBufRX++] = readByte; 318 | } 319 | #endif 320 | } 321 | _process(); 322 | } 323 | 324 | //***************************************************************************** 325 | void SmartThingsMega::send(String message) 326 | { 327 | // e.g. thing.print("raw 0x0 {00 00 0A 0A 62 75 74 74 6f 6e 20 64 6f 77 6e }"); 328 | _prt->print("raw 0x0 { 00 00 0A 0A "); 329 | if(_isDebugEnabled) 330 | { 331 | Serial.print("<-| "); 332 | Serial.print("raw 0x0 { 00 00 0A 0A "); 333 | } 334 | 335 | for(int i = 0; i < message.length(); i++) 336 | { 337 | char c = message[i]; 338 | 339 | _prt->print(c, HEX); 340 | _prt->print(' '); 341 | 342 | if(_isDebugEnabled) 343 | { 344 | Serial.print(c, HEX); 345 | Serial.print(' '); 346 | } 347 | } 348 | 349 | _prt->print('}'); 350 | _prt->print('\n'); 351 | if(_isDebugEnabled) 352 | { 353 | Serial.print('}'); 354 | Serial.print('\n'); 355 | } 356 | 357 | _prt->print("send 0x0 1 1"); 358 | _prt->print('\n'); 359 | } 360 | 361 | //***************************************************************************** 362 | void SmartThingsMega::shieldSetLED(uint8_t red, uint8_t green, uint8_t blue) 363 | { 364 | if (red > 9) red = 9; 365 | if (green > 9) green = 9; 366 | if (blue > 9) blue = 9; 367 | 368 | _prt->print("custom rgb "); 369 | _prt->write( (red+'0') ); 370 | _prt->print(' '); 371 | _prt->write( (green+'0') ); 372 | _prt->print(' '); 373 | _prt->write( (blue+'0') ); 374 | _prt->print(' '); 375 | _prt->print('\n'); 376 | 377 | if(_isDebugEnabled) 378 | { 379 | Serial.print(" |<~ "); 380 | Serial.print("custom rgb "); 381 | Serial.write(red+'0'); 382 | Serial.print(' '); 383 | Serial.write(green+'0'); 384 | Serial.print(' '); 385 | Serial.write(blue+'0'); 386 | Serial.print(' '); 387 | Serial.print('\n'); 388 | } 389 | } 390 | 391 | 392 | //***************************************************************************** 393 | SmartThingsNetworkState_t SmartThingsMega::shieldGetLastNetworkState(void) 394 | { 395 | return _networkState; 396 | } 397 | 398 | //***************************************************************************** 399 | SmartThingsNetworkState_t SmartThingsMega::shieldGetNetworkState(void) 400 | { 401 | _shieldGetNetworkInfo(); 402 | return _networkState; 403 | } 404 | 405 | //***************************************************************************** 406 | uint16_t SmartThingsMega::shieldGetNodeID(void) 407 | { 408 | _shieldGetNetworkInfo(); 409 | return _nodeID; 410 | } 411 | 412 | //***************************************************************************** 413 | void SmartThingsMega::shieldGetEUI64(uint8_t eui[8]) 414 | { 415 | _shieldGetNetworkInfo(); 416 | { 417 | uint_fast8_t i = 7; 418 | do 419 | { 420 | eui[i] = _eui64[i]; 421 | } 422 | while (i--); 423 | } 424 | } 425 | 426 | //***************************************************************************** 427 | void SmartThingsMega::shieldFindNetwork(void) 428 | { 429 | _prt->print("custom find"); 430 | _prt->print('\n'); 431 | 432 | if(_isDebugEnabled) 433 | { 434 | Serial.print(" |<~ "); 435 | Serial.print("custom find"); 436 | Serial.print('\n'); 437 | } 438 | } 439 | 440 | //***************************************************************************** 441 | void SmartThingsMega::shieldLeaveNetwork(void) 442 | { 443 | _prt->print("custom leave"); 444 | _prt->print('\n'); 445 | 446 | if(_isDebugEnabled) 447 | { 448 | Serial.print(" |<~ "); 449 | Serial.print("custom leave"); 450 | Serial.print('\n'); 451 | } 452 | } 453 | -------------------------------------------------------------------------------- /Arduino/libraries/SmartThingsMega/SmartThingsMega.h: -------------------------------------------------------------------------------- 1 | //******************************************************************************* 2 | /// @file 3 | /// @brief 4 | /// SmartThings Arduino Library 5 | /// @section License 6 | /// (C) Copyright 2013 Physical Graph 7 | //******************************************************************************* 8 | #ifndef __SMARTTHINGS_H__ 9 | #define __SMARTTHINGS_H__ 10 | 11 | #include 12 | #include 13 | 14 | //******************************************************************************* 15 | /// @brief SmartThings Arduino Library Version 16 | //******************************************************************************* 17 | #define SMARTTHINGSLIB_VERSION_MAJOR 0 18 | #define SMARTTHINGSLIB_VERSION_MINOR 0 19 | #define SMARTTHINGSLIB_VERSION_BUILD 5 20 | 21 | #define SMARTTHINGSLIB_VERSION \ 22 | (((SMARTTHINGSLIB_VERSION_MAJOR & 0xFF) << 24) |\ 23 | ((SMARTTHINGSLIB_VERSION_MINOR & 0xFF) << 16) |\ 24 | (SMARTTHINGSLIB_VERSION_BUILD & 0xFFFF)) 25 | 26 | //******************************************************************************* 27 | #define SMARTTHINGS_RX_BUFFER_SIZE 256 // if > 255: change _nBufRX to u16 28 | #define SMARTTHINGS_SHIELDTYPE_SIZE 32 // if > 255: change _shieldTypeLen to u16 29 | 30 | //******************************************************************************* 31 | /// @brief Callout Function Definition for Messages Received over ZigBee Network 32 | //******************************************************************************* 33 | typedef void SmartThingsCallout_t(String message); 34 | 35 | //******************************************************************************* 36 | /// @brief ZigBee Network State Definition 37 | //******************************************************************************* 38 | typedef enum 39 | { 40 | STATE_NO_NETWORK, 41 | STATE_JOINING, 42 | STATE_JOINED, 43 | STATE_JOINED_NOPARENT, 44 | STATE_LEAVING, 45 | STATE_UNKNOWN 46 | } SmartThingsNetworkState_t; 47 | 48 | //******************************************************************************* 49 | // 50 | class SmartThingsMega 51 | { 52 | private: 53 | HardwareSerial *_prt; 54 | SmartThingsCallout_t *_calloutFunction; 55 | bool _isDebugEnabled; 56 | uint32_t _lastPingMS; 57 | uint32_t _lastShieldMS; 58 | 59 | SmartThingsNetworkState_t _networkState; 60 | uint8_t _eui64[8]; 61 | uint16_t _nodeID; 62 | 63 | uint8_t _shieldTypeBuf[SMARTTHINGS_SHIELDTYPE_SIZE]; 64 | uint8_t _shieldTypeLen; 65 | 66 | uint8_t _pBufRX[SMARTTHINGS_RX_BUFFER_SIZE]; 67 | uint_fast8_t _nBufRX; 68 | 69 | //void debugPrintString(String prefix, String s); 70 | //void debugPrintBuffer(String prefix, byte* b, int len); 71 | 72 | void _shieldGetNetworkInfo(void); 73 | void _process(void); 74 | 75 | void debugPrintBuffer(String prefix, uint8_t * pBuf, uint_fast8_t nBuf); 76 | bool isRxLine(uint8_t * pLine); 77 | bool isAsciiHex(uint8_t ascii); 78 | uint8_t asciiToHexU8(uint8_t pAscii[2]); 79 | uint_fast8_t translatePayload(uint8_t *pBuf, uint_fast8_t nBuf, char* payloadString); 80 | void handleLine(void); 81 | 82 | public: 83 | //******************************************************************************* 84 | /// @brief SmartThings Constructor 85 | /// @param[in] prt - Hardwre serial port 86 | /// @param[in] callout - Set the Callout Function that is called on Msg Reception 87 | /// @param[in] shieldType (optional) - Set the Reported SheildType to the Server 88 | /// @param[in] enableDebug (optional) - Enable internal Library debug 89 | //******************************************************************************* 90 | SmartThingsMega(HardwareSerial *prt, SmartThingsCallout_t *callout, String shieldType="GenericShield", bool enableDebug=false); 91 | 92 | //******************************************************************************* 93 | /// @brief Run SmartThings Library 94 | //******************************************************************************* 95 | void run(void); 96 | 97 | //******************************************************************************* 98 | /// @brief Send Message out over ZigBee to the Hub 99 | /// @param[in] message to send 100 | //******************************************************************************* 101 | void send(String message); 102 | 103 | //******************************************************************************* 104 | /// @brief Set SmartThings Shield MultiColor LED 105 | /// @param[in] red: intensity {0=off to 9=max} 106 | /// @param[in] green: intensity {0=off to 9=max} 107 | /// @param[in] blue: intensity {0=off to 9=max} 108 | //******************************************************************************* 109 | void shieldSetLED(uint8_t red, uint8_t green, uint8_t blue); 110 | 111 | //******************************************************************************* 112 | /// @brief Get Last Read Shield State 113 | /// @return Last Read Network State 114 | //******************************************************************************* 115 | SmartThingsNetworkState_t shieldGetLastNetworkState(void); 116 | 117 | //******************************************************************************* 118 | /// @brief Get Last Read Shield State and Trigger Refresh of Network Info 119 | /// @return Last Read Network State 120 | //******************************************************************************* 121 | SmartThingsNetworkState_t shieldGetNetworkState(void); 122 | 123 | //******************************************************************************* 124 | /// @brief Get Last Read NodeID and Trigger Refresh of Network Info 125 | /// @return Last Read NodeID 126 | //******************************************************************************* 127 | uint16_t shieldGetNodeID(void); 128 | 129 | //******************************************************************************* 130 | /// @brief Get Last Read EUI64 and Trigger Refresh of Network Info 131 | /// @return Last Read EUI64 132 | //******************************************************************************* 133 | void shieldGetEUI64(uint8_t eui[8]); 134 | 135 | //******************************************************************************* 136 | /// @brief Find and Join a Network 137 | //******************************************************************************* 138 | void shieldFindNetwork(void); 139 | 140 | //******************************************************************************* 141 | /// @brief Leave the Current ZigBee Network 142 | //******************************************************************************* 143 | void shieldLeaveNetwork(void); 144 | 145 | //******************************************************************************* 146 | /// @brief Descructor 147 | //******************************************************************************* 148 | ~SmartThingsMega(); 149 | }; 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /Arduino/libraries/Timer/Event.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation; either version 2 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software 14 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 15 | * MA 02110-1301, USA. 16 | */ 17 | 18 | 19 | 20 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * 21 | Code by Simon Monk 22 | http://www.simonmonk.org 23 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 24 | // For Arduino 1.0 and earlier 25 | #if defined(ARDUINO) && ARDUINO >= 100 26 | #include "Arduino.h" 27 | #else 28 | #include "WProgram.h" 29 | #endif 30 | 31 | #include "Event.h" 32 | 33 | 34 | Event::Event() 35 | { 36 | eventType = EVENT_NONE; 37 | } 38 | 39 | 40 | int Event::update() 41 | { 42 | unsigned long now = millis(); 43 | if (now > lastEventTime + period) 44 | { 45 | switch (eventType) 46 | { 47 | case EVENT_EVERY: 48 | (*callback)(); 49 | break; 50 | 51 | case EVENT_OSCILLATE: 52 | pinState = ! pinState; 53 | digitalWrite(pin, pinState); 54 | break; 55 | } 56 | lastEventTime = now; 57 | count++; 58 | } 59 | if (repeatCount > -1 && count >= repeatCount) 60 | { 61 | eventType = EVENT_NONE; 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /Arduino/libraries/Timer/Event.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * This program is free software; you can redistribute it and/or modify 4 | * it under the terms of the GNU General Public License as published by 5 | * the Free Software Foundation; either version 2 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 16 | * MA 02110-1301, USA. 17 | */ 18 | 19 | 20 | 21 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * 22 | Code by Simon Monk 23 | http://www.simonmonk.org 24 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 25 | 26 | #ifndef Event_h 27 | #define Event_h 28 | 29 | #include 30 | 31 | #define EVENT_NONE 0 32 | #define EVENT_EVERY 1 33 | #define EVENT_OSCILLATE 2 34 | 35 | 36 | 37 | class Event 38 | { 39 | 40 | public: 41 | Event(); 42 | int update(); 43 | int eventType; 44 | long period; 45 | int repeatCount; 46 | int pin; 47 | int pinState; 48 | void (*callback)(); 49 | long lastEventTime; 50 | int count; 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /Arduino/libraries/Timer/Timer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation; either version 2 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software 14 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 15 | * MA 02110-1301, USA. 16 | */ 17 | 18 | 19 | 20 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * 21 | Code by Simon Monk 22 | http://www.simonmonk.org 23 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 24 | 25 | // For Arduino 1.0 and earlier 26 | #if defined(ARDUINO) && ARDUINO >= 100 27 | #include "Arduino.h" 28 | #else 29 | #include "WProgram.h" 30 | #endif 31 | 32 | #include "Timer.h" 33 | 34 | 35 | Timer::Timer() 36 | { 37 | } 38 | 39 | int Timer::every(long period, void (*callback)(), int repeatCount) 40 | { 41 | int i = findFreeEventIndex(); 42 | if (i == -1) return -1; 43 | 44 | _events[i].eventType = EVENT_EVERY; 45 | _events[i].period = period; 46 | _events[i].repeatCount = repeatCount; 47 | _events[i].callback = callback; 48 | _events[i].lastEventTime = millis(); 49 | _events[i].count = 0; 50 | return i; 51 | } 52 | 53 | int Timer::every(long period, void (*callback)()) 54 | { 55 | return every(period, callback, -1); // - means forever 56 | } 57 | 58 | int Timer::after(long period, void (*callback)()) 59 | { 60 | return every(period, callback, 1); 61 | } 62 | 63 | int Timer::oscillate(int pin, long period, int startingValue, int repeatCount) 64 | { 65 | int i = findFreeEventIndex(); 66 | if (i == -1) return -1; 67 | 68 | _events[i].eventType = EVENT_OSCILLATE; 69 | _events[i].pin = pin; 70 | _events[i].period = period; 71 | _events[i].pinState = startingValue; 72 | digitalWrite(pin, startingValue); 73 | _events[i].repeatCount = repeatCount * 2; // full cycles not transitions 74 | _events[i].lastEventTime = millis(); 75 | _events[i].count = 0; 76 | return i; 77 | } 78 | 79 | int Timer::oscillate(int pin, long period, int startingValue) 80 | { 81 | oscillate(pin, period, startingValue, -1); // forever 82 | } 83 | 84 | int Timer::pulse(int pin, long period, int startingValue) 85 | { 86 | oscillate(pin, period, startingValue, 1); // once 87 | } 88 | 89 | int Timer::stop(int id) 90 | { 91 | _events[id].eventType = EVENT_NONE; 92 | } 93 | 94 | int Timer::update() 95 | { 96 | for (int i = 0; i < MAX_NUMBER_OF_EVENTS; i++) 97 | { 98 | if (_events[i].eventType != EVENT_NONE) 99 | { 100 | _events[i].update(); 101 | } 102 | } 103 | } 104 | 105 | int Timer::findFreeEventIndex() 106 | { 107 | for (int i = 0; i < MAX_NUMBER_OF_EVENTS; i++) 108 | { 109 | if (_events[i].eventType == EVENT_NONE) 110 | { 111 | return i; 112 | } 113 | } 114 | return -1; 115 | } 116 | 117 | -------------------------------------------------------------------------------- /Arduino/libraries/Timer/Timer.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * This program is free software; you can redistribute it and/or modify 4 | * it under the terms of the GNU General Public License as published by 5 | * the Free Software Foundation; either version 2 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program; if not, write to the Free Software 15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 16 | * MA 02110-1301, USA. 17 | */ 18 | 19 | 20 | 21 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * 22 | Code by Simon Monk 23 | http://www.simonmonk.org 24 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 25 | 26 | #ifndef Timer_h 27 | #define Timer_h 28 | 29 | #include 30 | #include "Event.h" 31 | 32 | #define MAX_NUMBER_OF_EVENTS 10 33 | 34 | 35 | class Timer 36 | { 37 | 38 | public: 39 | Timer(); 40 | 41 | int every(long period, void (*callback)()); 42 | int every(long period, void (*callback)(), int repeatCount); 43 | int after(long duration, void (*callback)()); 44 | int oscillate(int pin, long period, int startingValue); 45 | int oscillate(int pin, long period, int startingValue, int repeatCount); 46 | int pulse(int pin, long period, int startingValue); 47 | int stop(int id); 48 | int update(); 49 | 50 | 51 | protected: 52 | Event _events[MAX_NUMBER_OF_EVENTS]; 53 | int findFreeEventIndex(); 54 | 55 | }; 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /Arduino/libraries/Timer/examples/kitchen_sink/kitchen_sink.pde: -------------------------------------------------------------------------------- 1 | #include "Timer.h" 2 | 3 | Timer t; 4 | 5 | int ledEvent; 6 | 7 | void setup() 8 | { 9 | Serial.begin(9600); 10 | int tickEvent = t.every(2000, doSomething); 11 | Serial.print("2 second tick started id="); 12 | Serial.println(tickEvent); 13 | 14 | pinMode(13, OUTPUT); 15 | ledEvent = t.oscillate(13, 50, HIGH); 16 | Serial.print("LED event started id="); 17 | Serial.println(ledEvent); 18 | 19 | int afterEvent = t.after(10000, doAfter); 20 | Serial.print("After event started id="); 21 | Serial.println(afterEvent); 22 | 23 | } 24 | 25 | void loop() 26 | { 27 | t.update(); 28 | } 29 | 30 | void doSomething() 31 | { 32 | Serial.print("2 second tick: millis()="); 33 | Serial.println(millis()); 34 | } 35 | 36 | 37 | void doAfter() 38 | { 39 | Serial.println("stop the led event"); 40 | t.stop(ledEvent); 41 | t.oscillate(13, 500, HIGH, 5); 42 | } 43 | -------------------------------------------------------------------------------- /Arduino/libraries/Timer/examples/pin_high_10_mins/pin_high_10_mins.pde: -------------------------------------------------------------------------------- 1 | #include "Timer.h" 2 | 3 | Timer t; 4 | int pin = 13; 5 | 6 | void setup() 7 | { 8 | pinMode(pin, OUTPUT); 9 | t.pulse(pin, 10 * 1000, HIGH); // 10 seconds 10 | // t.pulse(pin, 10 * 60 * 1000, HIGH); // 10 minutes 11 | } 12 | 13 | void loop() 14 | { 15 | t.update(); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Arduino/libraries/Timer/examples/read_A0_flashLED/read_A0_flashLED.pde: -------------------------------------------------------------------------------- 1 | #include "Timer.h" 2 | 3 | Timer t; 4 | int pin = 13; 5 | 6 | void setup() 7 | { 8 | Serial.begin(9600); 9 | pinMode(pin, OUTPUT); 10 | t.oscillate(pin, 100, LOW); 11 | t.every(1000, takeReading); 12 | } 13 | 14 | void loop() 15 | { 16 | t.update(); 17 | } 18 | 19 | void takeReading() 20 | { 21 | Serial.println(analogRead(0)); 22 | } 23 | -------------------------------------------------------------------------------- /Arduino/libraries/Timer/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Debounce 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | Timer KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | every KEYWORD2 16 | after KEYWORD2 17 | oscillate KEYWORD2 18 | pulse KEYWORD2 19 | 20 | 21 | ####################################### 22 | # Instances (KEYWORD2) 23 | ####################################### 24 | 25 | ####################################### 26 | # Constants (LITERAL1) 27 | ####################################### 28 | 29 | -------------------------------------------------------------------------------- /Arduino/libraries/readme.txt: -------------------------------------------------------------------------------- 1 | For information on installing libraries, see: http://arduino.cc/en/Guide/Libraries 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /Photos/IMG_20140105_204502.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obycode/DSCAlarmSmartThings/2ccc4a4b6159735f895af115b8a940b6e9ad1ed3/Photos/IMG_20140105_204502.jpg -------------------------------------------------------------------------------- /Photos/IMG_20140105_204512.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obycode/DSCAlarmSmartThings/2ccc4a4b6159735f895af115b8a940b6e9ad1ed3/Photos/IMG_20140105_204512.jpg -------------------------------------------------------------------------------- /Photos/IMG_20140105_204600.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obycode/DSCAlarmSmartThings/2ccc4a4b6159735f895af115b8a940b6e9ad1ed3/Photos/IMG_20140105_204600.jpg -------------------------------------------------------------------------------- /Photos/IMG_20140105_204606.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obycode/DSCAlarmSmartThings/2ccc4a4b6159735f895af115b8a940b6e9ad1ed3/Photos/IMG_20140105_204606.jpg -------------------------------------------------------------------------------- /Photos/IMG_20140105_204627.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obycode/DSCAlarmSmartThings/2ccc4a4b6159735f895af115b8a940b6e9ad1ed3/Photos/IMG_20140105_204627.jpg -------------------------------------------------------------------------------- /Photos/IMG_4266.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obycode/DSCAlarmSmartThings/2ccc4a4b6159735f895af115b8a940b6e9ad1ed3/Photos/IMG_4266.JPG -------------------------------------------------------------------------------- /Photos/IMG_4267.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obycode/DSCAlarmSmartThings/2ccc4a4b6159735f895af115b8a940b6e9ad1ed3/Photos/IMG_4267.JPG -------------------------------------------------------------------------------- /Photos/IMG_4268.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obycode/DSCAlarmSmartThings/2ccc4a4b6159735f895af115b8a940b6e9ad1ed3/Photos/IMG_4268.JPG -------------------------------------------------------------------------------- /Photos/IMG_4269.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obycode/DSCAlarmSmartThings/2ccc4a4b6159735f895af115b8a940b6e9ad1ed3/Photos/IMG_4269.JPG -------------------------------------------------------------------------------- /Photos/IMG_4805.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obycode/DSCAlarmSmartThings/2ccc4a4b6159735f895af115b8a940b6e9ad1ed3/Photos/IMG_4805.JPG -------------------------------------------------------------------------------- /Photos/IMG_4806.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/obycode/DSCAlarmSmartThings/2ccc4a4b6159735f895af115b8a940b6e9ad1ed3/Photos/IMG_4806.JPG -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | See the wiki for details: [Using AlarmThing](https://github.com/obycode/DSCAlarmSmartThings/wiki) 2 | -------------------------------------------------------------------------------- /VirtualContact.groovy: -------------------------------------------------------------------------------- 1 | /** 2 | * Virtual Contact Sensor 3 | * 4 | * Copyright 2014 obycode 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed 12 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing permissions and limitations under the License. 14 | * 15 | */ 16 | metadata { 17 | definition (name: "Virtual Contact Sensor", namespace: "com.obycode", author: "obycode") { 18 | capability "Contact Sensor" 19 | command "open" 20 | command "close" 21 | } 22 | 23 | simulator { 24 | // TODO: define status and reply messages here 25 | } 26 | 27 | tiles(scale: 2) { 28 | multiAttributeTile(name:"contact", type: "generic", width: 6, height: 4, canChangeIcon: true){ 29 | tileAttribute ("device.contact", key: "PRIMARY_CONTROL") { 30 | attributeState "open", label: '${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e" 31 | attributeState "closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821" 32 | } 33 | } 34 | 35 | main "contact" 36 | details(["contact"]) 37 | } 38 | } 39 | 40 | // parse events into attributes 41 | def parse(String description) { 42 | log.debug "Virtual Contact Parsing '${description}'" 43 | // initialize to closed state 44 | if (description == "updated") { 45 | sendEvent(name: "contact", value: "closed") 46 | } 47 | } 48 | 49 | def open() { 50 | sendEvent(name: "contact", value: "open") 51 | } 52 | 53 | def close() { 54 | sendEvent(name: "contact", value: "closed") 55 | } 56 | -------------------------------------------------------------------------------- /VirtualGlassBreak.groovy: -------------------------------------------------------------------------------- 1 | /** 2 | * Virtual Glass Break Sensor 3 | * 4 | * Copyright 2014 obycode 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed 12 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing permissions and limitations under the License. 14 | * 15 | */ 16 | metadata { 17 | definition (name: "Virtual Glass Break Sensor", namespace: "com.obycode", author: "obycode") { 18 | // There is no standard glass break sensor capability, so use motion sensor for now 19 | capability "Motion Sensor" 20 | command "open" 21 | command "close" 22 | } 23 | 24 | simulator { 25 | // TODO: define status and reply messages here 26 | } 27 | 28 | tiles(scale: 2) { 29 | multiAttributeTile(name:"break", type: "generic", width: 6, height: 4, canChangeIcon: true){ 30 | tileAttribute ("device.motion", key: "PRIMARY_CONTROL") { 31 | attributeState "active", label: '${name}', icon:"st.Home.home9", backgroundColor:"#ffa81e" 32 | attributeState "inactive", label:'${name}', icon:"st.Home.home9", backgroundColor:"#79b821" 33 | } 34 | } 35 | main "break" 36 | details(["break"]) 37 | } 38 | } 39 | 40 | // parse events into attributes 41 | def parse(String description) { 42 | log.debug "Virtual Glass Break Parsing '${description}'" 43 | // initialize to closed state 44 | if (description == "updated") { 45 | sendEvent(name: "motion", value: "inactive") 46 | } 47 | } 48 | 49 | def open() { 50 | sendEvent(name: "motion", value: "active") 51 | } 52 | 53 | def close() { 54 | sendEvent(name: "motion", value: "inactive") 55 | } 56 | -------------------------------------------------------------------------------- /VirtualMotion.groovy: -------------------------------------------------------------------------------- 1 | /** 2 | * Virtual Motion Sensor 3 | * 4 | * Copyright 2014 obycode 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 7 | * in compliance with the License. You may obtain a copy of the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed 12 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License 13 | * for the specific language governing permissions and limitations under the License. 14 | * 15 | */ 16 | metadata { 17 | definition (name: "Virtual Motion Sensor", namespace: "com.obycode", author: "obycode") { 18 | capability "Motion Sensor" 19 | command "open" 20 | command "close" 21 | } 22 | 23 | simulator { 24 | // TODO: define status and reply messages here 25 | } 26 | 27 | tiles(scale: 2) { 28 | multiAttributeTile(name:"motion", type: "generic", width: 6, height: 4, canChangeIcon: true){ 29 | tileAttribute ("device.motion", key: "PRIMARY_CONTROL") { 30 | attributeState "active", label: '${name}', icon:"st.motion.motion.inactive", backgroundColor:"#ffa81e" 31 | attributeState "inactive", label:'${name}', icon:"st.motion.motion.active", backgroundColor:"#79b821" 32 | } 33 | } 34 | 35 | main "motion" 36 | details(["motion"]) 37 | } 38 | } 39 | 40 | // parse events into attributes 41 | def parse(String description) { 42 | log.debug "Virtual Motion Parsing '${description}'" 43 | // initialize to closed state 44 | if (description == "updated") { 45 | sendEvent(name: "motion", value: "inactive") 46 | } 47 | } 48 | 49 | def open() { 50 | sendEvent(name: "motion", value: "active") 51 | } 52 | 53 | def close() { 54 | sendEvent(name: "motion", value: "inactive") 55 | } 56 | --------------------------------------------------------------------------------