Nest Protect Device Type


(Kmugh) #1

I bought a couple of Nest Protects (the smoke detectors, not the thermostat), but I am not able to integrate them into ST. I separately tried two different device types: NickHBailey’s and imbrainj’s.
The first requires the 802.15.4 MAC, while the second needs the serial number (even though both ask for a “MAC address” under preferences). Unfortunately, neither type seems to work for me. (Both Protects work well with the Nest app though.)

@nickhbailey @imbrian or anyone else, have you gotten the Nest Protect to work in ST?
If so, could you please share the device type, and what needs to be put in the “Device MAC address” field?


Has anyone been able to get Nest Protect working?
(Eric) #2

@kmugh I got this to work. What I noticed is that once the device type was created it failed to have any capabilities. Further once I pasted the code and saved it said that all changes had to be made in the metadate definition section. What I did was edited the code of @nickbailey and added the capabilities that I wanted. Please note that I also started from scratch once I realized this was what I needed to do. I have this working for 2 NPs. Here is the code:
/**

  • Nest Protect
  • Author: nick@nickhbailey.com
  • Date: 01.03.14
  • INSTALLATION
  • =========================================
    1. Create a new device type (https://graph.api.smartthings.com/ide/devices)
  • Name: Nest Protect
    
  • Author: nick@nickhbailey.com
    
  • Capabilities:
    
  •     Battery
    
  •     Carbon Monoxide Detector 
    
  •     Polling
    
  •     Smoke Detector
    
    1. Create a new device (https://graph.api.smartthings.com/device/list)
  • Name: Your Choice
    
  • Device Network Id: Your Choice
    
  • Type: Nest Protect (should be the last option)
    
  • Location: Choose the correct location
    
  • Hub/Group: Leave blank
    
    1. Update device preferences
  • Click on the new device to see the details.
    
  • Click the edit button next to Preferences
    
  • Fill in your Nest login information.
    
  • To find your MAC Address, login to http://home.nest.com. Click the Protect 
    
  • icon. Open the right-hand side bar, open Nest Protect Settings, choose the Nest Protect
    
  • you are adding, open Technical Info, copy the value next to 802.15.4 MAC.
    
  • Copyright © 2014 Nick Bailey nick@nickhbailey.com
  • Permission is hereby granted, free of charge, to any person obtaining a copy of this
  • software and associated documentation files (the “Software”), to deal in the Software
  • without restriction, including without limitation the rights to use, copy, modify,
  • merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  • permit persons to whom the Software is furnished to do so, subject to the following
  • conditions: The above copyright notice and this permission notice shall be included
  • in all copies or substantial portions of the Software.
  • THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  • INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  • PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  • HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  • CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  • OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  • Overall inspiration and Authentication methods originally developed by Brian Steere
  • as part of the Nest thermostat device type: https://gist.github.com/Dianoga/6055918
  • and are subject to the following:
  • Copyright © 2013 Brian Steere dianoga7@3dgo.net
  • Permission is hereby granted, free of charge, to any person obtaining a copy of this
  • software and associated documentation files (the “Software”), to deal in the Software
  • without restriction, including without limitation the rights to use, copy, modify,
  • merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  • permit persons to whom the Software is furnished to do so, subject to the following
  • conditions: The above copyright notice and this permission notice shall be included
  • in all copies or substantial portions of the Software.
  • THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  • INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  • PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  • HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  • CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  • OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    */

preferences {
input(“username”, “text”, title: “Username”, description: “Your Nest username (usually an email address)”)
input(“password”, “password”, title: “Password”, description: “Your Nest password”)
input(“mac”, “text”, title: “MAC Address”, description: “The MAC Address of your Nest Protect”)
}

// for the UI
metadata {
// Automatically generated. Make future change here.
definition (name: “Nest Protect Aug”, namespace: “NP”, author: "nick@nickhbailey.com") {
capability "Polling"
capability "Battery"
capability "Carbon Monoxide Detector"
capability “Smoke Detector”
}

simulator {
    // TODO: define status and reply messages here
}

tiles {

    valueTile("smoke", "device.smoke", width: 2, height: 2){
    	//state ("clear", label: "OK", unit: "Smoke", backgroundColor:"#44B621")
		//state ("detected", icon:"st.alarm.smoke.smoke", label:"SMOKE", backgroundColor:"#e86d13", unit: "Smoke")
		//state ("tested", label:"TEST", backgroundColor:"#003CEC", unit: "Smoke")
        state "smoke", label: 'Smoke ${currentValue}', unit:"smoke",
        	backgroundColors: [
                [value: "clear", color: "#44B621"],
                [value: "detected", color: "#e86d13"],
                [value: "tested", color: "#003CEC"]
            ]
	}
	valueTile("carbonMonoxide", "device.carbonMonoxide"){
    	//state("clear", backgroundColor:"#44B621", unit: "CO")
		//state("detected", label:"CO", icon:"st.alarm.smoke.smoke", backgroundColor:"#e86d13", unit: "CO")
		//state("tested", label:"TEST", icon:"st.alarm.smoke.test", backgroundColor:"#003CEC", unit: "CO")
        state("carbonMonoxide", label: 'CO ${currentValue}', unit:"CO", backgroundColors: [
                [value: "clear", color: "#44B621"],
                [value: "detected", color: "#e86d13"],
                [value: "tested", color: "#003CEC"]
            ]
        )
	}
    valueTile("battery", "device.battery"){
    	//state("OK", backgroundColor:"#44B621", unit: "Batt")
		//state("Low", label:"Low", backgroundColor:"#e86d13")
        state("battery", label: 'Battery ${currentValue}', unit:"battery", backgroundColors: [
                [value: "OK", color: "#44B621"],
                [value: "Low", color: "#e86d13"]
            ]
        )
	}
    standardTile("refresh", "device.smoke", inactiveLabel: false, decoration: "flat") {
        state "default", action:"polling.poll", icon:"st.secondary.refresh"
    }
	main "smoke"
    details(["smoke", "carbonMonoxide", "battery", "refresh"])
}

}

// parse events into attributes
def parse(String description) {

}

def auto() {
log.debug “Executing ‘auto’”
}

def poll() {
log.debug "Executing ‘poll’"
api(‘status’, []) {
data.topaz = it.data.topaz.getAt(settings.mac.toUpperCase())

    data.topaz.smoke_status = data.topaz.smoke_status == 0? "clear" : "detected"
    data.topaz.co_status = data.topaz.co_status == 0? "clear" : "detected"
    data.topaz.battery_health_state = data.topaz.battery_health_state  == 0 ? "OK" : "Low"
         
    sendEvent(name: 'smoke', value: data.topaz.smoke_status)
    sendEvent(name: 'carbonMonoxide', value: data.topaz.co_status)
    sendEvent(name: 'battery', value: data.topaz.battery_health_state )
    log.debug settings.mac
    log.debug data.topaz.wifi_mac_address
    log.debug data.topaz.smoke_status
    log.debug data.topaz.co_status
    log.debug data.topaz.battery_health_state
}

}

def api(method, args = [], success = {}) {
if(!isLoggedIn()) {
log.debug "Need to login"
login(method, args, success)
return
}

def methods = [
    'status': [uri: "/v2/mobile/${data.auth.user}", type: 'get']
]

def request = methods.getAt(method)

log.debug "Logged in"
doRequest(request.uri, args, request.type, success)

}

// Need to be logged in before this is called. So don’t call this. Call api.
def doRequest(uri, args, type, success) {
log.debug “Calling $type : $uri : $args”

if(uri.charAt(0) == '/') {
    uri = "${data.auth.urls.transport_url}${uri}"
}

def params = [
    uri: uri,
    headers: [
        'X-nl-protocol-version': 1,
        'X-nl-user-id': data.auth.userid,
        'Authorization': "Basic ${data.auth.access_token}"
    ],
    body: args
]

if(type == 'post') {
    httpPostJson(params, success)
} else if (type == 'get') {
    httpGet(params, success)
}

}

def login(method = null, args = [], success = {}) {
def params = [
uri: ‘https://home.nest.com/user/login’,
body: [username: settings.username, password: settings.password]
]

httpPost(params) {response -> 
    data.auth = response.data
    data.auth.expires_in = Date.parse('EEE, dd-MMM-yyyy HH:mm:ss z', response.data.expires_in).getTime()
    log.debug data.auth
    
    api(method, args, success)
}

}

def isLoggedIn() {
if(!data.auth) {
log.debug "No data.auth"
return false
}

def now = new Date().getTime();
return data.auth.expires_in > now

}


"Pollster" - A SmartThings Polling Daemon
(Kmugh) #3

@ecamodeo Seems to be working now! Many thanks.


(Samuel Wong) #4

Found two things with the device

  1. None of the icons show up on the ST app (all are just green circles with – in the middle)
  2. After adding the device and it shows up with the correct status, is that suppose to be updated in the activity?

(Paul) #5

Just curious… Is it possible to use the wired Nest Protects as motion detectors too?


(Beckwith) #6

Nest has indicated they don’t intend on exposing the motion detection through their API.


(Dustin H) #7

I too am having the same issue of

You state:

So I’m wondering what I need to do in order to get it working…?


(Dustin H) #8

Is there a way we can get all this code put into one Code section? It’s broken up into some code tags here within the post and some of it isn’t. Is the stuff that is in code blocks the stuff that is different from the original post?

Thanks!


(Paul) #9

Thanks for the information, @beckwith


(Heather A) #10

I just can not get this device type to work. I’ve got the devices created, the device type created using this code and I just get an Unknown thing in my thing list for each of my protects (I created 3 devices)

I was thinking it was the MAC address field causing the issue. I’ve tried both MAC addresses I grab from the Nest Website as well as the serial number for the protect. No luck

Anyone have any suggestions?


(Heather A) #11

Update… this morning my app has changed from Unknown for the Protects to the circles with – no info on the Protects though. So still not sure where to go from here.

Update2… I re-copied the code above and re-pasted it into my device type and it seemed to fix things and now my protects are showing in the app. :smile:


(Samuel Wong) #12

When you say its showing in app, do you mean its showing as Damage & Danger dashboard? Were you able to resolve the image issue with the dashes?


(Korban Hadley) #13

I have the same issue. All I see is a green circle with --. I have tried copying the code a few times. I double checked the Mac address as well. I waited 24 hours to see if it would refresh or change. Under activity I am still not getting any updates.


#14

I’m stuck at the – display issue too. I think there might be something wrong with the tile definition, I already noticed a missing parenthesis and corrected that but still no luck. I’m planning on devoting a 1/2 hour or so to walking through the code, I’ll post an update if I find a fix.

Just as a side note, has anyone tested a protect with this device type to see if they actually send an alert to smartthings when set off?

Update: So more than 1/2 hour later, 3 actually… I have no idea what the problem is. I can see that the data is being updated as the timestamp from Nest changes in data.topaz. ST just seems to think the device is in some sort of “INACTIVE” state, perhaps that’s why we see – where the current data should be.


(trac starr) #15

@friedpope I’ve been doing the same. I’ve managed to get it working in the simulator, changing colors and display text, but as a real device…nodda. It’s very frustrating.


(John Mielko) #16

great job… thank you


(Chris Burton) #17

I have the – happening as well. Just so that I am clear, which MAC are we supposed to put in?


(Cuda) #18

On my Android (S4), I’m exhibiting the same behavior as the rest of the community. However If I install the app on my iPad, voila - works just fine. Hmm …


#19

I made the mistake of assuming the Nest Protect was properly integrated into ST. It’s of concern to me we’re using self written code to alert on something that’s life or death.


#20

Pardon my ignorance, but I’m still fairly new to this! I’ve followed the directions from ecamodeo, but I keep getting the “Unknown” tile (gray with a question mark" on my ST app (using iOS ST version). However, I have the “Damage & Danger” option in the ST app now (it has a gray exclamation symbol) with a green dot to the side saying “Everything is OK.” Where exactly do I need to past my username and password (how many times - just in the first instance of username/password in bold, or each time username or password appears?)? I’ve included my portion of what I thought I should’ve pasted into the code. Please advise if this is WAY off or which direction to go. Also, where does the MAC address go?

preferences {
input(“myusername@gmail.com”, “text”, title: “Username”, description: “Your Nest username (usually an email address)”)
input(“mypassword”, “password”, title: “Password”, description: “Your Nest password”)
input(“1fakemac00000111”, “text”, title: “MAC Address”, description: “The MAC Address of your Nest Protect”)
}

Thank you in advance!