Hi! Thanks for reaching out!
I’ve been having a look just now and (in the 5 years since i started my SmartThings journey) it does look like a number of my apps can now probably be achieved with Routines. It looks like that has come a long way, as when i started you couldn’t even make simple decisions based on a temperature sensor going above or below a threshold. This appears to be there and i suspect i can re-work several of my apps to use this instead.
The big thing i’m going to struggle with is the data collection and http push to my server, which then graphs the data and (where required) makes changes to other items directly connected to the server within the house as a result.
I’m going to post it below with the more personal/irrelevant bits removed.
definition(
name: "Push AC Unit Info To Cacti",
namespace: "snip",
author: "snip",
description: "Pushes values from Air Conditioning devices to Cacti over HTTP.",
category: "snip",
iconUrl: "snip"
iconX2Url: "snip"
iconX3Url: "snip"
preferences {
section("Select an Air Conditioning Unit") {
input "acunit", "capability.airConditionerMode", title: "Unit", required: true
}
section("Cacti Target DS") {
input "roomName", "text", title: "Room Name", required: true
}
section("Cacti Password") {
input "password", "password", title: "Variable password", required: true
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
unschedule()
initialize()
}
def initialize() {
subscribe(acunit, "temperature", temperatureChangedHandler)
subscribe(acunit, "humidity", humidityChangedHandler)
subscribe(acunit, "switch", powerChangedHandler)
subscribe(acunit, "airConditionerMode", modeChangedHandler)
subscribe(acunit, "coolingSetpoint", setpointChangedHandler)
subscribe(acunit, "fanMode", fanModeChangedHandler)
subscribe(acunit, "acOptionalMode", optionalModeChangedHandler)
subscribe(acunit, "airFlowDirection", airflowChangedHandler)
schedule("0 /15 * * * ?", updateAllValues)
updateAllValues()
}
def debugHandler(evt) {
// get the event name, e.g., "switch"
log.debug "This event name is ${evt.name}"
// get the value of this event, e.g., "on" or "off"
log.debug "The value of this event is ${evt.value}"
// get the Date this event happened at
log.debug "This event happened at ${evt.date}"
// did the value of this event change from its previous state?
log.debug "The value of this event is different from its previous value: ${evt.isStateChange()}"
}
def updateAllValues() {
temperatureChangedHandler()
humidityChangedHandler()
setpointChangedHandler()
modeChangedHandler()
airflowChangedHandler()
fanModeChangedHandler()
optionalModeChangedHandler()
powerChangedHandler()
}
def updateDS(var, pwd, val) {
//log.debug "DS-POST: ${var} : ${pwd} : ${val}"
def params = [
uri: "https://a-web-server-url",
path: "/a-php-page.php",
query: [
"variable": var,
"ttl": "86400",
"password": pwd,
"value": val
]
]
try {
httpGet(params) { resp ->
log.debug "response data: ${resp.data}"
}
} catch (e) {
log.error "I did a bad: $e"
}
}
def temperatureChangedHandler(evt) {
updateDS("${roomName}T", password, acunit.currentTemperature)
}
def humidityChangedHandler(evt) {
updateDS("${roomName}H", password, acunit.currentHumidity)
}
def setpointChangedHandler(evt) {
updateDS("${roomName}SP", password, acunit.currentCoolingSetpoint)
}
def modeChangedHandler(evt) {
def result = ""
switch ("${acunit.currentAirConditionerMode}") {
case "auto": result = "0"; break;
case "cool": result = "1"; break;
case "dry": result = "2"; break;
case "coolClean": result = "3"; break;
case "dryClean": result = "4"; break;
case "fanOnly": result = "5"; break;
case "heat": result = "6"; break;
case "heatClean": result = "7"; break;
case "notSupported": result = "8"; break;
default: result = "9";
}
updateDS("${roomName}M", password, result)
}
def airflowChangedHandler(evt) {
def result = ""
switch ("${acunit.currentAirFlowDirection}") {
case "all": result = "0"; break;
case "fixed": result = "1"; break;
case "vertial": result = "2"; break;
case "horizontal": result = "3"; break;
default: result = "9";
}
updateDS("${roomName}AF", password, result)
}
def fanModeChangedHandler(evt) {
def result = ""
switch ("${acunit.currentFanMode}") {
case "auto": result = "0"; break;
case "low": result = "1"; break;
case "medium": result = "2"; break;
case "high": result = "3"; break;
case "turbo": result = "4"; break;
default: result = "9";
}
updateDS("${roomName}FM", password, result)
}
def optionalModeChangedHandler(evt) {
def result = ""
switch ("${acunit.currentAcOptionalMode}") {
case "off": result = "0"; break;
case "twoStep": result = "1"; break;
case "quiet": result = "2"; break;
case "speed": result = "3"; break;
case "windFree": result = "4"; break;
case "energySaving": result = "5"; break;
default: result = "9";
}
updateDS("${roomName}OPT", password, result)
}
def powerChangedHandler(evt) {
def result = ""
switch ("${acunit.switchState.value}") {
case "off": result = "0"; break;
case "on": result = "1"; break;
default: result = "9";
}
updateDS("${roomName}PWR", password, result)
}
This has worked for years now, and a chunk of it i’m sure i found from some Samsung page when i first made it - although please don’t judge my code too harshly!!
So looking through the list, i reckon most of what i need to do falls in to two groups with just one exception:
- Get info from a device and push it to a URL (i.e. the above).
- Look for a change in temperature and turn something on/off (now a routine).
The exception: Is a ZXT-120 IR transmitter which uses a custom device handler to control one very old A/C unit. I do not use this a lot, and i’m not adverse to changing the IR transmitter for another one. My priority is really getting the above code ‘migrated’ to something new so it does not suddenly stop working as it sounds like it soon will do.
Thanks for any help you can offer!!