Skip to content

Commit

Permalink
Merge pull request #3837 from SmartThingsCommunity/WWST-2086-wu-twc-c…
Browse files Browse the repository at this point in the history
…hanges

Rolling up WU to TWC changes to production
  • Loading branch information
workingmonk committed Dec 31, 2018
2 parents 17d48b5 + 2237934 commit 7234a92
Show file tree
Hide file tree
Showing 10 changed files with 3,141 additions and 3,273 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,16 @@ def updateWeather() {
// If there is a zipcode defined, weather forecast will be sent. Otherwise, no weather forecast.
if (settings.zipcode) {
log.debug "ZipCode: ${settings.zipcode}"
weather = getWeatherFeature("conditions", settings.zipcode)
weather = getTwcConditions(settings.zipcode)

// Check if the variable is populated, otherwise return.
if (!weather) {
log.debug("Something went wrong, no data found.")
return false
}

def locationScale = getTemperatureScale()
def tempToSend = (locationScale == "C") ? weather.current_observation.temp_c : weather.current_observation.temp_f
def tempToSend = weather.temperature
log.debug("Outdoor Temperature: ${tempToSend} ${locationScale}")
// Right now this can disrupt device health if the device is
// currently offline -- it would be erroneously marked online.
Expand Down Expand Up @@ -569,5 +569,3 @@ def auto() {
def fanAuto() {
log.debug "${device.displayName} does not support fan auto"
}


Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ metadata {
input("away_setpoint", "enum", title: "Away Setpoint", options: ["5", "5.5", "6", "6.5", "7", "7.5", "8", "8.5", "9", "9.5", "10", "10.5", "11", "11.5", "12", "12.5", "13", "13.5", "14", "14.5", "15", "5.5", "15.5", "16", "16.5", "17", "17.5", "18", "18.5", "19", "19.5", "20", "20.5", "21", "21.5", "22", "22.5", "23", "24", "24.5", "25", "25.5", "26", "26.5", "27", "27.5", "28", "28.5", "29", "29.5", "30"], defaultValue: "17", required: true)
input("vacation_setpoint", "enum", title: "Vacation Setpoint", options: ["5", "5.5", "6", "6.5", "7", "7.5", "8", "8.5", "9", "9.5", "10", "10.5", "11", "11.5", "12", "12.5", "13", "13.5", "14", "14.5", "15", "5.5", "15.5", "16", "16.5", "17", "17.5", "18", "18.5", "19", "19.5", "20", "20.5", "21", "21.5", "22", "22.5", "23", "24", "24.5", "25", "25.5", "26", "26.5", "27", "27.5", "28", "28.5", "29", "29.5", "30"], defaultValue: "13", required: true)
input("standby_setpoint", "enum", title: "Standby Setpoint", options: ["5", "5.5", "6", "6.5", "7", "7.5", "8", "8.5", "9", "9.5", "10", "10.5", "11", "11.5", "12", "12.5", "13", "13.5", "14", "14.5", "15", "5.5", "15.5", "16", "16.5", "17", "17.5", "18", "18.5", "19", "19.5", "20", "20.5", "21", "21.5", "22", "22.5", "23", "24", "24.5", "25", "25.5", "26", "26.5", "27", "27.5", "28", "28.5", "29", "29.5", "30"], defaultValue: "5", required: true)
*/
*/
}

tiles(scale : 2) {
Expand Down Expand Up @@ -326,16 +326,16 @@ def updateWeather() {
// If there is a zipcode defined, weather forecast will be sent. Otherwise, no weather forecast.
if (settings.zipcode) {
log.debug "ZipCode: ${settings.zipcode}"
weather = getWeatherFeature("conditions", settings.zipcode)
weather = getTwcConditions(settings.zipcode)

// Check if the variable is populated, otherwise return.
if (!weather) {
log.debug("Something went wrong, no data found.")
return false
}

def locationScale = getTemperatureScale()
def tempToSend = (locationScale == "C") ? weather.current_observation.temp_c : weather.current_observation.temp_f
def tempToSend = weather.temperature
log.debug("Outdoor Temperature: ${tempToSend} ${locationScale}")
// Right now this can disrupt device health if the device is
// currently offline -- it would be erroneously marked online.
Expand Down Expand Up @@ -534,5 +534,3 @@ def auto() {
def fanAuto() {
log.debug "${device.displayName} does not support fan auto"
}


240 changes: 114 additions & 126 deletions smartapps/egid/smart-windows.src/smart-windows.groovy
Original file line number Diff line number Diff line change
@@ -1,165 +1,153 @@
/**
* Smart Windows
* Compares two temperatures – indoor vs outdoor, for example – then sends an alert if windows are open (or closed!).
* Compares two temperatures – indoor vs outdoor, for example – then sends an alert if windows are open (or closed!).
*
* Copyright 2014 Eric Gideon
*
* Based in part on the "When it's going to rain" SmartApp by the SmartThings team,
* Based in part on the "When it's going to rain" SmartApp by the SmartThings team,
* primarily the message throttling code.
*
* 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
* 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.
*
*/
definition(
name: "Smart Windows",
namespace: "egid",
author: "Eric Gideon",
description: "Compares two temperatures – indoor vs outdoor, for example – then sends an alert if windows are open (or closed!). If you don't use an external temperature device, your location will be used instead.",
iconUrl: "https://s3.amazonaws.com/smartthings-device-icons/Home/home9-icn.png",
iconX2Url: "https://s3.amazonaws.com/smartthings-device-icons/Home/home9-icn@2x.png",
pausable: true
name: "Smart Windows",
namespace: "egid",
author: "Eric Gideon",
description: "Compares two temperatures – indoor vs outdoor, for example – then sends an alert if windows are open (or closed!). If you don't use an external temperature device, your location will be used instead.",
iconUrl: "https://s3.amazonaws.com/smartthings-device-icons/Home/home9-icn.png",
iconX2Url: "https://s3.amazonaws.com/smartthings-device-icons/Home/home9-icn@2x.png",
pausable: true
)


preferences {

if (!(location.zipCode || ( location.latitude && location.longitude )) && location.channelName == 'samsungtv') {
section { paragraph title: "Note:", "Location is required for this SmartApp. Go to 'Location Name' settings to setup your correct location." }
}

section( "Set the temperature range for your comfort zone..." ) {
input "minTemp", "number", title: "Minimum temperature"
input "maxTemp", "number", title: "Maximum temperature"
}
section( "Select windows to check..." ) {
input "sensors", "capability.contactSensor", multiple: true
}
section( "Select temperature devices to monitor..." ) {
input "inTemp", "capability.temperatureMeasurement", title: "Indoor"
input "outTemp", "capability.temperatureMeasurement", title: "Outdoor (optional)", required: false
}

if (location.channelName != 'samsungtv') {
section( "Set your location" ) { input "zipCode", "text", title: "Zip code" }
}

section( "Notifications" ) {
input "sendPushMessage", "enum", title: "Send a push notification?", metadata:[values:["Yes","No"]], required:false
input "retryPeriod", "number", title: "Minutes between notifications:"
}
section { paragraph title: "Note:", "Location is required for this SmartApp. Go to 'Location Name' settings to setup your correct location." }
}

section( "Set the temperature range for your comfort zone..." ) {
input "minTemp", "number", title: "Minimum temperature"
input "maxTemp", "number", title: "Maximum temperature"
}
section( "Select windows to check..." ) {
input "sensors", "capability.contactSensor", multiple: true
}
section( "Select temperature devices to monitor..." ) {
input "inTemp", "capability.temperatureMeasurement", title: "Indoor"
input "outTemp", "capability.temperatureMeasurement", title: "Outdoor (optional)", required: false
}

if (location.channelName != 'samsungtv') {
section( "Set your location" ) { input "zipCode", "text", title: "Zip code" }
}

section( "Notifications" ) {
input "sendPushMessage", "enum", title: "Send a push notification?", metadata:[values:["Yes","No"]], required:false
input "retryPeriod", "number", title: "Minutes between notifications:"
}
}


def installed() {
log.debug "Installed: $settings"
subscribe( inTemp, "temperature", temperatureHandler )
log.debug "Installed: $settings"
subscribe( inTemp, "temperature", temperatureHandler )
}

def updated() {
log.debug "Updated: $settings"
unsubscribe()
subscribe( inTemp, "temperature", temperatureHandler )
log.debug "Updated: $settings"
unsubscribe()
subscribe( inTemp, "temperature", temperatureHandler )
}


def temperatureHandler(evt) {
def currentOutTemp = null
if ( outTemp ) {
currentOutTemp = outTemp.latestValue("temperature")
} else {
log.debug "No external temperature device set. Checking WUnderground...."
currentOutTemp = weatherCheck()
}

def currentInTemp = evt.doubleValue
def openWindows = sensors.findAll { it?.latestValue("contact") == 'open' }

log.trace "Temp event: $evt"
log.info "In: $currentInTemp; Out: $currentOutTemp"

// Don't spam notifications
// *TODO* use state.foo from Severe Weather Alert to do this better
if (!retryPeriod) {
def retryPeriod = 30
}
def timeAgo = new Date(now() - (1000 * 60 * retryPeriod).toLong())
def recentEvents = inTemp.eventsSince(timeAgo)
log.trace "Found ${recentEvents?.size() ?: 0} events in the last $retryPeriod minutes"

// Figure out if we should notify
if ( currentInTemp > minTemp && currentInTemp < maxTemp ) {
log.info "In comfort zone: $currentInTemp is between $minTemp and $maxTemp."
log.debug "No notifications sent."
} else if ( currentInTemp > maxTemp ) {
// Too warm. Can we do anything?

def alreadyNotified = recentEvents.count { it.doubleValue > currentOutTemp } > 1

if ( !alreadyNotified ) {
if ( currentOutTemp < maxTemp && !openWindows ) {
send( "Open some windows to cool down the house! Currently ${currentInTemp}°F inside and ${currentOutTemp}°F outside." )
} else if ( currentOutTemp > maxTemp && openWindows ) {
send( "It's gotten warmer outside! You should close these windows: ${openWindows.join(', ')}. Currently ${currentInTemp}°F inside and ${currentOutTemp}°F outside." )
} else {
log.debug "No notifications sent. Everything is in the right place."
}
} else {
log.debug "Already notified! No notifications sent."
}
} else if ( currentInTemp < minTemp ) {
// Too cold! Is it warmer outside?

def alreadyNotified = recentEvents.count { it.doubleValue < currentOutTemp } > 1

if ( !alreadyNotified ) {
if ( currentOutTemp > minTemp && !openWindows ) {
send( "Open some windows to warm up the house! Currently ${currentInTemp}°F inside and ${currentOutTemp}°F outside." )
} else if ( currentOutTemp < minTemp && openWindows ) {
send( "It's gotten colder outside! You should close these windows: ${openWindows.join(', ')}. Currently ${currentInTemp}°F inside and ${currentOutTemp}°F outside." )
} else {
log.debug "No notifications sent. Everything is in the right place."
}
} else {
log.debug "Already notified! No notifications sent."
}
}
def currentOutTemp = null
if ( outTemp ) {
currentOutTemp = outTemp.latestValue("temperature")
} else {
log.debug "No external temperature device set. Checking The Weather Company..."
currentOutTemp = weatherCheck()
}

def currentInTemp = evt.doubleValue
def openWindows = sensors.findAll { it?.latestValue("contact") == 'open' }

log.trace "Temp event: $evt"
log.info "In: $currentInTemp; Out: $currentOutTemp"

// Don't spam notifications
// *TODO* use state.foo from Severe Weather Alert to do this better
if (!retryPeriod) {
def retryPeriod = 30
}
def timeAgo = new Date(now() - (1000 * 60 * retryPeriod).toLong())
def recentEvents = inTemp.eventsSince(timeAgo)
log.trace "Found ${recentEvents?.size() ?: 0} events in the last $retryPeriod minutes"

// Figure out if we should notify
if ( currentInTemp > minTemp && currentInTemp < maxTemp ) {
log.info "In comfort zone: $currentInTemp is between $minTemp and $maxTemp."
log.debug "No notifications sent."
} else if ( currentInTemp > maxTemp ) {
// Too warm. Can we do anything?

def alreadyNotified = recentEvents.count { it.doubleValue > currentOutTemp } > 1

if ( !alreadyNotified ) {
if ( currentOutTemp < maxTemp && !openWindows ) {
send( "Open some windows to cool down the house! Currently ${currentInTemp}°F inside and ${currentOutTemp}°F outside." )
} else if ( currentOutTemp > maxTemp && openWindows ) {
send( "It's gotten warmer outside! You should close these windows: ${openWindows.join(', ')}. Currently ${currentInTemp}°F inside and ${currentOutTemp}°F outside." )
} else {
log.debug "No notifications sent. Everything is in the right place."
}
} else {
log.debug "Already notified! No notifications sent."
}
} else if ( currentInTemp < minTemp ) {
// Too cold! Is it warmer outside?
def alreadyNotified = recentEvents.count { it.doubleValue < currentOutTemp } > 1
if ( !alreadyNotified ) {
if ( currentOutTemp > minTemp && !openWindows ) {
send( "Open some windows to warm up the house! Currently ${currentInTemp}°F inside and ${currentOutTemp}°F outside." )
} else if ( currentOutTemp < minTemp && openWindows ) {
send( "It's gotten colder outside! You should close these windows: ${openWindows.join(', ')}. Currently ${currentInTemp}°F inside and ${currentOutTemp}°F outside." )
} else {
log.debug "No notifications sent. Everything is in the right place."
}
} else {
log.debug "Already notified! No notifications sent."
}
}
}

def weatherCheck() {
def json
if (location.channelName != 'samsungtv')
json = getWeatherFeature("conditions", zipCode)
else
json = getWeatherFeature("conditions")
def currentTemp = json?.current_observation?.temp_f

if ( currentTemp ) {
log.trace "Temp: $currentTemp (WeatherUnderground)"
return currentTemp
} else {
log.warn "Did not get a temp: $json"
return false
}
def obs = getTwcConditions(zipCode)
def currentTemp = obs.temperature
if ( currentTemp ) {
log.trace "Temp: $currentTemp (The Weather Company)"
return currentTemp
} else {
log.warn "Did not get a temp: $obs"
return false
}
}

private send(msg) {
if ( sendPushMessage != "No" ) {
log.debug( "sending push message" )
sendPush( msg )
if ( sendPushMessage != "No" ) {
log.debug( "sending push message" )
sendPush( msg )
sendEvent(linkText:app.label, descriptionText:msg, eventType:"SOLUTION_EVENT", displayed: true, name:"summary")
}

if ( phone1 ) {
log.debug( "sending text message" )
sendSms( phone1, msg )
}

log.info msg
}
if ( phone1 ) {
log.debug( "sending text message" )
sendSms( phone1, msg )
}
log.info msg
}
Loading

0 comments on commit 7234a92

Please sign in to comment.