/** * Rollie Oil Tank Gauge * * Version - 0.6 * * Copyright 2017 David LaPorte * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License * for the specific language governing permissions and limitations under the License. * * Instructions: * * 1) For US, visit: https://graph.api.smartthings.com * 2) For UK, visit: https://graph-eu01-euwest1.api.smartthings.com * 3) Click "My Device Handlers" * 4) Click "New Device Handler" in the top right * 5) Click the "From Code" tab * 6) Paste in the code from: https://github.com/dlaporte/SmartThings/blob/master/DeviceHandlers/rollie-gauge/rollie-gauge.groovy * 7) Click "Create" * 8) Click "Publish -> For Me" * */ include 'asynchttp_v1' preferences { input(title: "", description: "Account Configuration", type: "paragraph", element: "paragraph") input(name: "serial", type: "text", title: "Gauge Serial Number", required: true, displayDuringSetup: true, capitalization: none) input(name: "password", type: "text", title: "Password", required: true, defaultValue: "rollie", displayDuringSetup: true, capitalization: none) input(name: "pid", type: "text", title: "PID", description: "search for \"id='pid'\" in the RollApp HTML", required: true, defaultValue: "0", displayDuringSetup: true, capitalization: none) input(title: "", description: "Alerting Configuration", type: "paragraph", element: "paragraph") input(name: "threshold", type: "number", title: "Low Oil Alert (gallons)", required: true, defaultValue: 15, capitalization: none) input(name: "email", type: "email", title: "Alert Email", required: true, displayDuringSetup: true, capitalization: none) input(name: "sms", type: "phone", title: "Alert SMS Number (10 digits)", required: true, displayDuringSetup: true, capitalization: none) input(title: "", description: "Tank Configuration", type: "paragraph", element: "paragraph") input(name: "tanktype", type: "enum", options: ["0": "275 Vertical", "1": "275 Horizontal", "2": "330 Vertical", "3": "330 Horizonal", "4": "Roth 1000L", "5": "Roth 1500L", "6": "Roth 400L", "7": "Vertical Cylinder", "8": "Horizontal Cylinder", "9": "Square Tank"], defaultValue: "0", title: "Tank Type", displayDuringSetup: true) input(title: "", description: "Vertical Cylinder Measurements (inches, optional) ", type: "paragraph image", image: "https://raw.githubusercontent.com/dlaporte/SmartThings/master/DeviceHandlers/rollie-gauge/images/vertical.png", element: "paragraph") input(name: "v_height", type: "number", title: "Height", required: false) input(name: "v_diameter", type: "number", title: "Diameter", required: false) input(title: "", description: "Horizontal Cylinder Measurements (inches, optional) ", type: "paragraph image", image: "https://raw.githubusercontent.com/dlaporte/SmartThings/master/DeviceHandlers/rollie-gauge/images/horizontal.png", element: "paragraph") input(name: "h_length", type: "number", title: "Length", required: false) input(name: "h_diameter", type: "number", title: "Diameter", required: false) input(title: "", description: "Square Tank Measurements (inches, optional) ", type: "paragraph image", image: "https://raw.githubusercontent.com/dlaporte/SmartThings/master/DeviceHandlers/rollie-gauge/images/square.png", element: "paragraph") input(name: "s_length", type: "number", title: "Length", required: false) input(name: "s_width", type: "number", title: "Width", required: false) input(name: "s_height", type: "number", title: "Height", required: false) } metadata { definition (name: "Rollie Oil Tank Gauge", namespace: "dlaporte", author: "David LaPorte") { capability "Configuration" capability "Polling" capability "Sensor" capability "Actuator" capability "Refresh" // kludge for ActionTiles tile support, "humidity"="percent remaining" capability "relativeHumidityMeasurement" attribute "gallons", "number" attribute "level", "number" } simulator { } tiles(scale: 2) { valueTile("gallons_icon", "device.gallons") { state("gallons", label: '${currentValue} gallons', unit: "gal", icon: "https://raw.githubusercontent.com/dlaporte/SmartThings/master/DeviceHandlers/rollie-gauge/images/oil-icon.png", backgroundColors: [ [value: 0, color: "#bc2323"], [value: 50, color: "#1e9cbb"], [value: 100, color: "#7bb630"] ] ) } multiAttributeTile(name:"summary", type:"generic", width:6, height:4) { tileAttribute("device.gallons", key: "PRIMARY_CONTROL") { attributeState("gallons", label: '${currentValue} gallons', icon: "https://raw.githubusercontent.com/dlaporte/SmartThings/master/DeviceHandlers/rollie-gauge/images/oil-drop-icon-png-large.png", unit: "gal", backgroundColors: [ [value: 0, color: "#bc2323"], [value: 50, color: "#1e9cbb"], [value: 100, color: "#7bb630"] ] ) } tileAttribute("device.level", key: "SECONDARY_CONTROL") { attributeState("level", label: '${currentValue} inches') } } standardTile("today", "today", width: 2, height: 2) { state("default", label: "Today") } valueTile("gallons_today_usage", "device.gallons_today_usage", width: 2, height: 2, decoration: "flat", wordWrap: false) { state("gallons_today_usage", label: '${currentValue}') } valueTile("level_today_usage", "device.level_today_usage", width: 2, height: 2) { state("level_today_usage", label: '${currentValue}') } standardTile("yesterday", "yesterday", width: 2, height: 2) { state("default", label: "Yesterday") } valueTile("gallons_yesterday_usage", "device.gallons_yesterday_usage", width: 2, height: 2, decoration: "flat", wordWrap: false) { state("gallons_yesterday_usage", label: '${currentValue}') } valueTile("level_yesterday_usage", "device.level_yesterday_usage", width: 2, height: 2) { state("level_yesterday_usage", label: '${currentValue}') } standardTile("week", "week", width: 2, height: 2) { state("default", label: "Last Week") } valueTile("gallons_week_usage", "device.gallons_week_usage", width: 2, height: 2, decoration: "flat", wordWrap: false) { state("gallons_week_usage", label: '${currentValue}') } valueTile("level_week_usage", "device.level_week_usage", width: 2, height: 2) { state("level_week_usage", label: '${currentValue}') } standardTile("refresh", "device.poll", inactiveLabel: false, decoration: "flat", width: 2, height: 2) { state("default", action:"polling.poll", icon:"st.secondary.refresh") } standardTile("configure", "device.configure", inactiveLabel: false, decoration: "flat", width: 2, height: 2) { state "configure", label:'', action:"configuration.configure", icon:"st.secondary.configure" } valueTile("updated", "device.updated", inactiveLabel: false, decoration: "flat", width: 2, height: 2) { state "updated", label: 'Updated:\n${currentValue}' } valueTile("level", "device.level", inactiveLabel: false, decoration: "flat", width: 2, height: 2) { state "level", label: '${currentValue} inches' } main "gallons_icon" details(["summary", "today", "gallons_today_usage", "level_today_usage", "yesterday", "gallons_yesterday_usage", "level_yesterday_usage", "week", "gallons_week_usage", "level_week_usage", "updated", "refresh", "configure"]) } } def updated() { log.debug("updated with settings: ${settings.inspect()}") pullAllControllers() pullHistory() } def refresh() { log.debug "refresh called" pullAllControllers() pullHistory() } def poll() { log.debug "poll called" pullAllControllers() pullHistory() } def pullAllControllers() { log.debug "pullAllControllers called" rollieLogin() def params = [ uri: "http://rollieapp.com", path: "/gauges/AllControllers.php", headers: [ "Cookie": data.cookies ] ] try { asynchttp_v1.get('parseAllControllers', params) } catch (e) { log.error "something went wrong: $e" } } def parseAllControllers(response, data) { log.debug "parseAllControllers called" log.debug "Request was successful, ${response.status}" def m if ((m = response.getData() =~ /(?ms)