Skip to content

This application monitors and manages energy consumption across devices, rooms, offices, and companies using MQTT for real-time data updates. It subscribes to energy topics, processes incoming data, and publishes aggregated energy metrics.

Notifications You must be signed in to change notification settings

CorefluxCommunity/Coreflux-Energy_Monitoring_System

Repository files navigation

Coreflux - Energy Monitoring System

Overview

This project is an Energy Consumption Monitoring System that aggregates and reports energy usage data from various devices within a company. The system is built using C# and relies on MQTT for communication. It processes energy data from Shelly devices and provides aggregated results at the device, room, office, and company levels.

Features

  • Real-Time Data Collection: Collects energy consumption data from Shelly devices in real-time using Coreflux MQTT.

  • Hierarchical Aggregation: Aggregates energy data at different levels: devices, rooms, offices, and the entire company.

  • Configurable and Automatic Topic Subscription: Uses a TOML configuration file to set up initial MQTT topics. Automatically subscribes to MQTT topics for new devices, rooms, and offices as they are discovered.

  • Detailed Logging: Logs detailed information about energy consumption for each device, room, office, and the entire company in order to ensure that everything is being sent to the right locations.

Project WorkFlow

graph TD
    Shellys((Shellys)) --> |Publishes to| BrokerPublic((Broker Public));
    BrokerPublic --> |Bridges to| MQTTBridge[/"MQTT Bridge Asset"\];
    MQTTBridge --> BrokerDroplet((Broker Droplet));
    AggregatorService((Aggregator Service Droplet)) <--> |Calculates energy consumption| BrokerDroplet;
    BrokerDroplet <--> |Receive and send| AutomatismService((Automatism Service Droplet));
    BrokerDroplet --> MariaDBAsset[/"MariaDB Asset"\];
    MariaDBAsset --> MariaDBDroplet((MariaDB Droplet));
    MariaDBDroplet --> Grafana[/Grafana\];

    style BrokerDroplet fill:#f9f,stroke:#333,stroke-width:2px;
    style MQTTBridge fill:#ccf,stroke:#333,stroke-width:2px;
    style MariaDBAsset fill:#ccf,stroke:#333,stroke-width:2px;
Loading

Getting Started

Prerequisites

  • .NET SDK 8.0
  • Shelly devices properly configured and connected to the MQTT broker
  • Coreflux MQTT broker

Installation

  1. Clone the repository:
git clone [email protected]:CorefluxCommunity/Coreflux-Energy_Monitoring_System.git
cd Coreflux-Energy_Monitoring_System
  1. Build the project:
dotnet build
  1. Run the project
dotnet run

Configuration

The system is configured using a TOML file named config.toml. This file should contain the MQTT topic information for the company's energy data. Below is an example configuration:

[company]
topic = "Coreflux/#"

Project Structure

  • Worker: The core service that runs continuously, processing incoming MQTT messages and updating energy consumption data.

  • Company, Office, Room, Device: Classes representing the hierarchy of the organization, each segment with its own energy consumption data.

  • DeviceDetails: Class representing the detailed energy data reported by each Shelly device.

Data Processing

  • Device Level: Each device reports its energy data, which is processed and stored.

  • Room Level: The energy data from all devices in a room is aggregated to provide room-level consumption.

  • Office Level: The energy data from all rooms in an office is aggregated to provide office-level consumption.

  • Company Level: The energy data from all offices is aggregated to provide company-level consumption.

Usage

The system will automatically subscribe to the MQTT topics specified in the configuration file and start collecting energy data from Shelly devices. The collected data will be aggregated and logged at regular intervals.

Using MQTT Explorer will help visualise the publication of each message, showing the energy spent on each topic segment.

Data Flow Diagram

graph TD;
    A[Arrival of new MQTT Payload] --> B{Parse the topic. Is it valid?};
    B -- Yes --> C[Parse Data];
    B -- No --> D[Wait for a valid message];
    C --> E{Device already created?};
    E -- Yes --> F[Calculate energy difference] --> H[Save new data];
    E -- No --> G[Create a new instance of that device and save a reference value] --> H[Save new data];
    H --> I[Wait 10 seconds] --> J[Publish data to the right topic segment] --> K[Wait for a new MQTT Payload] --> A;
   
Loading

Extra Service (Automation)

This service named AutomatismWorker ensures that all lighting devices connected via Shelly devices are turned off during a specified time period.
The service continuously monitors the state of these devices and automatically turns off any that are found to be on within the specified timeframe.

When a light is turned on during the monitoring period, the service will automatically publish a message to the topic to turn off the light.
For example, if the topic for a device is Coreflux/Porto/MeetingRoom/Light1/status, the service will publish an "off" command to Coreflux/Porto/MeetingRoom/Light1/command/switch:0.

About

This application monitors and manages energy consumption across devices, rooms, offices, and companies using MQTT for real-time data updates. It subscribes to energy topics, processes incoming data, and publishes aggregated energy metrics.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •