Smdn.Net.SmartMeter
2.0.0
Prefix Reserved
dotnet add package Smdn.Net.SmartMeter --version 2.0.0
NuGet\Install-Package Smdn.Net.SmartMeter -Version 2.0.0
<PackageReference Include="Smdn.Net.SmartMeter" Version="2.0.0" />
paket add Smdn.Net.SmartMeter --version 2.0.0
#r "nuget: Smdn.Net.SmartMeter, 2.0.0"
// Install Smdn.Net.SmartMeter as a Cake Addin #addin nuget:?package=Smdn.Net.SmartMeter&version=2.0.0 // Install Smdn.Net.SmartMeter as a Cake Tool #tool nuget:?package=Smdn.Net.SmartMeter&version=2.0.0
Smdn.Net.SmartMeter 2.0.0
Provides a class SmartMeterDataAggregator
, which implements the HEMS Controller that periodically collects the data from the low-voltage smart electric energy meter via the route-B.
「Bルート」を介して「低圧スマート電力量メータ」から定期的なデータ収集を行う「HEMS コントローラ」の実装であるクラスSmartMeterDataAggregator
を提供します。
Usage
This is an example that implements a BackgroundService
that periodically reads and displays the data from the smart meter.
以下のコードでは、スマートメーターから定期的にデータを読み出し、表示するBackgroundService
を実装します。
// SPDX-FileCopyrightText: 2024 smdn <smdn@smdn.jp>
// SPDX-License-Identifier: MIT
using Microsoft.Extensions.Hosting;
using Smdn.Net.SmartMeter;
/// <summary>
/// スマートメーターに接続して定期的なデータ収集を行う<see cref="BackgroundService"/>を実装します。
/// </summary>
public class SmartMeterAggregationService : BackgroundService {
private readonly IServiceProvider serviceProvider;
public SmartMeterAggregationService(IServiceProvider serviceProvider)
{
ArgumentNullException.ThrowIfNull(serviceProvider);
this.serviceProvider = serviceProvider;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
// 月曜日を週の始まりとして、週間での積算電力量(正方向のみ)を収集します
var weeklyUsage = new WeeklyCumulativeElectricEnergyAggregation(
aggregateNormalDirection: true,
aggregateReverseDirection: false,
firstDayOfWeek: DayOfWeek.Monday
);
// 瞬時電力を15秒おきに収集します
var electricPower = new InstantaneousElectricPowerAggregation(
aggregationInterval: TimeSpan.FromSeconds(15)
);
// 値が取得されたら、その値を標準出力に表示します
weeklyUsage.PropertyChanged += (sender, e) => {
if (e.PropertyName == nameof(weeklyUsage.NormalDirectionValueInKiloWattHours))
Console.WriteLine($"{weeklyUsage.NormalDirectionValueInKiloWattHours} [kWh] ({weeklyUsage.StartOfMeasurementPeriod:s} ~ {DateTime.Now:s})");
};
electricPower.PropertyChanged += (sender, e) => {
if (e.PropertyName == nameof(electricPower.LatestValue))
Console.WriteLine($"{electricPower.LatestValue} [W] ({DateTime.Now:s})");
};
// 上記2つのデータを収集するSmartMeterDataAggregatorを作成します
using var dataAggregator = new SmartMeterDataAggregator(
dataAggregations: [weeklyUsage, electricPower],
serviceProvider: serviceProvider
);
// スマートメーターに接続し、データ収集を開始します
// データ収集は、バックグラウンドで動作するタスクにて行われます
await dataAggregator.StartAsync(stoppingToken);
// stoppingTokenによる停止要求があるまで、無限に待機します
await Task
.Delay(Timeout.Infinite, stoppingToken)
.ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing);
// データ収集を停止し、スマートメーターから切断します
await dataAggregator.StopAsync(CancellationToken.None);
}
}
The entire code is available on the GitHub repository.
完全なコードはGitHubリポジトリを参照してください。
Contributing
This project welcomes contributions, feedbacks and suggestions. You can contribute to this project by submitting Issues or Pull Requests on the GitHub repository.
API List
List of APIs exposed by assembly Smdn.Net.SmartMeter-2.0.0
(net8.0)
// Smdn.Net.SmartMeter.dll (Smdn.Net.SmartMeter-2.0.0)
// Name: Smdn.Net.SmartMeter
// AssemblyVersion: 2.0.0.0
// InformationalVersion: 2.0.0+1702d101b7d7da969b9b6258406b4aea5a1b98b4
// TargetFramework: .NETCoreApp,Version=v8.0
// Configuration: Release
// Referenced assemblies:
// Microsoft.Extensions.DependencyInjection.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
// Microsoft.Extensions.Logging.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
// Polly.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=c8a3ffc3f8f825cc
// Smdn.Net.EchonetLite, Version=2.0.0.0, Culture=neutral
// Smdn.Net.EchonetLite.RouteB, Version=2.0.0.0, Culture=neutral
// Smdn.Net.EchonetLite.RouteB.Primitives, Version=2.0.0.0, Culture=neutral
// System.Collections, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.ComponentModel, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.ComponentModel.Primitives, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Linq, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.ObjectModel, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// System.Threading, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
#nullable enable annotations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Polly.Registry;
using Smdn.Net.EchonetLite.RouteB;
using Smdn.Net.EchonetLite.RouteB.Credentials;
using Smdn.Net.EchonetLite.RouteB.Transport;
using Smdn.Net.SmartMeter;
namespace Smdn.Net.SmartMeter {
public sealed class CumulativeElectricEnergyAggregation : PeriodicCumulativeElectricEnergyAggregation {
public CumulativeElectricEnergyAggregation(bool aggregateNormalDirection, bool aggregateReverseDirection) {}
public override TimeSpan DurationOfMeasurementPeriod { get; }
public override DateTime StartOfMeasurementPeriod { get; }
protected override bool TryGetBaselineValue(bool normalOrReverseDirection, out MeasurementValue<ElectricEnergyValue> @value) {}
}
public sealed class DailyCumulativeElectricEnergyAggregation : PeriodicCumulativeElectricEnergyAggregation {
public DailyCumulativeElectricEnergyAggregation(bool aggregateNormalDirection, bool aggregateReverseDirection) {}
public override TimeSpan DurationOfMeasurementPeriod { get; }
public override DateTime StartOfMeasurementPeriod { get; }
}
[TupleElementNames(new string[] { "RPhase", "TPhase" })]
public class InstantaneousCurrentAggregation : MeasurementValueAggregation<(ElectricCurrentValue, ElectricCurrentValue)> {
public static readonly TimeSpan DefaultAggregationInterval; // = "00:01:00"
public InstantaneousCurrentAggregation() {}
public InstantaneousCurrentAggregation(TimeSpan aggregationInterval) {}
}
public class InstantaneousElectricPowerAggregation : MeasurementValueAggregation<int> {
public static readonly TimeSpan DefaultAggregationInterval; // = "00:01:00"
public InstantaneousElectricPowerAggregation() {}
public InstantaneousElectricPowerAggregation(TimeSpan aggregationInterval) {}
}
public abstract class MeasurementValueAggregation<TMeasurementValue> : SmartMeterDataAggregation {
public TimeSpan AggregationInterval { get; }
public DateTime LatestMeasurementTime { get; }
public TMeasurementValue LatestValue { get; }
internal protected virtual void OnLatestValueUpdated() {}
}
public sealed class MonthlyCumulativeElectricEnergyAggregation : PeriodicCumulativeElectricEnergyAggregation {
public MonthlyCumulativeElectricEnergyAggregation(bool aggregateNormalDirection, bool aggregateReverseDirection) {}
public override TimeSpan DurationOfMeasurementPeriod { get; }
public override DateTime StartOfMeasurementPeriod { get; }
}
public abstract class PeriodicCumulativeElectricEnergyAggregation : SmartMeterDataAggregation {
protected PeriodicCumulativeElectricEnergyAggregation(bool aggregateNormalDirection, bool aggregateReverseDirection) {}
public bool AggregateNormalDirection { get; }
public bool AggregateReverseDirection { get; }
public abstract TimeSpan DurationOfMeasurementPeriod { get; }
public decimal NormalDirectionValueInKiloWattHours { get; }
public decimal ReverseDirectionValueInKiloWattHours { get; }
public abstract DateTime StartOfMeasurementPeriod { get; }
protected virtual void OnNormalDirectionBaselineValueUpdated() {}
internal protected virtual void OnNormalDirectionLatestValueUpdated() {}
protected virtual void OnNormalDirectionValueChanged() {}
protected virtual void OnReverseDirectionBaselineValueUpdated() {}
internal protected virtual void OnReverseDirectionLatestValueUpdated() {}
protected virtual void OnReverseDirectionValueChanged() {}
protected virtual bool TryGetBaselineValue(bool normalOrReverseDirection, out MeasurementValue<ElectricEnergyValue> @value) {}
public virtual bool TryGetCumulativeValue(bool normalOrReverseDirection, out decimal valueInKiloWattHours, out DateTime measuredAt) {}
}
public abstract class SmartMeterDataAggregation : INotifyPropertyChanged {
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null) {}
}
public class SmartMeterDataAggregator : HemsController {
public static readonly string ResiliencePipelineKeyForAcquirePropertyValuesForAggregatingData = "SmartMeterDataAggregator.resiliencePipelineAcquirePropertyValuesForAggregatingData";
public static readonly string ResiliencePipelineKeyForRunAggregationTask = "SmartMeterDataAggregator.resiliencePipelineRunAggregationTask";
public static readonly string ResiliencePipelineKeyForSmartMeterConnection = "SmartMeterDataAggregator.resiliencePipelineConnectToSmartMeter";
public static readonly string ResiliencePipelineKeyForSmartMeterPropertyValueReadService = "SmartMeterDataAggregator.ResiliencePipelineReadSmartMeterPropertyValue";
public static readonly string ResiliencePipelineKeyForSmartMeterPropertyValueWriteService = "SmartMeterDataAggregator.ResiliencePipelineWriteSmartMeterPropertyValue";
public static readonly string ResiliencePipelineKeyForSmartMeterReconnection = "SmartMeterDataAggregator.resiliencePipelineReconnectToSmartMeter";
public static readonly string ResiliencePipelineKeyForUpdatePeriodicCumulativeElectricEnergyBaselineValue = "SmartMeterDataAggregator.resiliencePipelineUpdatePeriodicCumulativeElectricEnergyBaselineValue";
public SmartMeterDataAggregator(IEnumerable<SmartMeterDataAggregation> dataAggregations, IRouteBEchonetLiteHandlerFactory echonetLiteHandlerFactory, IRouteBCredentialProvider routeBCredentialProvider, ResiliencePipelineProvider<string>? resiliencePipelineProvider, ILogger? logger, ILoggerFactory? loggerFactoryForEchonetClient) {}
public SmartMeterDataAggregator(IEnumerable<SmartMeterDataAggregation> dataAggregations, IServiceProvider serviceProvider) {}
public IReadOnlyCollection<SmartMeterDataAggregation> DataAggregations { get; }
public bool IsRunning { get; }
protected override void Dispose(bool disposing) {}
protected virtual bool HandleAggregationTaskException(Exception exception) {}
public ValueTask StartAsync(CancellationToken cancellationToken = default) {}
public async ValueTask StartAsync(TaskFactory? aggregationTaskFactory, CancellationToken cancellationToken = default) {}
public async ValueTask StopAsync(CancellationToken cancellationToken) {}
}
public sealed class WeeklyCumulativeElectricEnergyAggregation : PeriodicCumulativeElectricEnergyAggregation {
public WeeklyCumulativeElectricEnergyAggregation(bool aggregateNormalDirection, bool aggregateReverseDirection, DayOfWeek firstDayOfWeek) {}
public override TimeSpan DurationOfMeasurementPeriod { get; }
public DayOfWeek FirstDayOfWeek { get; }
public override DateTime StartOfMeasurementPeriod { get; }
}
}
// API list generated by Smdn.Reflection.ReverseGenerating.ListApi.MSBuild.Tasks v1.5.0.0.
// Smdn.Reflection.ReverseGenerating.ListApi.Core v1.3.1.0 (https://github.com/smdn/Smdn.Reflection.ReverseGenerating)
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Smdn.Net.EchonetLite.RouteB (>= 2.0.0)
-
net8.0
- Smdn.Net.EchonetLite.RouteB (>= 2.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.0.0 | 55 | 1/11/2025 |