How google-home/smarthome-washer works
Project Type and Purpose
• This is a “codelab” full‑stack serverless web application that demonstrates integrating a smart washer device with Google Assistant using Firebase as the backend.
• It comes in two variants (starter and completed), each containing:
• A Firebase Functions directory for smart‑home intent fulfillment
• A public directory serving the web UI via Firebase Hosting
• Firebase configuration and security rules for a Realtime Database
High‑Level Architecture Components
a. Google Assistant / Actions on Google
b. Firebase Cloud Functions (fulfillment webhook)
c. Firebase Realtime Database (device state store, security rules)
d. Firebase Hosting (static web UI)
e. Web Client (public/main.js + index.html)
f. (Conceptual) Smart Washer Device
Component Responsibilities
• Google Assistant: receives user voice commands (“Hey Google, start the washer”) and routes Smart Home intents (SYNC, QUERY, EXECUTE) to your Cloud Function endpoint.
• Cloud Functions (washer‑done/functions/index.js):
• Implements the Google Smart Home fulfillment API
• Handles SYNC (device discovery), QUERY (status), EXECUTE (start/stop washer)
• Reads/writes device state in the Realtime Database
• Realtime Database (washer‑done/database.rules.json):
• Persists device attributes (on/off, progress, diagnostics)
• Enforces read/write security via Firebase rules
• Firebase Hosting (washer‑done/public):
• Serves static assets (index.html, main.js, main.css)
• Provides a web dashboard to manually view or send commands to the washer by writing to the database or calling Functions
• Web Client:
• Listens for DB state changes (via Firebase SDK)
• Pushes user‑initiated commands (start/stop) back into the database or invokes Cloud Functions directly
Interactions and Data Flow
1. User issues voice command → Google Assistant → Actions on Google cloud
2. Actions cloud invokes your Cloud Function webhook
3. Cloud Function reads/writes to Realtime Database
4. Database change triggers:
– Function returns status back to Assistant → user hears confirmation
– If web client is open, it receives real‑time updates via Firebase SDK
Separately:
5. User opens the web UI (hosted on Firebase Hosting)
6. Web UI loads static assets + Firebase SDK, subscribes to Realtime DB
7. Web UI shows device status and can send commands to DB or call Functions
Architectural Patterns and Principles
• Serverless backend: no self‑managed servers, uses Firebase Functions + Realtime DB
• Event‑driven: DB triggers UI updates and may trigger backend logic
• Separation of concerns:
• Hosting layer (static UI)
• Business logic layer (Functions)
• Data persistence layer (Realtime DB)
• Declarative security: all data access controlled via database.rules.json
Diagramming Guidance
– Google Assistant (cloud bubble)
• Control plane (Assistant & Functions): e.g., blue
• Data plane (Database & UI updates): green
• Presentation layer (Hosting & Web Client): orange
[ ] Every component is labeled (e.g., “Firebase Realtime Database”).
[ ] Important technologies (Firebase Functions, Hosting, Realtime DB, Actions on Google) are noted.
[ ] Interactions (SYNC, QUERY, EXECUTE) are annotated on the Assistant → Function path.