Building a Home Office Weather Station with Raspberry Pi and Supabase
Ever wondered about building your own IoT weather station? I recently set up one in my home office using a Raspberry Pi and DHT-22 sensor, with Supabase as the backend. The entire project took just one day to complete - though keeping it running is another story entirely (more on that later).
Hardware Setup
The setup is deliberately simple:
- Raspberry Pi (any recent model will do)
- DHT-22 temperature and humidity sensor board
- A few jumper wires
- And most importantly, my ability to remember to plug it in every morning 😅
The DHT-22 is perfect for indoor use, offering good accuracy (±0.5°C, ±2-5% RH) at a reasonable price point.
Data Flow Architecture
Let’s talk about the “real-time” aspect (air quotes very much intended). Here’s how it works:
- Raspberry Pi wakes up every 5 minutes (assuming I remembered to turn it on)
- It reads the sensor data and sends it to Supabase
- The website fetches and displays the readings
So if you’re seeing data from three hours ago, there’s a good chance I got caught up in meetings and forgot to power on my little weather friend. Hey, even weather stations need their beauty sleep, right?
Securing the Database
Security was a top priority. Instead of exposing tables directly, I implemented several layers of protection:
-
Schema Isolation
- All tables live in a private schema
- No tables in the public schema
- No direct REST API exposure via Supabase
-
Public Interface
- All data access is strictly through database functions in the public schema
- Functions act as a controlled API layer
- Fine-grained access control at the function level
Feel free to use the exposed API in your own projects - though keep in mind that real-world applications are limited (it’s just my home office temperature after all, not a full-blown weather forecasting system). And remember, the data freshness is directly proportional to my memory to power on the Pi each morning. Maybe we should call it “eventually consistent” weather data? 😉
Frontend Implementation
The website’s weather widget is built using modern React patterns and components:
-
Data Fetching
- React Query handles the “real-time” updates (every 5 minutes, remember?)
- Automatic background refreshing
- Built-in caching and error handling (especially useful for those “oops, forgot to plug it in” moments)
-
UI Components
- Built using shadcn/ui for a polished look
- Responsive design that works on all devices
- Clean animations for data updates
- A subtle “Last Updated” timestamp that occasionally serves as a public reminder of my forgetfulness
Results
The weather station has been running reliably(ish), providing semi-real-time temperature and humidity data from my home office. The combination of Raspberry Pi’s reliability, Supabase’s robust backend, and modern React patterns has created a maintainable and secure IoT solution. Now if only I could automate the “turning it on” part…
You can see the live(ish) weather widget in action on my homepage, which I covered in my previous post about migrating to Astro. For the data nerds among you (and I know you’re out there), I’ve also created a historical data page with fancy charts showing temperature and humidity trends over time. Just don’t ask about those mysterious data gaps - they’re not system downtime, they’re… uh… planned maintenance periods. Yeah, that’s it.