Skip to content

Instantly share code, notes, and snippets.

@marclennox
Created October 27, 2020 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marclennox/b0758df12e598c42c60516bebc0b2f95 to your computer and use it in GitHub Desktop.
Save marclennox/b0758df12e598c42c60516bebc0b2f95 to your computer and use it in GitHub Desktop.
import groovy.json.JsonSlurper;
preferences {
section() {
input("integrateSHM", "boolean", title: "Integrate with SHM", description: "Whether to integrate this partition with Smart Home Monitor", required: true)
}
}
metadata {
definition (name: "DSC Alarm Partition", namespace: "TenStartups", author: "Marc Lennox") {
capability "Refresh"
capability "Alarm" // PANIC
capability "smokeDetector" // FIRE
command "disarm"
command "armStay"
command "armAway"
command "panic"
attribute "partitionState", "enum", ["disarmed", "in_exit_delay", "armed_stay", "armed_away", "in_entry_delay", "alarming"]
}
simulator {
// TODO: define status and reply messages here
}
tiles(scale: 2) {
multiAttributeTile(name: "status", type: "generic", width: 6, height: 4) {
tileAttribute("device.partitionState", key: "PRIMARY_CONTROL") {
attributeState "disarmed", label: 'Disarmed', icon: "st.security.alarm.off", backgroundColor: "#79b821", defaultState: true
attributeState "in_exit_delay", label: 'In Exit Delay', icon: "st.security.alarm.on", backgroundColor: "#ffa81e"
attributeState "armed_stay", label: 'Armed (Stay)', icon: "st.security.alarm.on", backgroundColor: "#ffa81e"
attributeState "armed_away", label: 'Armed (Away)', icon: "st.security.alarm.on", backgroundColor: "#ffa81e"
attributeState "in_entry_delay", label: 'In Entry Delay', icon: "st.security.alarm.on", backgroundColor: "#ffa81e"
attributeState "alarming", label: 'Alarming!', icon: "st.home.home2", backgroundColor: "#ff4000"
attributeState "fire", label: 'Fire!', icon: "st.contact.contact.closed", backgroundColor: "#ff0000"
}
}
standardTile("disarm", "device.partitionState", inactiveLabel: false, width: 2, height: 2) {
state "default", label: "DISARM", action: "disarm", icon: "st.security.alarm.off", backgroundColor: "#ffffff", nextState: "disarming"
state "disarmed", label: "DISARMED", action: "", icon: "st.security.alarm.off", backgroundColor: "#79b821", nextState: "disarming"
state "disarming", label: "DISARMING", action: "disarm", icon: "st.security.alarm.off", backgroundColor: "#2179b8"
}
standardTile("armStay", "device.partitionState", inactiveLabel: false, width: 2, height: 2) {
state "default", label: "STAY", action: "armStay", icon: "st.security.alarm.on", backgroundColor: "#ffffff", nextState: "arming_stay"
state "armed_stay", label: "STAY", action: "", icon: "st.security.alarm.on", backgroundColor: "#ffa81e", nextState: "arming_stay"
state "arming_stay", label: "ARMING", action: "armStay", icon: "st.security.alarm.on", backgroundColor: "#ffa81e"
}
standardTile("armAway", "device.partitionState", inactiveLabel: false, width: 2, height: 2) {
state "default", label: "AWAY", action: "armAway", icon: "st.security.alarm.on", backgroundColor: "#ffffff", nextState: "arming_away"
state "armed_away", label: "AWAY", action: "", icon: "st.security.alarm.on", backgroundColor: "#ffa81e", nextState: "arming_away"
state "arming_away", label: "ARMING", action: "armAway", icon: "st.security.alarm.on", backgroundColor: "#ffa81e"
}
standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "default", action:"refresh.refresh", icon:"st.secondary.refresh"
}
main(["status"])
details(["status", "disarm", "armStay", "armAway", "refresh"])
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
}
def updated() {
log.debug "Updated with settings: ${settings}"
}
def integrateSHM() {
return settings.integrateSHM
}
def disarm() {
log.debug("Disarming alarm partition")
sendCommand("disarm", true)
}
def armStay() {
log.debug("Arming alarm partition in STAY mode")
sendCommand("arm_stay")
}
def armAway() {
log.debug("Arming alarm partition in AWAY mode")
sendCommand("arm_away")
}
def refresh()
{
log.debug "Refreshing alarm partition status..."
sendCommand("status")
}
def sendCommand(String commandPath, boolean sendCode = false) {
def path = "/api/partition/${getDataValue("externalId")}/${commandPath}"
if (sendCode) {
path = "${path}/${getDataValue("userCode")}"
}
new physicalgraph.device.HubAction(
[
method: "POST",
path: path,
headers: [ HOST: "${getDataValue("ipAddress")}:${getDataValue("ipPort")}" ]
],
null,
[ callback: sendCommandResponseHandler ]
)
}
def sendCommandResponseHandler(physicalgraph.device.HubResponse hubResponse) {
processStatusUpdate(hubResponse.json?.result)
}
def processStatusUpdate(data) {
if (data != null && data.status != null) {
log.debug "Partition status is ${data.status.toUpperCase()}"
sendEvent(name: "partitionState", value: data.status)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment