Esempio n. 1
0
 public static EnergyValue Parse(byte[] message)
 {
     ZWaveValue zvalue = ZWaveValue.ExtractValueFromBytes(message, 4);
     EnergyValue energy = new EnergyValue();
     energy.Value = zvalue.Value;
     if (Enum.IsDefined(typeof(ZWaveEnergyScaleType), zvalue.Scale))
     {
         energy.Parameter = (ZWaveEnergyScaleType)zvalue.Scale;
     }
     switch (energy.Parameter)
     {
     // Accumulated power consumption kW/h
     case ZWaveEnergyScaleType.kWh:
         //energy.EventType = EventParameter.MeterKwHour;
         // TODO: The following is fix for AeonLabs HEM G2
         // TODO: https://github.com/genielabs/ZWaveLib/pull/186
         // TODO: possibly move this fix to ZWaveValue.ExtractValueFromBytes method
         if ((message[2] & 0x80) == 0x80)
             energy.EventType = EventParameter.MeterAcVolt;
         else
             energy.EventType = EventParameter.MeterKwHour;
         break;
     // Accumulated power consumption kilo Volt Ampere / hours (kVA/h)
     case ZWaveEnergyScaleType.kVAh:
         energy.EventType = EventParameter.MeterKvaHour;
         break;
     // Instant power consumption Watt
     case ZWaveEnergyScaleType.Watt:
         // TODO: The following is fix for Qubino Smart Meter
         // TODO: possibly move this fix to ZWaveValue.ExtractValueFromBytes method
         if ((message[2] & 0xA1) == 0xA1)
             energy.EventType = EventParameter.MeterPower;
         else
             energy.EventType = EventParameter.MeterWatt;
         break;
     // Pulses count
     case ZWaveEnergyScaleType.Pulses:
         energy.EventType = EventParameter.MeterPulses;
         break;
     // AC load Voltage
     case ZWaveEnergyScaleType.ACVolt:
         energy.EventType = EventParameter.MeterAcVolt;
         break;
     // AC load Current
     case ZWaveEnergyScaleType.ACCurrent:
         energy.EventType = EventParameter.MeterAcCurrent;
         break;
     // Power Factor
     case ZWaveEnergyScaleType.PowerFactor:
         energy.EventType = EventParameter.MeterPower;
         break;
     default:
         // Unknown value ?
         energy = null;
         break;
     }
     return energy;
 }
Esempio n. 2
0
        public static EnergyValue Parse(byte[] message)
        {
            ZWaveValue  zvalue = ZWaveValue.ExtractValueFromBytes(message, 11);
            EnergyValue energy = new EnergyValue();

            //energy.Value = ((double)int.Parse(
            //                       message[12].ToString("X2") + message[13].ToString("X2") + message[14].ToString("X2"),
            //                       System.Globalization.NumberStyles.HexNumber
            //                   )) / 1000D;
            energy.Value = zvalue.Value;
            if (Enum.IsDefined(typeof(ZWaveEnergyScaleType), zvalue.Scale))
            {
                energy.Parameter = (ZWaveEnergyScaleType)zvalue.Scale;
            }
            switch (energy.Parameter)
            {
            // Accumulated power consumption kW/h
            case ZWaveEnergyScaleType.kWh:
                energy.EventType = EventParameter.MeterKwHour;
                break;

            // Accumulated power consumption kilo Volt Ampere / hours (kVA/h)
            case ZWaveEnergyScaleType.kVAh:
                energy.EventType = EventParameter.MeterKvaHour;
                break;

            // Instant power consumption Watt
            case ZWaveEnergyScaleType.Watt:
                energy.EventType = EventParameter.MeterWatt;
                break;

            // Pulses count
            case ZWaveEnergyScaleType.Pulses:
                energy.EventType = EventParameter.MeterPulses;
                break;

            // AC load Voltage
            case ZWaveEnergyScaleType.ACVolt:
                energy.EventType = EventParameter.MeterAcVolt;
                break;

            // AC load Current
            case ZWaveEnergyScaleType.ACCurrent:
                energy.EventType = EventParameter.MeterAcCurrent;
                break;

            // Power Factor
            case ZWaveEnergyScaleType.PowerFactor:
                energy.EventType = EventParameter.MeterPower;
                break;

            default:
                energy.EventType = EventParameter.MeterWatt;
                break;
            }
            return(energy);
        }
Esempio n. 3
0
        public static SensorValue Parse(byte[] message)
        {
            SensorValue sensor = new SensorValue();
            //
            ZWaveValue zvalue = ZWaveValue.ExtractValueFromBytes(message, 11);
            //
            byte key = message[9];

            if (key == (byte)ZWaveSensorParameter.Temperature)
            {
                sensor.Parameter = ZWaveSensorParameter.Temperature;
                // convert from Fahrenheit to Celsius if needed
                sensor.Value     = (zvalue.Scale == (int)ZWaveTemperatureScaleType.Fahrenheit ? SensorValue.FahrenheitToCelsius(zvalue.Value) : zvalue.Value);
                sensor.EventType = EventParameter.SensorTemperature;
            }
            else if (key == (byte)ZWaveSensorParameter.GeneralPurposeValue)
            {
                sensor.Parameter = ZWaveSensorParameter.GeneralPurposeValue;
                sensor.Value     = zvalue.Value;
                sensor.EventType = EventParameter.Generic;
            }
            else if (key == (byte)ZWaveSensorParameter.Luminance)
            {
                sensor.Parameter = ZWaveSensorParameter.Luminance;
                sensor.Value     = zvalue.Value;
                sensor.EventType = EventParameter.SensorLuminance;
            }
            else if (key == (byte)ZWaveSensorParameter.RelativeHumidity)
            {
                sensor.Parameter = ZWaveSensorParameter.RelativeHumidity;
                sensor.Value     = zvalue.Value;
                sensor.EventType = EventParameter.SensorHumidity;
            }
            else if (key == (byte)ZWaveSensorParameter.Power)
            {
                //sensor.Value = BitConverter.ToUInt16(new byte[2] { message[12], message[11] }, 0) / 10D;
                //sensor.Value = ((double)int.Parse(
                //    message[12].ToString("X2") + message[13].ToString("X2") + message[14].ToString("X2"),
                //    System.Globalization.NumberStyles.HexNumber
                //    )) / 1000D;
                // TODO: this might be very buggy.... to be tested
                EnergyValue energy = EnergyValue.Parse(message);
                sensor.Parameter = ZWaveSensorParameter.Power;
                sensor.Value     = energy.Value;
                sensor.EventType = EventParameter.MeterPower;
            }
            else
            {
                sensor.Value = zvalue.Value;
            }
            //
            return(sensor);
        }
Esempio n. 4
0
 public static EnergyValue Parse(byte[] message)
 {
     ZWaveValue zvalue = ZWaveValue.ExtractValueFromBytes(message, 11);
     EnergyValue energy = new EnergyValue();
     //energy.Value = ((double)int.Parse(
     //                       message[12].ToString("X2") + message[13].ToString("X2") + message[14].ToString("X2"),
     //                       System.Globalization.NumberStyles.HexNumber
     //                   )) / 1000D;
     energy.Value = zvalue.Value;
     if (Enum.IsDefined(typeof(ZWaveEnergyScaleType), zvalue.Scale))
     {
         energy.Parameter = (ZWaveEnergyScaleType)zvalue.Scale;
     }
     switch (energy.Parameter)
     {
     // Accumulated power consumption kW/h
     case ZWaveEnergyScaleType.kWh:
         energy.EventType = EventParameter.MeterKwHour;
         break;
     // Accumulated power consumption kilo Volt Ampere / hours (kVA/h)
     case ZWaveEnergyScaleType.kVAh:
         energy.EventType = EventParameter.MeterKvaHour;
         break;
     // Instant power consumption Watt
     case ZWaveEnergyScaleType.Watt:
         energy.EventType = EventParameter.MeterWatt;
         break;
     // Pulses count
     case ZWaveEnergyScaleType.Pulses:
         energy.EventType = EventParameter.MeterPulses;
         break;
     // AC load Voltage
     case ZWaveEnergyScaleType.ACVolt:
         energy.EventType = EventParameter.MeterAcVolt;
         break;
     // AC load Current
     case ZWaveEnergyScaleType.ACCurrent:
         energy.EventType = EventParameter.MeterAcCurrent;
         break;
     // Power Factor
     case ZWaveEnergyScaleType.PowerFactor:
         energy.EventType = EventParameter.MeterPower;
         break;
     default:
         energy.EventType = EventParameter.MeterWatt;
         break;
     }
     return energy;
 }
        public static EnergyValue Parse(byte[] message)
        {
            ZWaveValue zvalue = ZWaveValue.ExtractValueFromBytes(message, 4);
            //int meterType = (message[1] & 0x1f);
            //Utility.logger.Warn("METER TYPE ({0})!", meterType);
            EnergyValue energy = new EnergyValue();

            energy.Value = zvalue.Value;
            if (Enum.IsDefined(typeof(ZWaveEnergyScaleType), zvalue.Scale))
            {
                energy.Parameter = (ZWaveEnergyScaleType)zvalue.Scale;
            }
            else
            {
                Utility.logger.Warn("Undefined Energy Meter Scale Type {0}!", zvalue.Scale);
            }


            // sometimes it appears this odd extra bit 0x80 (128) in message[2]
            // when scale type should be power factor it is interpreted as watt
            // (it happens with Qbino smart meter)
            // the following is a temporary work-around for that
            // TODO: find out the meaning of message[2] = 0xA1 (in place of 0x21)
            if ((message[2] & 0x80) == 0x80 && energy.Parameter == ZWaveEnergyScaleType.Watt)
            {
                energy.Parameter = ZWaveEnergyScaleType.PowerFactor;
            }


            switch (energy.Parameter)
            {
            // Accumulated power consumption kW/h
            case ZWaveEnergyScaleType.kWh:
                energy.EventType = EventParameter.MeterKwHour;
                break;

            // Accumulated power consumption kilo Volt Ampere / hours (kVA/h)
            case ZWaveEnergyScaleType.kVAh:
                energy.EventType = EventParameter.MeterKvaHour;
                break;

            // Instant power consumption Watt
            case ZWaveEnergyScaleType.Watt:
                energy.EventType = EventParameter.MeterWatt;
                break;

            // Pulses count
            case ZWaveEnergyScaleType.Pulses:
                energy.EventType = EventParameter.MeterPulses;
                break;

            // AC load Voltage
            case ZWaveEnergyScaleType.ACVolt:
                energy.EventType = EventParameter.MeterAcVolt;
                break;

            // AC load Current
            case ZWaveEnergyScaleType.ACCurrent:
                energy.EventType = EventParameter.MeterAcCurrent;
                break;

            // Power Factor
            case ZWaveEnergyScaleType.PowerFactor:
                energy.EventType = EventParameter.MeterPower;
                break;

            default:
                // Unknown value ?
                energy = null;
                break;
            }
            return(energy);
        }
Esempio n. 6
0
        public static SensorValue Parse(byte[] message)
        {
            var zvalue     = ZWaveValue.ExtractValueFromBytes(message, 4);
            var sensorType = ZWaveSensorParameter.Unknown;

            if (Enum.IsDefined(typeof(ZWaveSensorParameter), (int)message[2]))
            {
                sensorType = (ZWaveSensorParameter)message[2];
            }

            var sensorValue = new SensorValue
            {
                Parameter = sensorType,
                Value     = zvalue.Value
            };

            switch (sensorType)
            {
            case ZWaveSensorParameter.Temperature:
                // convert from Fahrenheit to Celsius if needed
                sensorValue.Value = zvalue.Scale == (int)ZWaveTemperatureScaleType.Fahrenheit
                        ? FahrenheitToCelsius(zvalue.Value)
                        : zvalue.Value;
                sensorValue.EventType = EventParameter.SensorTemperature;
                break;

            case ZWaveSensorParameter.GeneralPurposeValue:
                sensorValue.EventType = EventParameter.SensorGeneric;
                break;

            case ZWaveSensorParameter.Luminance:
                sensorValue.EventType = EventParameter.SensorLuminance;
                break;

            case ZWaveSensorParameter.RelativeHumidity:
                sensorValue.EventType = EventParameter.SensorHumidity;
                break;

            case ZWaveSensorParameter.Power:
                //sensor.Value = BitConverter.ToUInt16(new byte[2] { message[12], message[11] }, 0) / 10D;
                //sensor.Value = ((double)int.Parse(
                //    message[12].ToString("X2") + message[13].ToString("X2") + message[14].ToString("X2"),
                //    System.Globalization.NumberStyles.HexNumber
                //    )) / 1000D;
                // TODO: this might be very buggy.... to be tested
                EnergyValue energy = EnergyValue.Parse(message);
                sensorValue.Value     = energy.Value;
                sensorValue.EventType = EventParameter.MeterPower;
                break;

            case ZWaveSensorParameter.WaterFlow:
                sensorValue.EventType = EventParameter.WaterFlow;
                break;

            case ZWaveSensorParameter.WaterPressure:
                sensorValue.EventType = EventParameter.WaterPressure;
                break;

            case ZWaveSensorParameter.Ultraviolet:
                sensorValue.EventType = EventParameter.Ultraviolet;
                break;

                // TODO: implement other Sensor Types
            }

            return(sensorValue);
        }
Esempio n. 7
0
        public static EnergyValue Parse(byte[] message)
        {
            ZWaveValue  zvalue = ZWaveValue.ExtractValueFromBytes(message, 4);
            EnergyValue energy = new EnergyValue();

            energy.Value = zvalue.Value;
            if (Enum.IsDefined(typeof(ZWaveEnergyScaleType), zvalue.Scale))
            {
                energy.Parameter = (ZWaveEnergyScaleType)zvalue.Scale;
            }
            switch (energy.Parameter)
            {
            // Accumulated power consumption kW/h
            case ZWaveEnergyScaleType.kWh:
                //energy.EventType = EventParameter.MeterKwHour;
                // TODO: The following is fix for for AeonLabs HEM G2
                // TODO: https://github.com/genielabs/HomeGenie/pull/186
                // TODO: possibly move this fix to ZWaveValue.ExtractValueFromBytes method
                if ((message[2] & 0x80) == 0x80)
                {
                    energy.EventType = EventParameter.MeterAcVolt;
                }
                else
                {
                    energy.EventType = EventParameter.MeterKwHour;
                }
                break;

            // Accumulated power consumption kilo Volt Ampere / hours (kVA/h)
            case ZWaveEnergyScaleType.kVAh:
                energy.EventType = EventParameter.MeterKvaHour;
                break;

            // Instant power consumption Watt
            case ZWaveEnergyScaleType.Watt:
                energy.EventType = EventParameter.MeterWatt;
                break;

            // Pulses count
            case ZWaveEnergyScaleType.Pulses:
                energy.EventType = EventParameter.MeterPulses;
                break;

            // AC load Voltage
            case ZWaveEnergyScaleType.ACVolt:
                energy.EventType = EventParameter.MeterAcVolt;
                break;

            // AC load Current
            case ZWaveEnergyScaleType.ACCurrent:
                energy.EventType = EventParameter.MeterAcCurrent;
                break;

            // Power Factor
            case ZWaveEnergyScaleType.PowerFactor:
                energy.EventType = EventParameter.MeterPower;
                break;

            default:
                energy.EventType = EventParameter.MeterWatt;
                break;
            }
            return(energy);
        }