Version: 0.1.3
The SwitchBot Data Logger for Google Sheets is designed to collect data from SwitchBot devices and optionally the OpenWeatherMap API, and log the data (temperature, humidity, and absolute humidity) to a Google Sheets document.
- Retrieve data from SwitchBot devices
- Optionally fetch weather data from the OpenWeatherMap API
- Calculate absolute humidity
- Log data to Google Sheets (humidity, temperature, and absolute humidity)
- Automatically update data at specified intervals
- Easily expandable to include additional data sources
- dataAquisition.gs
- writeDataToSheet.gs
getSwitchbotData()
: Fetches data from SwitchBot devices using the SwitchBot API.getOpenWeatherMap()
: Retrieves weather data from the OpenWeatherMap API (optional).combineJsonData()
: Combines data from SwitchBot devices and, if desired, OpenWeatherMap API or other additional data sources.calculateAbsoluteHumidity()
: Calculates absolute humidity based on temperature and relative humidity.writeDataToOneSheet()
: Writes data to a specified sheet in the Google Sheets document.writeDataToAllSheets()
: Logs data to all sheets (humidity, temperature, and absolute humidity).
- Create a new Google Sheets document.
- Click on "Extensions" in the menu and then select "Apps Script."
- In the Apps Script editor, create two new script files with the names
dataAquisition.gs
andwriteDataToSheet.gs
. - Copy the content of the
dataAquisition.gs
file from this project into the corresponding file in the Apps Script editor. - If you want to use the OpenWeatherMap data, update the
API_KEY
in thegetOpenWeatherMap()
function with your own OpenWeatherMap API key, and uncomment the respective lines in thewriteDataToAllSheets()
function. - Update the
token
andsecret
variables in thegetSwitchbotData()
function with your SwitchBot API key and secret. - Copy the content of the
writeDataToSheet.gs
file from this project into the corresponding file in the Apps Script editor. - Create three new sheets in your Google Sheets document with the names "humidity", "temperature", and "absoluteHumidity."
- Run the
writeDataToAllSheets()
function in the Apps Script editor to log the data to your Google Sheets document. - To include additional data sources, add the necessary functions to fetch the data and modify the
combineJsonData()
function to include the new data.
To automatically log the data at regular intervals, you can create a time-driven trigger in the Apps Script editor:
- Click on the clock icon (Triggers) in the left sidebar of the Apps Script editor.
- Click the "+ Add Trigger" button in the bottom right corner.
- Choose the
writeDataToAllSheets()
function for the "Choose which function to run" option. - Select "Time-driven" as the event source.
- Choose the desired time interval (e.g., every hour or every day).
- Save the trigger.
The data logger will now automatically log the data at the specified interval.
To effectively visualize and analyze the data logged by the SwitchBot Data Logger for Google Sheets, we recommend using the GAS Dynamic Data Visualizer project. This web app allows you to create beautiful, responsive line charts for any combination of data sets directly fetched from your Google Sheets document.
The GAS Dynamic Data Visualizer provides an easy way to filter data by date range, with auto-resizing charts based on window size. It is highly customizable and powered by Google Charts and Google Apps Script, making it a seamless solution for visualizing the data logged by the SwitchBot Data Logger.
To set up the data visualization, follow the instructions in the GAS Dynamic Data Visualizer repository.
This project is inspired by the work of the OpenAI community and utilizes the following APIs:
This project is released under the MIT License.