roblans / ZWave4Net

ZWave4Net is a .NET library that interfaces with the Aeotec / Aeon Labs Z-Stick.
MIT License
41 stars 34 forks source link

Can't get Active Power from a device #26

Closed r9r-dev closed 5 years ago

r9r-dev commented 5 years ago

Hi,

I am using a Single Switch from Fibaro (FGS-213). Datasheet available here : https://manuals.fibaro.com/content/manuals/en/FGS-2x3/FGS-2x3-EN-T-v1.0.pdf

According to page 12, you can get two types of values for power consumption.

When using Metter CommandClass, I can get Electric energy (in kWh) but I don't find how to get Electric active power value.

var controller = new ZWaveController("COM4");
controller.Open();
var nodes = await controller.GetNodes();
var node = nodes[(byte)2];
var meter = node.GetCommandClass<Meter>();
var meterGet = await meter.Get();

var value = meterGet.Value; // Something like 1,03
var unit = meterGet.Unit; // kWh

Are there other ways to get meter values from the Metter Command class ? Maybe a way to get other Meters from the same device ?

Thanks for your help.

roblans commented 5 years ago

Hi,

Try to get the power value by using the SensorMultiLevel class

var sensorMultiLevel = node.GetCommandClass<SensorMultiLevel>();
var powerValue = sensorMultiLevel.Get(SensorType.Power);
r9r-dev commented 5 years ago

Thanks for your help @roblans ! It fails unfortunately.

It look like this device does not support SensorMultiLevel class. It is supporting the command classes listed on this page : https://products.z-wavealliance.org/products/1873/classes

At first, I guessed it should be Powerlevel command class. I forked your repository and started to handle it but Powerlevel is about the powerlevel of the zwave signal, not the power consumption of the connected device.

It look like this information is hidden somewhere else but I don't get it.

r9r-dev commented 5 years ago

I tried the method GetSupported() from the Meter Command Class. It returns Electric as Type and an array with kWh and W as supported Units. It look like it should be possible to add a parameter to the Get of the meter value of the command class ?

var meter = node.GetCommandClass<Meter>();
var supported = await meter.GetSupported();
Console.WriteLine($"{supported.Type} - {string.Join(", ", supported.Units)}"); // Electric - kWh, W

var consumption = await meter.Get();
Console.WriteLine($"{consumption.Value} {consumption.Unit}"); // 3,02 kWh
roblans commented 5 years ago

Yes, you are right, I checked the Z-wave specification and there is an extra optional parameter which can be passed to the Get command. This parameter determines the type of metervalue to return.

I will fix this tomorrow.

Rob.

r9r-dev commented 5 years ago

That's really awesome. Thanks for sharing this library, it helps a lot :)

roblans commented 5 years ago

Done:

var meter = node.GetCommandClass<Meter>();
var value = await meter.Get(ElectricMeterScale.W);

New NuGet package (1.0.0.178) published.

r9r-dev commented 5 years ago

Working perfectly, thank you :)