Feedback on component for SleepIQ beds

My bed has an API, so obviously I want to integrate it into homeassistant :smiley: SleepNumber beds have an addon called SleepIQ. It tracks sleep over time, and in particular, it does know if you are in bed or not, and it knows your ‘SleepNumber’ (firmness of the mattress). There are controls for changing the incline of the frame, and firmness, but it requires using bluetooth near the bed, and doesn’t seem to be exposed by the API (I wrote the library sleepyq for interacting it, and made some notes: https://github.com/technicalpickles/sleepyq).

This is my first component, and first real python, so I was hoping to get some feedback before preparing to contribute it.

Here’s the code (place in ~/.homeassistant/customcomponents/sensors/sleepiq.py): https://gist.github.com/technicalpickles/e642164926f4259aa029409f59b0baa3

And a screenshot:

I have a couple questions in particular:

The ‘is in bed’ sensor is at some point a boolean value in a JSON response coming back. It gets represented as True or False in Python, and it seems that setting that as a sensor value renders it as a string ‘True’ or ‘False’. Are there any conventions for this? My Ecobee3 occupancy sensors uses ‘true’ and ‘false’. The current name of the sensor would suggest ‘yes’ or ‘no’ as more logical.

I went with making it a sensor, rather than a platform so the config is like:

sensor:
  platform: sleepiq
  login: whatever
  password: whatever

I was thinking it’d be a little clearer to make it a platform, so it’d be like:

sleepiq:
  login: whatever
  password: whatever

Is there a convention for when to use a platform vs the type of component (ie sensor)? Some part of me hopes they release more API functionality, so I can make a bed domain, and that would justify a platform I think.

2 Likes

I forgot to mention I used the forecast.io and fitbit components for inspiration.

It seems that creating a component, a binary sensor platform (is in bed), and a sensor platform (counter) could be a way to go as both platforms would share the same details.

I would like to suggest that you create a PR for the integration into Home Assistant. This would make it easier to make comments on the code.

Was just going to suggest the same thing that @fabaff did. Build a single component (sleepiq) which make the “in bed” sensor a binary_sensor and then the SleepNumber can be a sensor (which could even have in bed state as an attribute, and the binary_sensor can have the SleepNumber as an attribute).

If you want to go a bit further and give back to the community, you should add a new sensor_class to binary_sensor for occupied (on meaning occupied, off meaning not occupied). You would also want to add the new class to the frontend.

1 Like

Ecobee occupancy sensor has been moved to be a binary sensor for 0.27 (source)

1 Like

https://github.com/home-assistant/home-assistant/pull/2949 is the PR for this, thanks!

Hey @technicalpickles, great work on the sleepiq API. Not sure if you noticed but in the SleepNumber app, there is now a cloud option for control over the bed. No longer need BlueTooth. You can test this by turning off Bluetooth on your phone. See the cloud icon on the top right.

Would love to be able to routinely bump the firmness up to 100 and then back to the desired number before bed. This is a great way to keep the bed at the appropriate firmness.

I’m not sure what is different, but I don’t seem to have that option. I don’t have the cloud icon, and anytime I try to use the remote w/o bluetooth, it says I need it. Maybe it’s only in newer SleepIQs? Or an update I haven’t gotten yet?

Given that, I don’t think I would be able to write this without being able to develop & test. Happy to accept PRs to sleepyq to support that though.

1 Like

I also can’t connect without BLE. I just tried at work. It immediately fails and kicks me out of the remote. @CCOSTAN how long ago did you buy your bed?

EDIT: Looks like if you are out of BLE range it will fall back to WiFi (same network) or fail if WiFi is not available. While at home and downstairs (out of bt range) it failed over to WiFi and I now see the cloud icon.

1 Like

I bought the bed just a month or two ago. It’s an i8.

Mine is about a year old, an ILE.

I looked through the mobile app, and there doesn’t seem to be any information about the firmware or hardware version. It’s been awhile since I looked at data from sleepiq, but that may have some metadata in it.

My Mobile app shows version 2.6.1. Under Support.

1 Like

2.6.1 here as well. My bed is also ILE bought about a year ago.

The iot class of this component is listed as “local polling” but this is not the case. The component is only able to detect bed occupancy when I unblock the bed’s access to the internet on my router.

I’ve recently configured my Hassio raspeberry pi 3B to look for my SleepIQ bed.

Many times it works great, but sometimes… I get a lot of messages about length of time for the response. Since this is an API and SleepIQ may be doing something to throttle the volume of requests… Is anyone else running into this?

Error:
Updating sleepiq binary_sensor took longer than the scheduled update interval 0:00:30

I’ve set up a WeMo switch to cycle the bed twice a day, I’ve monitored it. I’ve manually restarted it. I’ve ensured 10 full minutes pass between turning it off and turning it on… all with very mixed results.

Curious to know if others are seeing similar - or if someone has found a solution.

Any chance “responsive air” can be located and toggled on and off from Homeassistant? What is exposed in the API that could be added? This is a great component but it’s limited in scope. I don’t have the skill to do it though. Thanks for your efforts!

It would be great if we could somehow access the preset positions for the frame and possibly allowing a change of the sleep number setting and turning on/off responsive air. Anyone still following this discussion?

Hi All, any news? Is this still active? How can I contribute? Just got an M7.

There’s a PR open for adding support to set sleep number, and favorite sleep number values. https://github.com/home-assistant/core/pull/30722

It looks like that PR was closed after becoming stale. From what I can tell though it was mostly ready to merge? What would be the best next step to see this happen, should we reopen that PR, or perhaps start a new PR (from a new branch) with the changes? I haven’t done much development with HA (yet!) so concerned about a steep learning curve, but I’d be happy to help.

1 Like