Eight Sleep Mattress - Port from ST

Closer… when I try to add the device from the app I receive

null on line 553

which corresponds to this code:

   if (state.eightSleepAccessToken) {
   		def now = new Date().getTime()
   		def sessionExpiryTime = Date.parse("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", atomicState.expirationDate).getTime()

I tested that line and there are no syntax issues with Date.parse or getTime(). So it looks like atomicState.expirationDate is the problem. Possibly try completely removing the app and starting over. Some values may have not been set with the previous errors. If you still have the error, click the blue i icon next to the App and check if expirationDate is listed and has a value.

So here is a shot.... there is no expirationDate at all?

![20%20PM|690x356](upload://6IqH5tpAr0B3stlDvL8c8vcLp3N.png)

Also perhaps the full log would be helpful.  It seems everything initiates, just when I go to select my devices, I am not presented with choices.

2018-03-19 18:50:58.344:debuginitialize

[app:429](http://192.168.7.201/logs#app429)2018-03-19 18:50:58.343:debuginstalled

[app:429](http://192.168.7.201/logs#app429)2018-03-19 18:50:36.741:errornull on line 553

[app:429](http://192.168.7.201/logs#app429)2018-03-19 18:50:27.632:debugeightSleepTokenExpirationDate: 2018-04-02T22:50:27.526Z

[app:429](http://192.168.7.201/logs#app429)2018-03-19 18:50:27.631:debugeightSleepUserId: 2ddb0e487c814bd38ae64f95129d1774

[app:429](http://192.168.7.201/logs#app429)2018-03-19 18:50:27.629:debugeightSleepAccessToken: 58c148b2200a4530826c38b0ba091190-b356fa8b6bed0d19d908482c75128bfe

[app:429](http://192.168.7.201/logs#app429)2018-03-19 18:50:27.623:infoBody: [session:[expirationDate:2018-04-02T22:50:27.526Z, userId:2ddb0e487c814bd38ae64f95129d1774, token:58c148b2200a4530826c38b0ba091190-b356fa8b6bed0d19d908482c75128bfe]]

[app:429](http://192.168.7.201/logs#app429)2018-03-19 18:50:27.621:infoStatus: 200

[app:429](http://192.168.7.201/logs#app429)2018-03-19 18:50:26.925:debugBeginning API POST: /login, [emailxxxxx] <-- changed

So it does look like you’re receiving the expirationDate value which is good! Just noticed though that on line 453 where it’s set, it’s mixed with state and atomicState. From what I’ve read the two access methods shouldn’t be mixed. I’ve never tested mixing them, but try changing atomicState to state and see if there’s any change.

Every day a bit more progress is made!

Changing atomicState to state worked and now I can select the device.

Now the error is regarding creating the child device.

I have the driver installed and it is named Eight Sleep Mattress.

Try replacing app.namespace in the two addChildDevice() calls with “alyc100” . The error seems to indicate that app.namespace is ‘null’. It needs to be a string that matches the namespace: definition of your child device. In this case, that would be “alyc100”

I'm sure I did this incorrectly...

I made the same change with respect to the right side code as well.

Change this line…

childDevice = addChildDevice(app.namespace, "Eight Sleep Mattress", "${device}/${leftUserId}", null, data)

to this line

childDevice = addChildDevice("alyc100", "Eight Sleep Mattress", "${device}/${leftUserId}", null, data)

and make the same change for the other one as well.

DONE!!! It works. I will update my GitHub later on to reflect the driver and the app for all that have this (or both of us).

2 Likes

Awesome! I committed the atomicState fix and @ogiewon's app.namespace fix to github. Once all the other bugs are sorted out we can pull the changes back into @justin.bennett's repo.

The error on line 50 could either be device.deviceNetworkId or parent being null. More logging would help narrow it down.

I'd try changing device.currentState("switch").getValue() to device.currentSwitch

So, as it turns out, I was being a bit slow. I didn’t realize that the app would create the device. Once I figured that out, deleted the device and then reloaded the app success smiled upon me.

Thank you for all your help with this!!

I've been playing with it a bit and I can't get any of the on/off options to work for either side. I get the following from the app logs:

for this line of code:

What does it mean when it's says "no encoder?"

You can try changing httpPut to httpPutJson. This is a method in the ST documentation which I haven’t tried it on Hubitat yet. If that doesn’t work, try adding in requestContentType parameter (you can add it in after headers): headers: apiRequestHeaders(), requestContentType: "application/json"

@mattw Thank you very much. I tried the httpPutJson and it now turns on and off. Would I also have to do that with the httppost? I haven’t seen anything in the logs to indicate there is a post happening, but better safe than sorry right?

@justin.bennett. Please add this to your app code and let me know where your GitHub is :slight_smile:

I will, this weekend. Since I really can’t login to hubitat from work (remote login rules and all), I am confined to nights and weekends.

That’s great! Thank you. I’m working on commenting out the code that I’m not finding helpful now. For example, he used the battery as a way to report on the sleep score. Using the battery automatically included it in my HSM battery rule (and I can use the app to see the sleep score) so I commented it out. I’m also looking at the contact switch (in bed) part to see if it works and how I can speed up the reporting of it. I’d like to drive some automation based on whether I’m in bed or not.

I can keep you updated on this if you want. I’m not sure what has value to you in the code though, and it’ll be a slow process as I continue to relearn how to program. Seems that’s taking longer than I thought.

There is definitely something strange going on. The devices will only log a poll and refresh. So, even when I select the On or Off buttons and the Device page shows the switch turning on/off, I don’t see any updates on the Events or Log pages.

I have noticed the lack of logging as well.

In addition, when I make changes through the app, they do not appear in the driver and vice-versa.

I’m going to simply turn on the heater with the driver to see if the bed heats up and report back.

Actually this is the issue, it’s within the Bed App

[app:433](http://192.168.7.201/logs#app433)2018-03-21 21:39:29.433:infoStatus: 200

[app:433](http://192.168.7.201/logs#app433)2018-03-21 21:39:25.799:errorNo encoder found for request content type */* on line 538

[app:433](http://192.168.7.201/logs#app433)2018-03-21 21:39:25.793:debugBeginning API POST: /devices/3b0037000151363133343338, [leftHeatingDuration:11700]

[app:433](http://192.168.7.201/logs#app433)2018-03-21 21:39:23.792:errorNo encoder found for request content type */* on line 538

[app:433](http://192.168.7.201/logs#app433)2018-03-21 21:39:23.779:debugBeginning API POST: /devices/3b0037000151363133343338, [leftTargetHeatingLevel:10, leftHeatingDuration:11700]

I'm not seeing those errors. I'm getting this when I select the "off"

but when I select the "on", I get:

So the app is connecting and doing some things. I'm trying to figure out why it is and not doing some of this.