At ADBV-POOLS, we’ve always believed that pool management should be as wonderful as enjoying the pool itself. That’s why we created ZwemcoCloud, an app that makes it incredibly easy to control everything about your swimming pool. With a user-friendly interface and compatibility with most major swimming pool device brands, ZwemcoCloud puts control of your pool’s temperature, lighting, filtration, and more at your fingertips—whether you’re poolside or halfway across the world.
But we wanted to take this convenience one step further. That’s when my colleague came up with an idea: what if controlling your pool could be as easy as talking to your smart speaker? After looking into several options for voice control, we decided that integrating ZwemcoCloud with Google Home would be the best first step. Our goal was to make the app even more accessible through voice commands, so you could say, “Hey Google, turn on the pool lights” or “Set the pool heater to 28°C” without ever touching your phone.
From Concept to Reality
To integrate ZwemcoCloud with Google Home, we opted for a cloud-to-cloud approach. This allowed us to securely connect our platform with Google’s ecosystem, enabling seamless communication between your pool’s smart devices and Google Home. The first step in this integration was implementing OAuth2, a robust and secure protocol for granting third-party applications access to user data.
Step 1: Implementing OAuth2 for Secure Authorization
OAuth2 was crucial for ensuring that ZwemcoCloud and Google Home could interact securely. The protocol ensures that users can authorize Google Home to access their ZwemcoCloud account without sharing sensitive login information like usernames and passwords. Instead, Google Home receives access tokens that allow it to interact with ZwemcoCloud on behalf of the user.
To start, we created an OAuth2 authorization endpoint that handles the flow of tokens. When a user connects their ZwemcoCloud account to Google Home, they’re first redirected to our authorization page, where they can log in. After they grant permission, our server issues JWT (JSON Web Tokens) to Google. These tokens act as proof that Google is authorized to query ZwemcoCloud for information about the user’s pool devices.
The tokens come in two forms:
- Access Tokens, which allow Google to make short-term requests (like turning on the heater).
- Refresh Tokens, which allow Google to request new access tokens when the original expires.
This ensures that the connection between ZwemcoCloud and Google Home remains secure, without forcing the user to reauthorize every time they want to give a command.
Step 2: Syncing Google Home with ZwemcoCloud User Devices
Once OAuth2 was implemented, the next step was to make sure that Google Home could “sync” with the user’s pool devices in ZwemcoCloud. This is where the magic of device discovery happens. Google needs to know what devices are linked to the user’s ZwemcoCloud account—whether it’s a heat pump, lighting system, or pool filter.
To do this, ZwemcoCloud exposes an API endpoint that lists all the devices associated with a user when Google makes a SYNC request. We provide Google with information about these devices, including their traits—specific features that Google can control or query, such as the current temperature of the pool or whether the lights are on.
For example, if the user has a heat pump, ZwemcoCloud sends Google details like its temperature range and any additional traits, such as whether it can be turned on or off remotely. This allows Google to integrate these devices into its ecosystem and respond to user queries like, “What’s the maximum temperature of the pool?”
Step 3: Querying Device Attributes Securely
After syncing, the next step was making sure Google Home could query the status of these devices securely. For example, after discovering a heat pump, Google might send a QUERY request to ZwemcoCloud to find out what temperature it’s currently set to.
Security here is critical. We had to ensure that users can only query and control devices they own. We implemented multiple checks in the system to confirm that the user’s identity is valid and matches the device being controlled. Even if someone attempted to forge a request to control another user’s pool, our system would reject it. This ensures that no unauthorized user can access or control devices outside of their own ZwemcoCloud account.
Step 4: Executing Commands
Once Google Home knows what devices a user has, the next step is executing commands. For instance, when the user says, “Turn off the pool filter,” Google sends a command to ZwemcoCloud, which translates the request and communicates with the pool’s control system.
Google Home uses a very specific JSON format for its EXECUTE commands, which ZwemcoCloud must adhere to. These commands are structured in a way that precisely specifies what action should be taken on which device. For example, the JSON might specify the target device (e.g., “heat pump”) and the action (e.g., “set temperature to 28°C”).
Step 5: Implementing Report State
The final step was implementing Report State, a feature that allows ZwemcoCloud to continuously send updates to Google about the current status of a user’s pool devices. This way, Google doesn’t need to query ZwemcoCloud for information constantly. Instead, whenever a user changes the pool temperature, turns on the lights, or starts the filtration system, ZwemcoCloud immediately reports the new state back to Google.
This not only improves efficiency but also enhances the user experience. For example, if you turn on the pool heater through ZwemcoCloud, Google Home will already know it’s on when you ask, “Is the pool heater running?”
What I Learned from the Google Home Integration Project
This project was a fantastic learning experience that expanded my technical knowledge in multiple areas. I gained a deeper understanding of:
- OAuth2 and security protocols, learning how to securely manage user authorization and how to handle access and refresh tokens for a smooth, secure experience.
- Google Home’s device and trait models, which gave me a better grasp of how voice assistant platforms communicate with third-party services.
- API design and endpoint management, ensuring that ZwemcoCloud’s API could handle complex requests in real-time while maintaining a high level of security.
- JSON formatting and command execution, where I learned the intricacies of handling Google’s specific request and response formats.
This project also reinforced the importance of security in IoT (Internet of Things) devices. Given the nature of the data and the direct control over physical devices, ensuring that unauthorized users can’t access or manipulate pool systems was a top priority.
In conclusion, the integration of ZwemcoCloud with Google Home has made pool management easier and more accessible than ever. It was a challenging project that not only improved our app but also strengthened my technical skills and understanding of cloud-based integrations. Now, ZwemcoCloud users can enjoy seamless voice control of their pools, bringing a new level of convenience and simplicity to pool ownership. I want to thank Kjetil for guiding me trough this project.
Want to discuss this article with me?