My bed has an API, so obviously I want to integrate it into homeassistant 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.