Withings Sleep + Homekit Integration
2 min read • 290 words
Update July 2020: I am using Pushcut with an iPod Touch as a server, and have stopped using this package. I've simplified my setup and have IFTTT forwarding the Withings Sleep webhook straight to Pushcut.
I got the Withings Sleep Mat as a gift. While the sleep tracking and health app integrations are cool, what I find exciting is that it can sense when I get in and out of bed. This gives me lots of new automation ideas to implement in my smart home. I was mad excited to start playing with this aspect of the sleep mat, but once I got everything set up, I was disappointed to learn that the Withings Sleep Mat doesn't integrate with HomeKit, only IFTTT, leaving Apple users out to dry.
I couldn't have this. My house needs to know when I get in or out of the bed, and a Shortcut should be able to determine if I am in bed or not–if the sleep mat doesn't enable that, its only realizing half of its purpose.
After brainstorming, I figured I can use the same contact sensor approach that I use to bridge plex to HomeKit, with the help of
homebridge-http-webhooks. Except this time, the incoming webhook will be coming from IFTTT, which the sleep sensor does support.
I adapted the code I use to receive Plex webhooks and forward it to
hemebridge-http-webhooks, and repurposed it for receiving webhooks from IFTTT and sending them along to HomeBridge. Find it here.
Note the code integrates with ngrok. The node server runs on your local network, while IFTTT is a hosted service, so ngrok is used to set up a persistent hostname for handling the incoming requests. This requires a paid ngrok account.