Calculating energy (in)dependence

One of the goals of building a digital twin of our house is to reduce our dependence on external energy sources. To achieve this goal, and to validate if my measures are having a positive effect, I need to compute our dependence on external energy sources. Our house will be fully electric, so that makes things a bit easier as I don’t have to take gas into account.

Basically, we will have two sources of energy (the grid and the PV (solar) panels) and one consumer: the house itself, including all the appliances consuming energy.

Energy situation of our future house.

External energy, in this context, is energy consumed from the grid. I calculate the total amount of energy we consume using:

total_consumption = pv_production + grid_consumption - pv_overproduction

When the PV panels are not producing energy, there will not be any overproduction, and the total_consumption will be equal to the grid_consumption. When there is no grid_consumption and the PV panels are producing sufficient energy to meet the demand, the total_consumption is equal to the pv_production minus the pv_overproduction.

I’m interested in our dependence from the grid. This is then an easy next step:

dependence = grid_consumption / total_consumption

This gives me a number that gives me the amount of energy consumed from the grid related to the total consumption. Initially, I will calculate our dependence based on 30 minute intervals.

The good news is that I already have the data, but it’s spread over multiple time-series. I’m building a small service that consumes the required data from the time-series, computes the dependence, and writes it back into a new time-series for historic analysis.

Grafana showing pv_overproduction (green) and grid_consumption(yellow).

Installing .NET 6 on a Raspberry PI (Debian)

Create a folder, for example /app/dotnet6, and assign ownership to the right user:

sudo mkdir /app/dotnet6
sudo chown -R pi /app/

Download the .NET 6 SDK at Microsoft:


Extract the tar.gz file in the /app/dotnet6 directory:

sudo tar zxf dotnet-sdk-6.0.100-linux-arm64.tar.gz -C /app/dotnet6

Test the .NET6 installation by browsing to the installation directory and execute the dotnet –info command:

cd /app/dotnet6
./dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.101
 Commit:    d05174dc5a

Runtime Environment:
 OS Name:     debian
 OS Version:  10
 OS Platform: Linux
 RID:         debian.10-arm64
 Base Path:   /app/dotnet/sdk/5.0.101/

Host (useful for support):
  Version: 5.0.1
  Commit:  b02e13abab

.NET SDKs installed:
  5.0.101 [/app/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.1 [/app/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.1 [/app/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs:

Automatically push .NET libraries on NuGet

Getting the source code of my home automation project on Github was a first step. Now, I’m ready to post some components on NuGet as well. This makes it easier to manage the packages and reduces the dependencies between my Visual Studio projects.

I ran into a challenge though: how could I easily upload my projects to NuGet without having to use the command line? Luckily, Visual Studio has something called Post-build event command line.

Post-build event command line; you can find this in the properties / build events tab of your project.

The command put into this block is executed after finishing the build. The only thing you need to do manually is change the package version, otherwise NuGet will rightfully decline the push (the version already exists).

You need to manually update the package version for NuGet to accept the push.

Depending on your directory and project structure you should be able to get the command below up and running. You can easily test this in the Command Prompt, just make sure you browse to the right target directory.

cd bin\Debug && dotnet nuget push *.nupkg -k xxx -s --skip-duplicate

Of course, you should replace the xxx with the NuGet API key.

Publishing an existing .NET (Core) project to Github

I started working on my home automation project in 2020. I started with a simple backup script that copies the source code to a second hard drive, just in case the primary hard drive fails. When my code base started to grow I extended the script to create a (daily) second copy on OneDrive. From a backup perspective this is working fine, but it does not give me versioning and source control. Luckily, Github exists. Microsoft developed a Github extension for Visual Studio.

Make sure you update your Visual Studio installation before you install the extension. Additionally you need a Github account. After that, publishing an existing project to Github is pretty straightforward. Open the project, click File, Add to Source Control, and Visual Studio will offer you to create a new Github repository.

Add to Source Control in the File menu.

Login to your Github account, and fine a suitable name for your project.

Visual studio will offer you to create a Github repository.

Once you have published the project on Github you need to maintain it. There are three steps required to upload changes to the Github repository:

  1. Pull: pulls the latest version of the repository to the local development machine.
  2. Commit: commits the code changes to a “snapshot” of your project.
  3. Push: pushes the latest snapshot of your project to the repository.