Skip to content

Instantly share code, notes, and snippets.

@joshualyon
Last active October 13, 2018 09:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joshualyon/fc9b3fe25cda6cbfc42eb281588141d4 to your computer and use it in GitHub Desktop.
Save joshualyon/fc9b3fe25cda6cbfc42eb281588141d4 to your computer and use it in GitHub Desktop.
SmartApp which subscribes to Smart Home Monitor status and maps the state to an attribute of a custom Device Handler so other apps can access the attribute
/**
* SHM Mapper
*
* Copyright 2017 Josh Lyon
*
* This SmartApp works in unison with the custom SHM Mapper device type handler to copy Smart Home Monitor statuses to an
* attribute of a Thing. Even though SHM code is available on the SmartThings community, it was never officially approved
* for use in officially published SmartApps.
*
* In order to get around this, the SHM Mapper SmartApp copies SHM status to the attribute of a Thing so that Thing can be
* subscribed to in other official SmartApps. For example, you could use this to display SHM status in SharpTools.
*
* Required Device Type Handler: https://gist.github.com/joshualyon/22f6e8f7bebd37779e50f5e42d8cc761
*/
definition(
name: "SHM Mapper",
namespace: "joshualyon",
author: "Josh Lyon",
description: "Maps Smart Home Monitor states to a device attribute for access in other applications",
category: "My Apps",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
preferences {
section("Select your custom SHM Mapper device"){
paragraph "Note that all Alarm devices are shown. Select the installed SHM Mapper device."
input "shmDevice", "capability.alarm", title: "Which SHM Mapper?"
}
section("Other Settings")
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
//subscribe to attributes, devices, locations, etc.
//Subscribe to SHM status
subscribe(location, "alarmSystemStatus", alarmStatusHandler)
}
def alarmStatusHandler(evt) {
log.debug "alarm status changed to: ${evt.value}"
shmDevice.setShmState(evt.value)
log.debug "SHM mapped device is now: ${shmDevice.currentValue("shmState")}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment