/** * ESP Easy CO2 DTH (v.0.0.1) * * MIT License * * Copyright (c) 2018 * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ import groovy.json.JsonSlurper import groovy.transform.Field metadata { definition (name: "ESP UVB HTTP", namespace: "ShinJjang", author: "ShinJjang") { capability "Sensor" capability "Temperature Measurement" capability "Relative Humidity Measurement" capability "Illuminance Measurement" capability "Refresh" attribute "lastCheckinDate", "date" command "setData" command "refresh" command "timerLoop" command "averageCo" command "updateMinMaxTemps" command "updateMinMaxCo" command "checkNewDay" command "checkPPM" command "ledOnsec" } simulator { } preferences { input "url", "text", title: "ESP IP주소", description: "로컬IP 주소를 입력", required: true input "homekitSet", "enum", title: "홈킷 CO2 경고수치", defaultValue: 1200, options:[800: "800ppm", 900: "900ppm", 1000: "1000ppm", 1100 : "1100ppm", 1200: "1200ppm", 1300 :"1300ppm", 1400 :"1400ppm", 1500 :"1500ppm", 1600: "1600ppm", 1700: "1700ppm", 1800: "1800ppm", 2000: "2000ppm"], displayDuringSetup: true } tiles(scale: 2) { multiAttributeTile(name:"main", type:"generic", width:6, height:4) { tileAttribute("device.illuminance", key: "PRIMARY_CONTROL") { attributeState "illuminance",label:'UVB${currentValue}', backgroundColors:[ [value: 1, color: "#a3da91"], [value: 5, color: "#d8e288"], [value: 10, color: "#f2d33c"], [value: 20, color: "#dd6637"], [value: 30, color: "#77110b"] ] } tileAttribute ("device.lastCheckin", key: "SECONDARY_CONTROL") { attributeState "lastCheckin", label:'Updated: ${currentValue}' } } valueTile("temperature", "device.temperature", width:2, height:2) { state "temperature", label:'${currentValue}°', defaultState: true, backgroundColors:[ [value: 0, color: "#153591"], [value: 5, color: "#1e9cbb"], [value: 10, color: "#90d2a7"], [value: 15, color: "#44b621"], [value: 20, color: "#f1d801"], [value: 25, color: "#d04e00"], [value: 30, color: "#bc2323"], [value: 44, color: "#1e9cbb"], [value: 59, color: "#90d2a7"], [value: 74, color: "#44b621"], [value: 84, color: "#f1d801"], [value: 95, color: "#d04e00"], [value: 96, color: "#bc2323"] ] } valueTile("humidity", "device.humidity", decoration: "flat", width:2, height:2) { state "humidity", label:'${currentValue}%', defaultState: true } main (["main"]) details(["main", "temperature", "humidity"]) } } def updated() { log.debug "URL >> ${url}" state.address = url state.lastTime = new Date().getTime() // state.averageNumber = averageNumber as int state.homekit = homekitSet } def refresh() { } def parse(String description) { def events = [] log.debug "Parsing '${description}'" def msg = parseLanMessage(description) log.debug "headers ${msg.headers}" log.debug "header ${msg.header}" // log.debug "json ${msg.json}" // log.debug "status ${msg.status}" // log.debug "data ${msg.data}" // log.debug "body ${msg.body}" def desc = msg.header.toString() log.debug "def: descr ${desc}" def descr = desc.split("&")[1] log.debug "def: descr1 ${descr}" def slurper = new JsonSlurper() def result = slurper.parseText(descr) log.debug "def: descr3 ${result}" if (result.containsKey("UVB")) { state.uvb = result.UVB as int events << createEvent(name:"illuminance", value: state.uvb ) } if (result.containsKey("Temperature")) { state.temperature = result.Temperature events << createEvent(name:"temperature", value: state.temperature, unit: "C") } if (result.containsKey("Humidity")) { state.humidity = result.Humidity as int events << createEvent(name:"humidity", value: state.humidity, unit: "%") } def nowk = new Date().format("yyyy-MM-dd HH:mm:ss", location.timeZone) def now = new Date() state.lastTime = now.getTime() sendEvent(name: "lastCheckin", value: nowk) return events }