Monoprice door/window sensor and Smoke Alarm Device Type


(Colin) #1

Just getting started with my V2 hub, and new devices. First project is connecting my wired smoke alarms to ST. I have the BRK-RM4 relay, and I picked up a Monoprice door/window sensor to work with it. - I found the custom device type for the Monoprice Door/Window sensor here: https://github.com/tslagle13/smartthings-4/blob/master/devicetypes/mikemaxwell/monoprice-door-window-sensor.groovy

It seems to work fine, but of course, it’s displayed as a door/window sensor. I would really like to get it to display smoke alarm type messages and be available in Damage/Danger section.

The Connected Smoke Alarm device type that does these things was written for the Schlage door/window sensor and doesn’t work properly. it’s code is here, from @Dan999 https://github.com/dan06/Connected-Smoke-Alarm/blob/master/SmokeAlarmDevice.groovy

Can anybody help me figure out how to modify the Monoprice sensor to operate like the Connected Smoke Alarm?


First Alert Smoke Detector - Iris
When are "Hard Wired" Smoke detectors going to be supported by Smart Things
(Pre-Subcategory creation) Deals/Sales/Coupons/Pricing
(Dan) #2

You can try to change this function:

def sensorValueEvent(value) { if (value) { createEvent(name: "contact", value: "open", descriptionText: "$device.displayName is open") } else { createEvent(name: "contact", value: "closed", descriptionText: "$device.displayName is closed") } }

with this:

def sensorValueEvent(value) { if (value) { createEvent(name: "smoke", value: "detected", descriptionText: "$device.displayName is detected") } else { createEvent(name: "smoke", value: "clear", descriptionText: "$device.displayName is clear") } }

If it works in reverse, then swap the clear and detected lines.

Also change the line near the top:
capability "Contact Sensor"
to
capability “Smoke Detector”


(Colin) #3

No dice. I can still see the live log passing the open/close payloads, but the status never updates at all.


(Colin) #4

Best I have been able to do so far is just manipulate the labels, icons and colors on the tile… still can’t get it to work as a Smoke Detector device.


(Dan) #5

Just to clear up a misunderstanding - this device was adapted for the Peq / Centralite Zigbee open/close sensor, so it will not work for a Z-Wave device.

It works perfectly in my application, even now with Smart Home Monitor in the ST 2.0. The only issue I had after the ST 1.7 update, is that the particulate icon didn’t show up in the activity feed, but functionally it works fine.


(Colin) #6

Hah. Noooo, I’m not a n00b at this thing at all! But hey, at least that is a darn good explanation of the problem! Guess I will have to go see if I can find Z-wave smoke alarm code to play with…

Though, in the Connected Smoke Alarm thread, @Dan999 you did reference your code being Z-wave :wink:


(Eric) #7

WHOOAAA BACK UP - is there ANY Zwave or Zigbee sensor that shows particulate count in ST?


(Colin) #8

He’s using the particulate icon to indicate smoke for his smoke detector device type…


(Colin) #9

For now, since I already have the z-wave sensor, I’ve modified the device type to show Clear/Smoke status labels and Home/Particulate icon. Monoprice Door/Window Sensor as Smoke Detector interface

/**
  • Z-Wave Door/Window Sensor
  • Author: SmartThings
  • Date: 2013-11-3
    */

// for the UI
metadata {
// Automatically generated. Make future change here.
definition (name: “Monoprice Door/Window Sensor as Smoke Detector”, namespace: “ctrost”, author: “ctrost”) {
capability "Contact Sensor"
capability "Smoke Detector"
capability "Sensor"
capability “Battery”
//0 0 0x2001 0 0 0 7 0x71 0x85 0x80 0x72 0x30 0x86 0x84
fingerprint deviceId: “0x2001”, inClusters: “0x71, 0x85, 0x80, 0x72, 0x30, 0x86, 0x84”
}

// simulator metadata
simulator {
// status messages
status “open”: "command: 2001, payload: FF"
status “closed”: “command: 2001, payload: 00”
}

// UI tile definitions
tiles {
standardTile(“contact”, “device.contact”, width: 2, height: 2) {
state “open”, label: ‘Clear’, icon: “st.Home.home2”, backgroundColor: “#1fff1f"
state “closed”, label: ‘Smoke’, icon: “st.particulate.particulate.particulate”, backgroundColor: “#ff1f1f
}
valueTile(“battery”, “device.battery”, inactiveLabel: false, decoration: “flat”) {
state “battery”, label:’${currentValue}% battery’, unit:”"
}

  main "contact"
  details(["contact", "battery"])

}
}

def parse(String description) {
log.debug "parse:${description}"
def result = null
if (description.startsWith(“Err”)) {
result = createEvent(descriptionText:description)
} else if (description == “updated”) {
if (!state.MSR) {
result = [
response(zwave.wakeUpV1.wakeUpIntervalSet(seconds:4*3600, nodeid:zwaveHubNodeId)),
response(zwave.manufacturerSpecificV2.manufacturerSpecificGet()),
]
}
} else {
def cmd = zwave.parse(description, [0x20: 1, 0x25: 1, 0x30: 1, 0x31: 5, 0x80: 1, 0x84: 1, 0x71: 3, 0x9C: 1])
if (cmd) {
result = zwaveEvent(cmd)
}
}
return result
}

def sensorValueEvent(value) {
if (value) {
createEvent(name: “contact”, value: “open”, descriptionText: “$device.displayName is open”)
} else {
createEvent(name: “contact”, value: “closed”, descriptionText: “$device.displayName is closed”)
}
}

def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd)
{
sensorValueEvent(cmd.value)
}

def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd)
{
sensorValueEvent(cmd.value)
}

def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd)
{
sensorValueEvent(cmd.value)
}

def zwaveEvent(physicalgraph.zwave.commands.sensorbinaryv1.SensorBinaryReport cmd)
{
sensorValueEvent(cmd.sensorValue)
}

def zwaveEvent(physicalgraph.zwave.commands.sensoralarmv1.SensorAlarmReport cmd)
{
sensorValueEvent(cmd.sensorState)
}

def zwaveEvent(physicalgraph.zwave.commands.notificationv3.NotificationReport cmd)
{
def result = []
if (cmd.notificationType == 0x06 && cmd.event == 0x16) {
result << sensorValueEvent(1)
} else if (cmd.notificationType == 0x06 && cmd.event == 0x17) {
result << sensorValueEvent(0)
} else if (cmd.notificationType == 0x07) {
if (cmd.v1AlarmType == 0x07) { // special case for nonstandard messages from Monoprice door/window sensors
result << sensorValueEvent(cmd.v1AlarmLevel)
} else if (cmd.event == 0x01 || cmd.event == 0x02) {
result << sensorValueEvent(1)
} else if (cmd.event == 0x03) {
result << createEvent(descriptionText: “$device.displayName covering was removed”, isStateChange: true)
result << response(zwave.wakeUpV1.wakeUpIntervalSet(seconds:4*3600, nodeid:zwaveHubNodeId))
if(!state.MSR) result << response(zwave.manufacturerSpecificV2.manufacturerSpecificGet())
} else if (cmd.event == 0x05 || cmd.event == 0x06) {
result << createEvent(descriptionText: “$device.displayName detected glass breakage”, isStateChange: true)
} else if (cmd.event == 0x07) {
if(!state.MSR) result << response(zwave.manufacturerSpecificV2.manufacturerSpecificGet())
result << createEvent(name: “motion”, value: “active”, descriptionText:"$device.displayName detected motion")
}
} else if (cmd.notificationType) {
def text = “Notification $cmd.notificationType: event ${([cmd.event] + cmd.eventParameter).join(”, ")}"
result << createEvent(name: “notification$cmd.notificationType”, value: “$cmd.event”, descriptionText: text, displayed: false)
} else {
def value = cmd.v1AlarmLevel == 255 ? “active” : cmd.v1AlarmLevel ?: "inactive"
result << createEvent(name: “alarm $cmd.v1AlarmType”, value: value, displayed: false)
}
result
}

def zwaveEvent(physicalgraph.zwave.commands.wakeupv1.WakeUpNotification cmd)
{
def result = [createEvent(descriptionText: “${device.displayName} woke up”, isStateChange: false)]
if (!state.lastbat || (new Date().time) - state.lastbat > 5360601000) {
result << response(zwave.batteryV1.batteryGet())
result << response(“delay 1200”)
}
if (!state.MSR) {
result << response(zwave.wakeUpV1.wakeUpIntervalSet(seconds:4
3600, nodeid:zwaveHubNodeId))
result << response(zwave.manufacturerSpecificV2.manufacturerSpecificGet())
result << response(“delay 1200”)
}
result << response(zwave.wakeUpV1.wakeUpNoMoreInformation())
result
}

def zwaveEvent(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd) {
def map = [ name: “battery”, unit: “%” ]
if (cmd.batteryLevel == 0xFF) {
map.value = 1
map.descriptionText = "${device.displayName} has a low battery"
map.isStateChange = true
} else {
map.value = cmd.batteryLevel
}
state.lastbat = new Date().time
[createEvent(map), response(zwave.wakeUpV1.wakeUpNoMoreInformation())]
}

def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) {
def result = []

def msr = String.format("%04X-%04X-%04X", cmd.manufacturerId, cmd.productTypeId, cmd.productId)
log.debug "msr: $msr"
updateDataValue(“MSR”, msr)

retypeBasedOnMSR()

result << createEvent(descriptionText: “$device.displayName MSR: $msr”, isStateChange: false)

if (msr == “011A-0601-0901”) { // Enerwave motion doesn’t always get the associationSet that the hub sends on join
result << response(zwave.associationV1.associationSet(groupingIdentifier:1, nodeId:zwaveHubNodeId))
} else if (!device.currentState(“battery”)) {
result << response(zwave.batteryV1.batteryGet())
}

result
}

def zwaveEvent(physicalgraph.zwave.Command cmd) {
createEvent(descriptionText: “$device.displayName: $cmd”, displayed: false)
}

def retypeBasedOnMSR() {
switch (state.MSR) {
case “0086-0002-002D”:
log.debug(“Changing device type to Z-Wave Water Sensor”)
setDeviceType(“Z-Wave Water Sensor”)
break
case “011F-0001-0001”: // Schlage motion
case “014A-0001-0001”: // Ecolink motion
case “0060-0001-0002”: // Everspring SP814
case “0060-0001-0003”: // Everspring HSP02
case “011A-0601-0901”: // Enerwave ZWN-BPC
log.debug(“Changing device type to Z-Wave Motion Sensor”)
setDeviceType(“Z-Wave Motion Sensor”)
break

}
}


(Colin) #10

@Dan999 I can’t find a good price on the PEQ Zigbee Sensors anymore… do you think it would take much tweaking of your device type to work with the Securifi sensor? http://www.amazon.com/Securifi-Door-Window-Sensor-AL-DSW02/dp/B00TBWKPMQ


(Dan) #11

All I can say, is that it looks like it’s a Zigbee HA device, like the Centralite one. I don’t have any experience writing device type code. So unfortunately I’m not sure if the code will work as is. Maybe some of the low-level device guys can chime in.

On a more general note, the changes I made to the code was very simple, and you should be able to adapt the changes for any device, zigbee or z-wave. As I understand it, the device type translates device specific messages into device independent SmartThings events. All I did, was replace the open and close events with smoke events (which I copied from a Z-Wave smoke device in the code library), and then mark the capability of the device as smoke alarm and not contact sensor.

def sensorValueEvent(value) { if (value) { createEvent(name: "contact", value: "open", descriptionText: "$device.displayName is open") } else { createEvent(name: "contact", value: "closed", descriptionText: "$device.displayName is closed") }}

The code above seems to be where the device creates the open and close events. But Groovy hasn’t been super intuitive for me (as a C# / C++ guy), so I can’t tell if that code actually returns the events that are created, or if createEvent() actually sends the event. So if you want to experiment a little, you can try various things - like sendEvent() instead of createEvent, or adding a “return” in front of createEvent(). Unfortunately I don’t have a z-wave contact sensor to experiment with. And of course make sure to change the device type of the sensor in the IDE to the one you’ve modified.


(Colin) #12

I did modify the device type for my z-wave sensor, so it shows up with appropriate icons and name, I was still operating under the assumption that it still won’t behave in SmartThings as a smoke alarm device, but perhaps i’m mistaken. A bit harder to tell with the new app and not seeing the same layout (Damage & Danger, etc)


(Daniel) #13

@Toasty, this is an interesting project. I have the BRK-RM4 relay attached to my smoke detectors, and I am using a z-wave door/window sensor to trigger an alert. I am coming from a Vera system and this is my first try with Smartthings. I am hoping that if I use a Monoprice door/window sensor attached to the BRK-RM4 relay with your code, it would behave as a Smoke Detector and it can be seen by “Smart Home Monitor” as a smoke detector.


(Colin) #14

Some things have come up and I haven’t gotten it all hooked up yet, but my plan is same as yours. If it doesn’t show up and report as I expect, worse case scenario is to fork out $$ for a zigbee sensor and use the connected smoke alarm code instead.


(Daniel) #15

@Toasty, I tried the modified driver with a Monoprice Door/Window sensor last night. ST 2.0 recognized the detector as a Smoke detector, and I was able to add it to the “Smart Home Monitor” as a Smoke Detector. However, when the smoke detector tripped, Smart Home Monitor did not recognize it as tripped event, It did not react to the violation.


(Colin) #16

I was afraid of that. Unfortunately, I’m not sure how to fix it :frowning:


(Colin) #17

Thanks to @Dan999 for a working device type for the Z-Wave Monoprice Door/Window sensor as a Connected Smoke Alarm!


(Daniel) #18

I just tested @Dan999’s device code for a SmartSense Open/Closed sensor and I was going to remove the reed switch and use that as a Connected Smoke Alarm. Now that Monoprice Door/Window Sensor is working as a Connected Smoke Alarm, I might switch to that since it has the external input terminals.


(Daniel) #19

Do you have the link for the updated code from @Dan999?


(Dan) #20