Skip to content

This Guidance demonstrates how to integrate building systems, assets, and sensors to enable real-time and historical insights for sustainable building management.

License

Notifications You must be signed in to change notification settings

aws-solutions-library-samples/guidance-for-smart-and-sustainable-buildings-on-aws

Smart and More Sustainable Buildings on AWS

日本語はこちら

Table of Contents

  1. Overview
  2. Prerequisites
  3. Deployment Steps
  4. Deployment Validation
  5. Running the Guidance
  6. Next Steps
  7. Cleanup
  8. FAQ
  9. Notices
  10. Authors

Overview

This is an example implementation of this Solution Guidance to demonstrate how to collect and visualize buildings data to gain insight and automate operation to optimize energy usage, cost, and associated Greenhouse Gas (GHG) emissions.

This guidance uses the AWS Cloud Development Kit (AWS CDK) to deploy infrastructure assets and AWS IoT Greengrass to deploy component to edge devices.

Architecture

architecture

  1. In this sample scenario, we have two buildings with a heater and ventilation system. The aim is to keep the building at a desired temperature and air quality while optimizing energy usage.
  2. Install plug-in sensor to measure the energy usage of the heater and store data in an external service accesible via API.
  3. Install edge IoT device with AWS IoT Greengrass components. One component collects temperature and CO2 ppm sensor data and sends to AWS IoT Core, and the other component ventilates the building automatically by monitoring the IoT Things Device Shadow that indicates if the CO2 ppm is too high.
  4. AWS IoT Core collects the sensor data and routes it to AWS Lambda for storage in Amazon Timestream for real-time data analytics.
  5. Amazon EventBridge triggers AWS Lambda at regular intervals to collect data from external services, such as energy usage and weather data service.
  6. Amazon Managed Grafana connects to Amazon Timestream to visualize data in real-time.

dashboard

Cost

You are responsible for the cost of AWS services used while running this Guidance sample code.

Note: Actual costs may vary based on factors such as the number of devices, Amazon Managed Grafana users, and frequency of Amazon Timestream queries.

Example 1: 2 devices

As of August 2024, the estimated cost for running this solution in the US West 2 (Oregon) region with following assumption is approximately $117.43 per month.

Assumptions

This cost scenario is based on the following configuration:

  • IoT Sensor Data ingestion from 2 IoT Greengrass Devices at 10-second intervals (518,400 requests/month)
  • Energy usage API data collection at 1-minute intervals (43,200 requests/month)
  • Weather data collection at 5-minute intervals (10,800 requests/month)
Cost Breakdown by Service
AWS service Dimensions Monthly Cost [USD]
AWS IoT Greengrass 2 Active Devices $0.33
AWS IoT Core 86,400 connection minutes, 518,400 Messages, 518,400 Device Shadow operations,518,400 Rule Engine actions $1.42
AWS Lambda (IoT Sensor Data Collection) 518,400 requests, 128 MB memory allocation, 200 msec duration $0.32
AWS Lambda (Device Shadow) 518,400 requests, 128 MB memory allocation, 1s duration $1.18
AWS Lambda (Energy Usage Data Collection) 43,200 requests, 128 MB memory allocation, 200 ms duration $0.19
AWS Lambda (Weather Data Collection) 10,800 requests, 128 MB memory allocation, 1s duration $0.02
Amazon Timestream 1KB record size, 0.62 GB memory store writes, 4 TCU x 40 hours, 3 days memory retention, 3 month magnetic storage retention $84.77
Amazon Managed Grafana 2 active editors, 2 active viewers $28
Amazon DynamoDB 1 million read requests units $0.13
AWS Secrets Manager 2 secrets, 54,000 API calls $1.07
Total Estimated Monthly Cost $117.43

Example 2: 1,000 devices

As of August 2024, the estimated cost for running this solution in the US West 2 (Oregon) region is approximately $4,671.12 per month.

Assumptions

This cost scenario is based on the following configuration:

  • IoT Sensor Data ingestion from 1,000 IoT Greengrass Devices at 10-second intervals (259,200,000 requests/month)
  • Energy usage API data collection at 1-minute intervals (43,200 requests/month)
  • Weather data collection at 5-minute intervals (10,800 requests/month)
  • 10 devices are installed per building. Each building has 1 Amazon Managed Grafana viewer.
  • Amazon Timestream queries are made 8 hours/day for 30 days/month with average of 4 TCU.
Cost Breakdown by Service
AWS service Dimensions Monthly Cost [USD]
AWS IoT Greengrass 1,000 Active Devices $163.60
AWS IoT Core 43,200,000 connection minutes, 259,200,000 Messages, 259,200,000 Device Shadow operations, 259,200,000 Rule Engine actions $703.34
AWS Lambda (IoT Sensor Data Collection) 259,200,000 requests, 128 MB memory allocation, 200 msec duration $159.84
AWS Lambda (Device Shadow) 259,200,000 requests, 128 MB memory allocation, 1s duration $591.84
AWS Lambda (Energy Usage Data Collection) 43,200 requests, 128 MB memory allocation, 100s duration $9.01
AWS Lambda (Weather Data Collection) 10,800 requests, 128 MB memory allocation, 100s duration $2.25
Amazon Timestream 1KB record size, 310.80 GB memory store writes, 4 TCU x 730 hours, 3 days memory retention, 3 month magnetic storage retention $2,459.67
Amazon Managed Grafana 2 active editors, 100 active viewers $518.00
Amazon DynamoDB 500 million read requests units $62.5
AWS Secrets Manager 2 secrets, 54,000 API calls $1.07
Total Estimated Monthly Cost $4,671.12

Folder structure

smart-and-sustainable-buildings/
├── bin
│   └── smart-and-sustainable-buildings-demo.ts (CDK Main App)
├── docs (Documentation)
│   ├── README-ja.md (Japanese README)
│   └── DEVICE_SETUP.md (How to set up device)
├── imgs (Images such as screenshots)
├── lib
│   ├── construct (CDK Constructs)
│   │   ├── gdk-publish (Greengrass Development Kit related constructs)
│   │   ├── datastore.ts (Timestream)
│   │   ├── greengrass-bootstrap.ts (Bootstrapping Greengrass)
│   │   ├── iot.ts (AWS IoT Core Rule and related Lambda)
│   │   ├── power-data-collection.ts (Collecting energy usage)
│   │   └── weather-data-collection.ts (Collecting weather data)
│   ├── gg_components (AWS IoT Greengrass Components)
│   │   ├── automate-ventilation (Component to automatically ventilate)
│   │   └── sensor-data-collection (Component to collect sensor data)
│   ├── grafana (Grafana Dashboard)
│   │   └── dashboard.json (Grafana Dashboard Template)
│   ├── lambda (Lambda functions assets)
│   │   ├── external-data-collection (Lambda functions to collect data from external service)
│   │   ├── gdk-publish (Lambda for publishing Greengrass Development Kit)
│   │   ├── iot (Lambda to handle IoT data)
│   │   └── layer (Lambda Layer)
│   ├── data-collection.ts (Stack for deploying backend resources)
│   └── greengrass-stack.ts (Stack for publishing AWS IoT Greengrass Component)
├── tools
│   ├── dynamodb (Script to register device info to Amazon DynamoDB)
│   └── secrets-manager (Script to register secrets to Secrets Manager)
├── .gitignore
├── .npmignore
├── LICENSE
├── README.md (This document)
├── cdk.json (CDK configuration)
├── jest.config.js (Test configuration)
├── package-lock.json (Related package info)
├── package.json (elated package inf)
└── tsconfig.json (TypeScript configuration)

Prerequisites

Operating System

These deployment instructions are intended for use on MacOS. Deployment using a different operating system may require additional steps.

Third-Party Tools

This project utilizes external APIs (e.g., OpenWeatherMap, SwitchBot, etc.) and hardware devices. When using these services, please adhere to their respective terms of service. This project is not responsible for any issues arising from the use of these external services.

Software

The following packages will need to be installed on your environment to deploy and run sample code provided in this guidance:

Hardware

You need the following hardware - or equivalent alternative - to enjoy the full set of capabilities in this repository. If you want to use different hardware, additional or modification of steps may be required.

AWS Account Requirements

IAM users must have permissions to deploy the stack using AWS CDK. Refer to this documentation on how to assign AWS Cloudformation permissions to learn which actions need to be granted for deploying infrastructure.

Users will also need permission to deploy the following resources used in this guidance:

Example Resources:

  • Amazon DynamoDB
  • Amazon S3
  • AWS Lambda
  • AWS IoT
  • Amazon Timestream
  • AWS Secrets Manager
  • AWS CodeBuild
  • Amazon SNS
  • AWS IAM
  • AWS IAM Identity Center
  • Access to a Region that supports this deployment [Default: US West 2 (Oregon)]
  • Amazon Managed Grafana

AWS CDK Bootstrap

This section provides the steps required to configure your environment before deploying the infrastructure using AWS CDK. These steps include:

  1. Cloning the repository for this guidance
  2. Installing node dependencies
  3. Configure AWS IAM credentials
  4. Bootstrap CDK

1. Cloning the repository for this guidance

git clone https://github.com/aws-solutions-library-samples/guidance-for-smart-and-sustainable-buildings-on-aws.git

2. Installing node dependencies

npm ci

3. Configure AWS IAM credentials with specific permission If this is your first time setting up AWS IAM credentials for using AWS CDK, refer Getting started with the AWS CDK to learn more.

export AWS_ACCESS_KEY_ID=<insert your access key>
export AWS_SECRET_ACCESS_KEY=<insert secret access key>
export AWS_SESSION_TOKEN=<insert session token>

4. Set AWS Region to deploy resources

  • Set your AWS Region to deploy resources using the command below. This example sets AWS Region to Oregon (us-west-2)
export AWS_REGION=us-west-2
...
      "publish": {
        "bucket": "gdk-components",
        "region": "{aws_region}"
      }
...

Deployment Steps

There are 6 steps to deploy the sample code for the guidance:

1. Install Python dependencies for the AWS Lambda layers 2. Deploy the infrastructure with AWS CDK 3. Register device information into Amazon DynamoDB 4. Register secrets into AWS Secret Manager 5. Configure device 6. Setup Amazon Managed Grafana Dashboard

1. Install dependencies for the AWS Lambda

chmod +x tools/install.sh
./tools/install.sh

2. Deploy the infrastructure with AWS CDK

Run the commands below at the root directory of the repository.

npm ci

If this is your first time using the CDK in your AWS account, you need to Bootstrap once. You don't need to run the command below if your account is already CDK bootstrapped.

cdk bootstrap

Next run command below to deploy AWS resources. It may take a while.

cdk deploy --all

Note the output for the resource ID. You will need this in subsequent steps. Example output are following.

 ✅  SustainableBuilding

✨  Deployment time: 53.85s

SustainableBuilding.DatastorelocationTable0A158CD4 = SustainableBuilding-DatastorelocationB25ECCC2-1F13H7MQ5JGUT
SustainableBuilding.PowerDataCollectionswitchBotApiSecretName96638740 = PowerDataCollectionswitchBo-p8emQ8cnT8SV
SustainableBuilding.WeatherDataCollectionOpenWeatherMapApiSecretNameCC86E358 = WeatherDataCollectionOpenWe-c1gS1OBWCXo8
...
 ✅  GreengrassStack

✨  Deployment time: 87.13s

Outputs:
GreengrassStack.AutomateVentilationComponentName = automateVentilation
GreengrassStack.AutomateVentilationComponentVersion = 1.0.0
GreengrassStack.SensingDevice1GreengrassInstallCommandforLinuxCD1E1E30 = sudo -E java "-Droot=/greengrass/v2" "-Dlog.store=FILE"  -jar ./GreengrassInstaller/lib/Greengrass.jar --aws-region us-west-2  --thing-name SensingDevice1 --thing-policy-name SensingDevice1ThingPolicy --tes-role-name  GreengrassStack-SensingDevice1GreengrassTESRole5551-5P3cYy7LMKix --tes-role-alias-name GreengrassStack-SensingDevice1GreengrassTESRole5551-5P3cYy7LMKixAlias --component-default-user ggc_user:ggc_group --provision true --setup-system-service true --deploy-dev-tools true
GreengrassStack.SensingDevice2GreengrassInstallCommandforLinuxB03CE7B0 = sudo -E java "-Droot=/greengrass/v2" "-Dlog.store=FILE"  -jar ./GreengrassInstaller/lib/Greengrass.jar --aws-region us-west-2  --thing-name SensingDevice2 --thing-policy-name SensingDevice2ThingPolicy --tes-role-name  GreengrassStack-SensingDevice2GreengrassTESRole9F2A-fvugXegtX4Bx --tes-role-alias-name GreengrassStack-SensingDevice2GreengrassTESRole9F2A-fvugXegtX4BxAlias --component-default-user ggc_user:ggc_group --provision true --setup-system-service true --deploy-dev-tools true
GreengrassStack.sensorDataCollectionComponentName = collectSensorData
GreengrassStack.sensorDataCollectionComponentVersion = 1.0.0

3. Register device information into Amazon DynamoDB

Run the command below after followings changes.

bash tools/dynamodb/add_location.sh {locationTable}

4. Register secrets into AWS Secret Manager

4.1 OpenWeather API Key

Run the command below after making the following changes.

  • Replace {secretid} with the output value of ustainableBuilding.WeatherDataCollectionOpenWeatherMapApiSecretName~ after running cdk deploy --all.
  • Replace {apikey} with the OpenWeather Map API Key obtained at Prerequisite - Hardware.
bash tools/secrets-manager/register-openweathermap-secret.sh {secretid} {apikey}

4.2 SwitchBot API Token

Run the command below after making the following changes.

  • Replace {secretid} with the output value of SustainableBuilding.PowerDataCollectionswitchBotApiSecretName~ after running cdk deploy --all.
  • Replace {apikey} with the SwitchBot API Token obtained at Prerequisite - Hardware.
bash tools/secrets-manager/register-openweathermap-secret.sh {secretid} {apikey}

5. Configure device

Set up the AWS IoT Greengrass device by referencing DEVICE_SETUP.

6. Setup Amazon Managed Grafana Dashboard

If you follow the previous steps, you will have data coming into Amazon Timestream. Let's build a Amazon Managed Grafana dashboard to visualize near realtime data stored in the Amazon Timestream database.

Refer Learn how to create and use Amazon Managed Grafana resources for how to setup Amazon Managed Grafana resources.

Following is an example steps for setting up the resources and create sample dashboard. Run these steps after logging in AWS Management Console.

  1. Log in to the AWS Management Console and select the region in which you deployed the CDK resources.

  2. Setup IAM Identity Center for managing users that can access to Amazon Managed Grafana.

  3. Add user to IAM Identity Center.

  4. Create Amazon Managed Grafana Workspace. Following is the example configuration screenshots.

    Configure Grafana version to 10.4. Alt text Enable AWS IAM Identity Center as authentication method Alt text

    Check "Turn plugin management" Alt text

  5. Configure Amazon Timestream as a data source.

    Alt text Alt text

  6. Add an IAM Identity Center user to the workspace with appropriate role (Admin, Viewer) Click "Assign new user or group" Alt text Alt text

  7. Access the Workspace URL to login with the IAM Identity Center user.

  8. Configure Amazon Managed Grafana to set Amazon Timestream DB as data source. From side bar, go to Apps -> AWS Data Sources -> Data sources

    Alt text In AWS services tab, click "Install now" on Timestream.

    Alt text Click Install [version] button in upper right corner. Alt text

    Click Add new data source on upper right corner. Alt text Configure Default Region and click Save & Test. Alt text

  9. Import JSON File to create a dashboard from the template (EN, JP).

    Alt text

    You should see dashboard similar to below image. Alt test

Deployment Validation

Deployment Validation - IoT Data Collection

  • Ensure the metrics (e.g., energy usage, CO2 ppm, temperature and weather data) are in the Amazon Managed Grafana dashboard. See below:

Alt test

Deployment Validation - IoT Device Shadow

  • Ensure the IoT Things Device Shadow is updated when CO2 ppm is above the threshold (default 800 ppm) and ventilate the building door by rotating servo.

Running the Guidance

Everything should run automatically after the deployment completes. You can now monitor the Amazon Managed Grafana dashboard and see how you can optimize energy, cost and associated GHG emission by optimizing operation.

Next Steps

This example implementation of the guidance provides a base for collecting, visualizing and automate operation to gain insights to optimize energy usage from multiple buildings. You can modify this sample to be tailored to your environment. This may include the following:

  • Customize and increase edge devices and components to collect from other sources such as Building Management Systems, smart meters, etc.
  • Use Amazon Athena and Amazon QuickSight to perform historical data analysis and create reports.
  • Create digital twins with AWS IoT TwinMaker to visualize and monitor physical asset status.

Cleanup

To cleanup, delete the following stacks in this order:

  1. Amazon Managed Grafana resources
  2. AWS IAM Identity Center
  3. CDK Resources To delete the resources created by AWS CDK, run the following command to delete stacks.
cdk destroy --all

FAQ

Notices

Customers are responsible for making their own independent assessment of the information in this Guidance. This Guidance: (a) is for informational purposes only, (b) represents AWS current product offerings and practices, which are subject to change without notice, and (c) does not create any commitments or assurances from AWS and its affiliates, suppliers or licensors. AWS products or services are provided “as is” without warranties, representations, or conditions of any kind, whether express or implied. AWS responsibilities and liabilities to its customers are controlled by AWS agreements, and this Guidance is not part of, nor does it modify, any agreement between AWS and its customers.

Authors

This project is built and maintained by Kenta Sato.

About

This Guidance demonstrates how to integrate building systems, assets, and sensors to enable real-time and historical insights for sustainable building management.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published