Need a point in the right direction please - Sleep Number Integration

Hi all - thanks for reading through this and hopefully someone can help.

I’m not a coder or developer, but a tech savvy end user who is curious and not afraid to fail. I have a goal of integrating my sleep number bed to smartthings using the sleep iq app. The end goal is to be able to automate the inflation/deflation of each side of the bed and a bonus would be also to control the vertical motion. While I do not have a bed frame that is adjustable to test with, it is better to include it than to stop short.

In addition to inflation/deflation and vertical motion of the frame, sleep iq also has a presence sensor. There has already been an app developed to take advantage of this as a presence sensor, but doesn’t go far enough to control the inflation/deflation or bed frame vertical motion. The topic for this is https://community.smartthings.com/t/sleepiq-presence-sensors/37143 and the topic I posted to the developer of the app is https://community.smartthings.com/t/sleepnumber-sleepiq-integration/3211.

I would love to be able to start doing some research on my end about the calls made to the server from my phone, but I’m not sure where to start. It seems like I need to identify the packets that are being sent to the sleep iq servers to identify some information to then use in a smart app fashion. How do I do this and what programs will I need?

Once I get this info, I can start a trial and error (mostly error) attempt at writing some code to see if I can make it work with smartthings.

Any advice or help that anyone could provide would be a huge help.

Thank you!

Jason

1 Like

I only have time to write a brief reply, but Ill try to answer more in depth and look at this a bit over the winter break.

What ultimately needs to happen if this is to work is I need to know how to talk to the SleepIQ servers. The current implementation uses the same endpoints as their web app, which was easily discoverable by using the developer console in a desktop browser to watch the network requests to see the URL and data being sent. The important requests/responses to analyze are the login procedure and the specific actions you want (e.g. inflate, deflate, …). The same thing needs to happen with the mobile app.

Are you using iOS or Android? That doesn’t matter once you get the requests, but here is a brief article that I just found that looks like it might be useful: http://jasdev.me/intercepting-ios-traffic
I’m not too familiar with the process on mobile, but my limited understanding is depending on how the app is communicating with the servers, this might not be possible. Another possibility is seeing if this functionality is available through the website, in which case its much easier. I haven’t used the app or website in a long time, so I have no idea what has changed, if anything, since I initially wrote the integration.

1 Like

did you get a chance to look at this over break? If we can provide anything to help, let us know.

So it turns out someone last year did enough to decode the API calls necessary to ‘set’ the sleep number, provided your bed at least allows cloud control (you can check via your app - the option will be there).

Check it out here:

I’ve tried it myself (just installed it on my raspberry pi) and it works like a charm. But for some reason I can’t get the same thing to work in SmartThings. I continue to get a 401 error, despite being pretty sure all of the cookie and session variables are correct.

Here is my function code (I was hacking away at a doStatus copy to try this out), which I added to Natecj’s previous efforts. Maybe someone else with a bit more HTTP-foo can take it the rest of the way?

private def doSetSleepNumber(value) {
log.trace “doSetSleepNumber(${value})”

// Make the request
/*
data = {‘bed’: bedId, ‘side’: side, “sleepNumber”: int(round(setting/5))*5}
self._session.params[‘side’]=side
r=self.__make_request(’/bed/’+bedId+’/sleepNumber’, “put”, data)
del self._session.params[‘side’]

/
//uri: ApiUriBase() + ‘/rest/bed/’ + bedd + ‘/sleepNumber?_k=’ + state.session?.key,
try {
doLogin()
def bedd = -9999999029697646152
def setParams = [
uri: ApiUriBase() + ‘/rest/bed/’ + bedd + ‘/sleepNumber’,
bed: bedd,
side: ‘R’,
sleepNumber: ‘100’,
_k: state.session?.key,
headers: [
‘Content-Type’: ‘application/json’,
‘User-Agent’: ‘python-requests/2.12.4’,
‘Cookie’: state.session?.cookies,
‘Accept’: '
/*’,
‘Accept-Encoding’: ‘gzip, deflate’,
‘Connection’ : ‘keep-alive’
],
]
state.session.side = ‘R’
httpPut(setParams) { response ->
if (response.status == 200) {
log.trace “doSetSleepNumber() Success - Request was successful: ($response.status) $response.data”
doStatus(true)
} else {
log.trace “doSetSleepNumber() Failure - Request was unsuccessful: ($response.status) $response.data”
state.session = null
state.requestData = [:]
}
}
} catch(Exception e) {
if (alreadyLoggedIn) {
log.error “doSetSleepNumber() Error ($e)”
} else {
log.trace “doSetSleepNumber() Error ($e)”
doLogin()
}
}
}

@panealy did you ever get this to work??

In a way, yes. I’m working on buttoning it up now.

Thanks for the update.

I need to integrate with SmartThings, but that’s the easier part, honestly. Below is a fully working method of managing your Sleep Number bed via Alexa. The README should describe how to set it all up, but note that I have not done a dry run of my own instructions yet. This was based off of the work I did to set it up in the first place.

I plan to create a new thread once the SmartThings work is complete, but I’ll share the current working LAMBDA plus Alexa Skill now:

https://github.com/panealy/aws/tree/master/sleepiq

Hey Pete - thanks for your work on this! I was going to check out the alexa skill but the link brings me to a 404 with github.

That was my bad. It is public now!