Ledger Nano X - The secure hardware wallet
SHARE
TWEET

KT ST arduino device handler code

a guest Mar 2nd, 2017 121 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  *  ST_Anything_Doors Device Type - ST_Anything_Doors.device.groovy
  3.  *
  4.  *  Copyright 2015 Daniel Ogorchock
  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.  *  Change History:
  16.  *
  17.  *    Date        Who            What
  18.  *    ----        ---            ----
  19.  *    2015-01-10  Dan Ogorchock  Original Creation
  20.  *
  21.  *
  22.  */
  23.  
  24. metadata {
  25.     definition (name: "ST_Anything_Doors", namespace: "ogiewon", author: "Daniel Ogorchock") {
  26.         capability "Configuration"
  27.         capability "Contact Sensor"
  28.         capability "Motion Sensor"
  29.         capability "Temperature Measurement"
  30.         capability "Relative Humidity Measurement"
  31.         capability "Sensor"
  32.         capability "Polling"
  33.  
  34.         attribute "frontdoubleDoor", "string"
  35.         attribute "backDoor", "string"
  36.         attribute "sunroomDoor", "string"
  37.         attribute "diningroomWindows", "string"
  38.         attribute "kitchennookWindows", "string"
  39.         attribute "sunroomWindows", "string"
  40.         attribute "bedroom1Windows", "string"
  41.         attribute "bedroom2Windows", "string"
  42.         attribute "garageDoor", "string"
  43.        
  44.         command "pushLeft"
  45.         command "pushRight"
  46.     }
  47.  
  48.     simulator {
  49.         status "on":  "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6E"
  50.         status "off": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6666"
  51.  
  52.         // reply messages
  53.         reply "raw 0x0 { 00 00 0a 0a 6f 6e }": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6E"
  54.         reply "raw 0x0 { 00 00 0a 0a 6f 66 66 }": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6666"
  55.     }
  56.    
  57.     // Preferences
  58.     preferences {
  59.         input "temphumidSampleRate", "number", title: "Temperature/Humidity Sensor Sampling Interval (seconds)", description: "Sampling Interval (seconds)", defaultValue: 30, required: true, displayDuringSetup: true
  60.     }
  61.  
  62.     // tile definitions
  63.     tiles {
  64.         standardTile("frontdoubleDoor", "device.frontdoubleDoor", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
  65.             state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
  66.             state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
  67.         }
  68.         standardTile("backDoor", "device.backDoor", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
  69.             state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
  70.             state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
  71.         }
  72.         standardTile("sunroomDoor", "device.sunroomDoor", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
  73.             state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
  74.             state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
  75.         }
  76.         standardTile("diningroomWindows", "device.diningroomWindows", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
  77.             state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
  78.             state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
  79.         }
  80.         standardTile("kitchennookWindows", "device.kitchennookWindows", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
  81.             state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
  82.             state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
  83.         }
  84.         standardTile("sunroomWindows", "device.sunroomWindows", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
  85.             state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
  86.             state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
  87.         }
  88.         standardTile("bedroom1Windows", "device.bedroom1Windows", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
  89.             state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
  90.             state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
  91.         }
  92.         standardTile("bedroom2Windows", "device.bedroom2Windows", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
  93.             state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
  94.             state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
  95.         }
  96.         standardTile("garageDoor", "device.garageDoor", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
  97.             state("open", label:'${name}', icon:"st.contact.contact.open", backgroundColor:"#ffa81e")
  98.             state("closed", label:'${name}', icon:"st.contact.contact.closed", backgroundColor:"#79b821")
  99.         }
  100.  
  101. /*        valueTile("temperature", "device.temperature", width: 1, height: 1) {
  102.             state("temperature", label:'${currentValue}°',
  103.                 backgroundColors:[
  104.                     [value: 31, color: "#153591"],
  105.                     [value: 44, color: "#1e9cbb"],
  106.                     [value: 59, color: "#90d2a7"],
  107.                     [value: 74, color: "#44b621"],
  108.                     [value: 84, color: "#f1d801"],
  109.                     [value: 95, color: "#d04e00"],
  110.                     [value: 96, color: "#bc2323"]
  111.                 ]
  112.             )
  113.         }
  114.         valueTile("humidity", "device.humidity", inactiveLabel: false) {
  115.             state "humidity", label:'${currentValue}% humidity', unit:""
  116.         }
  117.         standardTile("motion", "device.motion", width: 1, height: 1) {
  118.             state("active", label:'motion', icon:"st.motion.motion.active", backgroundColor:"#53a7c0")
  119.             state("inactive", label:'no motion', icon:"st.motion.motion.inactive", backgroundColor:"#ffffff")
  120.         }  
  121.     standardTile("leftDoor", "device.leftDoor", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
  122.             state "closed", label: 'Closed', action: "pushLeft", icon: "st.doors.garage.garage-closed", backgroundColor: "#79b821", nextState: "closed"
  123.             state "open", label: 'Open', action: "pushLeft", icon: "st.doors.garage.garage-open", backgroundColor: "#ffa81e", nextState: "open"
  124.             state "opening", label: 'Opening', action: "pushLeft", icon: "st.doors.garage.garage-opening", backgroundColor: "89C2E8", nextState: "opening"
  125.             state "closing", label: 'Closing', action: "pushLeft", icon: "st.doors.garage.garage-closing", backgroundColor: "89C2E8", nextState: "closing"
  126.         }
  127.         standardTile("rightDoor", "device.rightDoor", width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
  128.             state "closed", label: 'Closed', action: "pushRight", icon: "st.doors.garage.garage-closed", backgroundColor: "#79b821", nextState: "closed"
  129.             state "open", label: 'Open', action: "pushRight", icon: "st.doors.garage.garage-open", backgroundColor: "#ffa81e", nextState: "open"
  130.             state "opening", label: 'Opening', action: "pushRight", icon: "st.doors.garage.garage-opening", backgroundColor: "89C2E8", nextState: "opening"
  131.             state "closing", label: 'Closing', action: "pushRight", icon: "st.doors.garage.garage-closing", backgroundColor: "89C2E8", nextState: "closing"
  132.         }  */
  133.  
  134.         standardTile("configure", "device.configure", inactiveLabel: false, decoration: "flat") {
  135.             state "configure", label:'', action:"configuration.configure", icon:"st.secondary.configure"
  136.         }
  137.        
  138.         main (["frontdoubleDoor"])
  139.         details(["frontdoubleDoor","backDoor","sunroomDoor","diningroomWindows","kitchennookWindows","sunroomWindows","bedroom1Windows","bedroom2Windows","garageDoor","configure"])
  140.     }
  141. }
  142.  
  143. //Map parse(String description) {
  144. def parse(String description) {
  145.     def msg = zigbee.parse(description)?.text
  146.     log.debug "Parse got '${msg}'"
  147.  
  148.     def parts = msg.split(" ")
  149.     def name  = parts.length>0?parts[0].trim():null
  150.     def value = parts.length>1?parts[1].trim():null
  151.  
  152.     name = value != "ping" ? name : null
  153.  
  154.     def result = createEvent(name: name, value: value)
  155.  
  156.     log.debug result
  157.  
  158.     return result
  159. }
  160.  
  161. def pushLeft() {
  162.     log.debug "Executing 'pushLeft' = 'leftDoor on'"
  163.     zigbee.smartShield(text: "leftDoor on").format()
  164. }
  165.  
  166. def pushRight() {
  167.     log.debug "Executing 'pushRight' = 'rightDoor on'"
  168.     zigbee.smartShield(text: "rightDoor on").format()
  169. }
  170.  
  171. def poll() {
  172.     //temporarily implement poll() to issue a configure() command to send the polling interval settings to the arduino
  173.     configure()
  174. }
  175.  
  176. def configure() {
  177.     log.debug "Executing 'configure'"
  178.     log.debug "temphumid " + temphumidSampleRate
  179.     [
  180.         zigbee.smartShield(text: "temphumid " + temphumidSampleRate).format()
  181.     ]
  182. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top