https://github.com/lazauk/sustainability-homeenergy
Open Source solution to measure the energy consumption at home for a hybrid-work environment. Data is accumulated and visualised in Azure cloud environment.
https://github.com/lazauk/sustainability-homeenergy
consumption-analytics energy sustainability
Last synced: 3 months ago
JSON representation
Open Source solution to measure the energy consumption at home for a hybrid-work environment. Data is accumulated and visualised in Azure cloud environment.
- Host: GitHub
- URL: https://github.com/lazauk/sustainability-homeenergy
- Owner: LazaUK
- Created: 2021-07-15T19:37:54.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-17T20:36:38.000Z (over 3 years ago)
- Last Synced: 2025-01-12T05:11:08.346Z (4 months ago)
- Topics: consumption-analytics, energy, sustainability
- Language: Python
- Homepage:
- Size: 1.72 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Sustainability Hack - Measuring energy consumption at home
This is my contribution to the open source project, based on the original idea from my Microsoft colleagues Anurag Peshne and Chris Templeman to measure *energy consumption from home for the work-related activities*.
> **Note:** This solution has been built and tested in Python 3.8.## Pre-requisites
For this tutorial, you would need the following hardware and software components:
- Kasa Smart Wi-Fi Strip or Plug. See the [TP-Link Web site](https://www.tp-link.com/uk/home-networking/smart-plug/hs100) for available models that support *Energy Monitoring*. For testing purposes, I'm using Kasa Mini Smart Plug (**KP115**);
- Computer with the Internet connectivity and pre-installed Python 3.x;
- Azure subscription to provision backend cloud resources.## Step 0 - Client Setup
1. Download content of this repo;
2. Install python-kasa library, either by using pip command as shown below or manually as described on this [PyPi](https://pypi.org/project/python-kasa/) Web page:
```
pip install python-kasa
```
3. Install Azure IoT Device SDK for Python as described on this [PyPi](https://pypi.org/project/azure-iot-device/) Web page:
```
pip install azure-iot-device
```## Step 1 - Azure IoT Hub configuration
1. Deploy Azure IoT Hub resource in your Azure subscription;
2. In Azure IoT Hub, add new IoT device corresponding to your SmartPlug using "Add Device" under Explorers -> IoT devices:

3. Open newly created IoT device record and copy one of its connection strings (either primary or secondary:

4. Open downloaded DemoKasa.py file and update the value of the CONNECTION_STRING variable with the copied connection string from the previous action above:
## Step 2 - Azure SQL configuration
1. Deploy Azure SQL database in your Azure subscription;
2. Create a table in the newly-deployed Azure SQL database, using the following SQL script, so that you can store there your Smart Plug's daily and monthly stats:
```
CREATE TABLE [dbo].[energydata](
[id] [int] IDENTITY(1, 1) NOT NULL,
[teledate] [varchar](10) NULL,
[monthly_stats] [nvarchar](max) NULL,
[yearly_stats] [nvarchar](max) NULL
)
```## Step 3 - Azure Stream Analytics configuration
1. Deploy Azure Stream Analytics job resource in your Azure subscription;
2. Add Azure IoT Hub from Step 1 above as a stream input for your Azure Stream Analytics job:

3. Add PowerBI as a real-time telemetry output from your Azure Stream Analytics job:

4. Add Azure SQL as a historical data output from your Azure Stream Analytics job:

5. Create a new query in Stream Analytics that can analyse input from IoT Hub and redirect specific values to PowerBI and Azure SQL DB based on the values of telemetryContent custom property:
```
WITH data AS
(
SELECT
*,
GetMetadataPropertyValue(MyIotHub, '[User].[telemetryContent]') AS telemetryContent
FROM MyIoTHub
)SELECT
current_ma, voltage_mv, power_mw, total_wh, EventProcessedUtcTime as time
INTO
MyBIRT
FROM data
WHERE
telemetryContent = 'RealTime_Telemetry'SELECT
teledate, monthly_stats, yearly_stats
INTO
MySQLDB
FROM data
WHERE
telemetryContent = 'Monthly_Stats'
```
6. Activate your Azure Stream Analytics job.## Step 4 - Visualise content in PowerBI dashboard
Finally, you can visualise your Energy Metering data in PowerBI. Below is an example of a PowerBI dashboard with the real-time telemetry and historical stats.
