I have been wanting to figure out an automatic way of knowing whether or not my wife and I are in bed or not. This would allow for some additional automations, like automating Hubitat Safety Monitor arming at night, automatic path lighting in the middle of the night, notification of sleep walking, etc... This might also be useful for ensuring children are where they are supposed to be Or for knowing if elderly loved ones are following their normal routine.
I have added a new Device Class to ST_Anything called IS_Presence. This class simply monitors a digital input to see if the signal has changed from high to low (very similar to a IS_Contact sensor device.) Using this new device, a Child Presence Sensor Hubitat device will be created for each sensor. This Presence Sensor device can then be used to trigger any automations that you desire in Hubitat.
The real trick for this project is the hardware. I found an example from a Home Assistant user that I thought would work well with my memory foam mattress/solid platform. This design uses a 24" long Force Sensitive Resistor, which provides decent coverage for a variety of sleeping positions. It also allows for multiple FSR's to be used on a one bed, to detect two distinct occupants.
This is the model of FSRs that I purchased from SparkFun. I believe Adafruit also sells these, but does not sell the same connector.
UPDATE: A user has informed me that the FCI Clincher connector below may not be the best idea for attaching wires to the FSR strips. Soldering is NOT recommended as the heat will melt the FSR plastic. So, you may want to simply try using a standard female jumper wire pair and see if you can get a good solid connection with the FSR.
Here is the connector that simplifies the wiring to the FSR (as soldering is known to damage these sensor strips.) Crimping this connector on to the FSR does take some work, but once attached seems to work well.
WARNING: To use these connectors you have to snip off the small "pins" from the FSR strip, making it impossible to go back afterwards.
And here is what it looks like as the connector is attached to the FSR strip. This is not exactly a simple align, crimp, and forget. It takes some time and effort with a pair of pliers to get this connector crimped and then even more work to get the plastic cover to stay latched. As I mentioned above, please try using a standard female jumper wire connector instead and see if you get a good connection.
In this first picture, the 'pins' have already been snipped off of the FSR's electrical connection.
FSR inserted into the connector.
Connector crimped and closed.
Since this is a fairly unique solution, wiring diagrams are not readily available online. I created a Fritzing diagram to explain the wiring should you like to attempt this project. Note - the 10k resistors shown are simply a starting point to adjust the amount of force required on the strip to cause a change in the presence status. Feel free to try various values to find something that works for your specific needs. I believe the user's weight and type of mattress will factor into the resistance that works best to prevent false status changes while rolling over in your sleep. I would probably stick to a range of 1k to 22k resistors, as higher values resulted in no change detected whatsoever.
Finally, I have created an example HubDuino Arduino sketch to help you get started. This example implements two sensors and matches the wiring diagram above.
I would like to thank @marktheknife for helping to inspire me to complete this project which I have had on the back burner for a few months.
If you have any questions or suggestions, I would love to hear them. If you try this project, please let us all know how it works for you. I can always tweak things to improve the reliability based on feedback from the community.