Background
I have really been wanting to get bed occupancy working with Home Assistant for a while. I have some lights around the house that are triggered by motion detectors. Especially for the one in the bedroom, I thought it would be nice if I could disable the motion-activated light whenever someone is in bed.
Additionally, I thought it would be a good idea to disable some other triggers if both of us are in bed (like motion sensors elsewhere in the house that the cat would set off) or disabling turning on the bathroom fan automatically (due to humidity) if someone is sleeping.
Research
There are a lot of solutions for for doing this:
- Using load sensors under the bed
- Not good for us as our bed is on wheels
- Using aluminum-foil to measure pressure
- I was concerned about the sturdiness of the aluminum foil
- Measuring pressure with FSRs
- I was concerned about the integrity of the solder connections to the FSR strips
- Measuring air pressure with Sleep Number Bed
- I am going to try to set this one up
- Using a Withings Sleep Tracking Mat
Buying the Mats
I bought a pair of the Withings Mats from Amazon for \$179.99. A bit pricey, but I thought the automations would be fantastic and ultimately worth it.
They came in a few days and were easy to set up. I slid them under the mattress width-wise at about chest level when lying down. I used the Withings Health Mate app that I already had on my phone for our Smart Scale to pair the mats.
After about 10 minutes, the Mats were paired and synced with my Withings Account and the Health Mate app.
Initial Problems
Then I set up the Withings integration in Home Assistant. For the life of me, I could not get this to work at all with Home Assistant. I was just not seeing any data from the Withings site from my scale or my sleep mats. I assumed it was a problem with the Withings site because I saw a bunch of postings in the Home Assistant forums.
Then I happened to look at the account info on my phone and realized that I had set up the Dev account with MY email account and not the shared email account I used for the Health Mate app.
So I set up another Dev account per the Home Assistant instructions and re-did the integrations in Home Assistant. Then I started seeing data from my scale. But the In Bed detection still showed Unavailable.
Paying Closer Attention to the Directions
I reread the documentation and saw that setting "use_webhook: true" in Home Assistant for the Withings integration was "also required to populate the in_bed sensor".
So, I turned on "use_webhook" and re-added the integration in Home Assistant. Still no luck.
Light Bulb Moment
I scouring the Home Assistant Community and issues on Github, I saw some people mention issues with the webhook and Withings trying to connect to a private IP address or hostname. And the light bulb went off!
I looked at my Home Assistant settings (Configuration -> General -> External URL) and noticed that the URL was set to my hold URL before I started using the Home Assistant Nabu Casa product. I then went into Configuration -> Home Assistant Cloud and copied my Nabu Casa URL and pasted it into the External URL setting under General.
I restart Home Assistant and added the Integration again and still nothing.
I also went into the Home Assistant Cloud settings and click the enable slider for each webook (my and my wife's profiles).
But at this time, my wife was already in bed. I had not gotten in bed yet so I was anxious to see if by getting in bed and causing a change to the presence sensor, the data at Withings might update and Home Assistant might see the change. And it did! Almost immediately!
Sure enough, after Holly got out of bed in the morning, her status changed to "Clear" from "Unavailable".
Now both of our sensors work in Home Assistant. And the sleep score seems somewhat accurate, so I'll continue using the Sleep Tracking Mats to track my sleep patterns and snoring even if I ultimately go with a different bed presence detection sensor like one of the alternatives I mentioned above.
Conclusion
I hope this helps anyone else struggling.
The TL;DR:
- Use the right email address for the Dev account
- Make sure the External URL is correct (either your external URL or your Nabu Casa URL)
- Set "use_webhook: true" in the Withings integration section of your YAML config.
- Enable the webhook under the Home Assistant Cloud section of the Home Assistant GUI Configuration