Current For Carbon

A Grid Game Agent

Posted by dave on March 12, 2024

CurrentForCarbon is a "grid game" application designed to aid the sustainable power grid by incentivizing players to adjust their power usage during times of grid stress. The game is built using the C2Agent Services Toolkit.

A C2Agent runs as a Windows Service in a home personal computer. When activated and started, the C2Agent waits for a game to begin. When the C2Agent detects a game event, the game player receives a text message. During the game, the player, with help from home automation, reduces power in the home by turning off appliances and adjusting the thermostat. After the game finishes, the C2Agent retrieves the players home power data, calculates results and stores the results in an Ethereum Smart Contract.

The CurrentForCarbon proof-of-concept utilizes several cloud services. These services include:

MQTT: A light-weight, publish-subscribe messaging bus used for distributing event notifications
	Provider - HiveMQ MQTT (
Internet of Things Historian: Data storage for home power data
	Provider - Mathworks Thingspeak (
Blockchain Ledger: Ethereum smart contracts used for storing game events and results
	Provider - EnergyWeb Volta/EWC (
Texting: Used for player notifications
	Provider- TextMagic (
Game Scheduler: Used to analyze grid market data and determine when to play a game
	Provider - OpenAI AIAgent Toolkit with ChatGPT-4

Game Guide

Game Incentives

The proof-of-concept has been tested to 100,000 game event results per smart contact. With 50 game events per year, each smart contract can support 100,000/50=2000 homes/players. Smart contracts run on Ethereum-compatible blockchains and can be created as needed.

If 2000 players played 50 games and saved 500 watts each during high cost peaks, 1,000,000 watts of demand could be saved per smart contract. These price peaks can often exceed $100 per megawatt hour. Does this represent sufficient value for the grid to incentivize players to participate? It seems to me that it does...

C2Agent Services Toolkit

C2Agent is a simple software framework built on Microsoft .NET that allows for rapid prototyping of integration projects that require flexibility and extensibility. Agents are written in C# and run as Windows Services on Windows 10/11 PCs.

A software framework provides a structure that makes it easier to write, debug and maintain code. The framework provides common functions such as logging and configuration services along with a common way of organizing software components.

Why C#?

C# is a compiled language developed by Microsoft and built on .NET, a managed virtual machine.

Some benefits of C# include: • Long term Microsoft support • Excellent development tools • Availability of mature open source libraries • Native support for Windows • Support for wide range of non-windows platforms

The main reasons I chose C# were; 1) Visual Studio 2022 tools make programming and debugging easy, 2) strong long-term support from Microsoft and 3) I was already familiar with C, C++ and Java.

Why Windows?

Windows personal computers (PC) are popular, widely used and come in all shapes and sizes. When an agent needs to run continually in a home, PCs are an effective and inexpensive platform choice.

Why Windows Services?

The Windows Service was designed as a standard operating system component to run embedded applications. Services become part of the Windows operating system, much like daemons in a Linux system.

When activated and started, the Service runs the AgentObject every few seconds. The AgentObject orchestrates execution with Init, Start, Fire, and Stop methods. Assistants are modules that are called from the Agent Object and delegate work to Worker modules. The AgentObject has attributes that can be read and written by Assistants. This is a generic structure that mirrors organizations of all types and has proven to be flexible. Note that the code uses a composition style versus an inheritance style. Object inheritance hierarchies are best left to production code when requirements and scope have matured.


C2Agent Toolkit -

Smart Contracts -

AIAgent Toolkit -

A Little History

The original design was for a "Colony" that consisted of multiple Windows Services, with each Service running multiple AgentObjects. The Colony would provide a set of common services for the AgentObjects. This design was too tightly coupled and subsequently reduced to each Visual Studio 2022 solution consisting of one Service running one AgentObject. The solution can be cloned to create multiple Services each running one AgentObject. Threads can be spun as required for enhanced concurrency.

Please bear in mind that the code is my playground and still a work-in-progress after all these years…

Dave Hardin