/**
* Weather Panel
*
* Copyright 2016 Sidney Johnson
* If you like this code, please support the developer via PayPal: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XKDRYZ3RUNR9Y
*
* 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.
*
* Version: 1.0 - Initial Version
* Version: 1.1 - Fixed font size not changing the font size
* Version: 1.2 - Decoupled weather data refresh from wallpaper refresh
* Version: 1.3 - Minor formating tweaks, removed all static data from json
* Version: 2.0 - Addeded 3 day forcast and more formating and presentation tweaks. Removed weather station requirement
* Version: 2.1 - Preloads images for smoother transitions
* Version: 2.1.1 - Added dynamic API URL
* Version: 2.2 - Added support for user selectable Station ID
* Version: 2.2.1 - Added better browser support
* Version: 2.3 - Upgraded Icons
* Version: 2.4 - TWC Weather Update
* Version: 2.5 - Added Rain Switch
*
*/
definition(
name: "Weather Panel",
namespace: "sidjohn1",
author: "Sidney Johnson",
description: "Weather Panel, a SmartThings web client",
category: "Convenience",
iconUrl: "http://cdn.device-icons.smartthings.com/Weather/weather14-icn.png",
iconX2Url: "http://cdn.device-icons.smartthings.com/Weather/weather14-icn@2x.png",
iconX3Url: "http://cdn.device-icons.smartthings.com/Weather/weather14-icn@3x.png",
oauth: true)
preferences {
page(name: "selectDevices")
page(name: "viewURL")
}
def selectDevices() {
dynamicPage(name: "selectDevices", install: true, uninstall: true) {
section("About") {
paragraph "Weather Panel displays inside and outside temp and weather infomation as a web page. Also has a random customizable background serviced by Dropbox public folders."
paragraph "${textVersion()}\n${textCopyright()}"
}
section("Select...") {
input "insideTemp", "capability.temperatureMeasurement", title: "Inside Tempature...", multiple: false, required: true
input "outsideTemp", "capability.temperatureMeasurement", title: "Outside Tempature...", multiple: false, required: false
input "showForcast", "bool", title:"Show Forcast", required: false, multiple:false
input "stationID", "text", title:"Station ID (Optional)", required: false, multiple:false
input "rainswitch", "capability.switch", title:"Rain Switch (Optional)", required: false, multiple:false
}
section(hideable: true, hidden: true, "Optional Settings") {
input "fontColor", "bool", title: "Font Color Black", required: false
input "fontSize", "enum", title:"Select Font Size", required: true, multiple:false, defaultValue: "Medium", metadata: [values: ['xSmall','Small','Medium','Large']]
input "outsideWeather", "capability.temperatureMeasurement", title: "Clear to free weather device", multiple: true, required: false
}
section("Wallpaper URL") {
input "wallpaperUrl", "text", title: "Wallpaper URL",defaultValue: "http://", required:false
}
section() {
href "viewURL", title: "View URL"
}
}
}
def viewURL() {
dynamicPage(name: "viewURL", title: "${title ?: location.name} Weather Pannel URL", install:false) {
section() {
paragraph "Copy the URL below to any modern browser to view your ${title ?: location.name}s' Weather Panel. Add a shortcut to home screen of your mobile device to run as a native app."
input "weatherUrl", "text", title: "URL",defaultValue: "${generateURL("html")}", required:false
href url:"${generateURL("html")}", style:"embedded", required:false, title:"View", description:"Tap to view, then click \"Done\""
}
}
}
mappings {
path("/html") {
action: [
GET: "generateHtml",
]
}
path("/json") {
action: [
GET: "generateJson",
]
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unschedule()
unsubscribe()
initialize()
}
def initialize() {
log.info "Weather Panel ${textVersion()} ${textCopyright()}"
generateURL()
}
def generateHtml() {
render contentType: "text/html", headers: ["Access-Control-Allow-Origin": "*"], data: "\n\n