My Smart Home Automation Journey: A Bed Occupancy Sensor DIY Project

Hello everyone! I wanted to share my recent DIY project that I’ve been working on for the past few months. It’s a bed occupancy sensor using a Raspberry Pi Zero WH, an AnalogZero pHAT, and force-sensitive resistors (FSRs). While the project is still a work in progress, I thought it would be a great opportunity to document my experience and share some insights with the community.

The idea behind this project was to create a sensor that could detect whether someone is in bed or not, which would then trigger various automations in my smart home. For example, turning off the lights, adjusting the thermostat, or even controlling smart speakers. The possibilities are endless!

The Setup

I started by gathering all the necessary components:

  • Raspberry Pi Zero WH: I chose this because I already had it on hand and it’s compact enough to fit under the bed.
  • AnalogZero pHAT: This allows the Raspberry Pi to read analog sensor inputs, which is essential for the FSRs.
  • Force-Sensitive Resistors (FSRs): I used four of these, placed strategically on the slatted frame of my bed.

The FSRs are connected to the pHAT via a voltage divider circuit, which converts the resistance readings into a voltage that the Raspberry Pi can interpret. I wrote a Python script to read the sensor values and store them in a text file for analysis.

Challenges and Solutions

One of the biggest challenges I faced was getting consistent readings from the FSRs. I discovered that one of the sensors I ordered was faulty, giving non-zero readings even when no pressure was applied. After isolating the problem, I decided to work around it by focusing on changes in the sensor values rather than the absolute values themselves.

Another challenge was attaching the FSRs to the slatted frame. They are quite thin and don’t hold well in female headers, so I had to get creative with my wiring. I ended up using extra-long FSRs and securing them with adhesive tape to ensure they stayed in place.

Current Progress

At this stage, the sensor is successfully reading the values and storing them for analysis. My next steps involve integrating MQTT to send these readings to my Home Assistant instance. From there, I plan to create automations based on the sensor data. For example, if the sensor detects that someone is still in bed after a certain time, it could automatically adjust the thermostat or turn off the lights.

I also hope to use the data to determine different states, such as whether someone is still asleep, just waking up, or has left the bed. This would allow for more granular control over my home automation system.

Future Plans

Looking ahead, I plan to:

  • Integrate MQTT: This will allow the sensor data to be used within my smart home ecosystem.
  • Develop Automations: Based on the sensor data, I’ll create rules to control various devices around the house.
  • Enclosure Design: I need to create a housing for the Raspberry Pi and pHAT to protect them and make the setup more permanent.

Final Thoughts

This project has been a fantastic learning experience. It’s pushed me out of my comfort zone, especially when it comes to working with sensors and analog circuits. I’m excited to see where this project goes and how it can enhance my smart home setup.

If anyone has any tips or suggestions, I’d love to hear them! Happy tinkering everyone! :rocket: