Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for logging SHM alarm status #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions smartapps/influxdb-logger/influxdb-logger.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ preferences {
input "prefLogModeEvents", "bool", title:"Log Mode Events?", defaultValue: true, required: true
input "prefLogHubProperties", "bool", title:"Log Hub Properties?", defaultValue: true, required: true
input "prefLogLocationProperties", "bool", title:"Log Location Properties?", defaultValue: true, required: true
input "prefLogSHMEvents", "bool", title:"Log Smart Home Monitor events?", defaultValue: true, required: true
}

section("Devices To Monitor:") {
Expand Down Expand Up @@ -211,8 +212,8 @@ def updated() {
state.deviceAttributes << [ devices: 'sleepSensors', attributes: ['sleeping']]
state.deviceAttributes << [ devices: 'smokeDetectors', attributes: ['smoke']]
state.deviceAttributes << [ devices: 'soundSensors', attributes: ['sound']]
state.deviceAttributes << [ devices: 'spls', attributes: ['soundPressureLevel']]
state.deviceAttributes << [ devices: 'switches', attributes: ['switch']]
state.deviceAttributes << [ devices: 'spls', attributes: ['soundPressureLevel']]
state.deviceAttributes << [ devices: 'switches', attributes: ['switch']]
state.deviceAttributes << [ devices: 'switchLevels', attributes: ['level']]
state.deviceAttributes << [ devices: 'tamperAlerts', attributes: ['tamper']]
state.deviceAttributes << [ devices: 'temperatures', attributes: ['temperature']]
Expand Down Expand Up @@ -263,6 +264,26 @@ def handleModeEvent(evt) {
postToInfluxDB(data)
}

/**
* alarmStatusHandler(evt)
*
* Log SHM Alarm status changes.
**/
def alarmStatusHandler(evt) {
logger("alarmStatusHandler(): SHM Mode changed to: ${evt.value}","info")
def locationId = escapeStringForInfluxDB(location.id)
def locationName = escapeStringForInfluxDB(location.name)
def tz = '"' + escapeStringForInfluxDB(location.timeZone.ID) + '"'
def mode = '"' + escapeStringForInfluxDB(location.mode) + '"'
def hubCount = location.hubs.size()
def times = getSunriseAndSunset()
def srt = '"' + times.sunrise.format("HH:mm", location.timeZone) + '"'
def sst = '"' + times.sunset.format("HH:mm", location.timeZone) + '"'
def alarmstatus = '"' + escapeStringForInfluxDB(location.currentState("alarmSystemStatus")?.value) + '"'
def data = "_stLocation,locationId=${locationId},locationName=${locationName},latitude=${location.latitude},longitude=${location.longitude},timeZone=${tz} mode=${mode},hubCount=${hubCount}i,sunriseTime=${srt},sunsetTime=${sst},alarmstatus=${alarmstatus}"
postToInfluxDB(data)
}

/**
* handleEvent(evt)
*
Expand Down Expand Up @@ -554,8 +575,8 @@ def logSystemProperties() {
def times = getSunriseAndSunset()
def srt = '"' + times.sunrise.format("HH:mm", location.timeZone) + '"'
def sst = '"' + times.sunset.format("HH:mm", location.timeZone) + '"'

def data = "_stLocation,locationId=${locationId},locationName=${locationName},latitude=${location.latitude},longitude=${location.longitude},timeZone=${tz} mode=${mode},hubCount=${hubCount}i,sunriseTime=${srt},sunsetTime=${sst}"
def alarmstatus = '"' + escapeStringForInfluxDB(location.currentState("alarmSystemStatus")?.value) + '"'
def data = "_stLocation,locationId=${locationId},locationName=${locationName},latitude=${location.latitude},longitude=${location.longitude},timeZone=${tz} mode=${mode},hubCount=${hubCount}i,sunriseTime=${srt},sunsetTime=${sst},alarmstatus=${alarmstatus}"
postToInfluxDB(data)
} catch (e) {
logger("logSystemProperties(): Unable to log Location properties: ${e}","error")
Expand Down Expand Up @@ -692,7 +713,10 @@ private manageSubscriptions() {

// Subscribe to mode events:
if (prefLogModeEvents) subscribe(location, "mode", handleModeEvent)


// Subscribe to SHM alarm events
if (prefLogSHMEvents) subscribe(location, "alarmSystemStatus", alarmStatusHandler)

// Subscribe to device attributes (iterate over each attribute for each device collection in state.deviceAttributes):
def devs // dynamic variable holding device collection.
state.deviceAttributes.each { da ->
Expand Down