Skip to content

Power Measure

José Antonio Jiménez Campos edited this page May 16, 2021 · 26 revisions

Power measuring characteristics can be added to sensors and the power measurements can be reported to HomeKit. At the time of writing these characteristics are not supported by Apple's Home application. You will need to use HAA Home Manager to access the values that these sensors are reporting.

To declare a power measuring service type,

Type Device Type
75 Power measure

The sensor options remain the same, but additional power measure options can also be used. Follow the details in Sensors to define the sensor requirements. Below are details on how to setup and use the power measurement capabilities.

The following configuration options are available for power measure:

Section Key Description
Chip Type "n" Chip type configuration
CF GPIO "c0" GPIO connected to CF pin
CF1 GPIO "c1" GPIO connected to CF1 pin
Sel1 GPIO "sl" GPIO connected to Sel1 pin
Reading Period "j" Period in seconds between readings
Voltage Factor "vf" Voltage factor adjustment
Voltage Offset "vo" Voltage offset adjustment
Current Factor "cf" Current factor adjustment
Current Offset "co" Current offset adjustment
Power Factor "pf" Power factor adjustment
Power Offset "po" Power offset adjustment

Example 1

{
  "c":{"l":2,"b":[{"g":13,"t":5}]},
  "a":[
    {
      "t":2,
      "0":{"r":[{"g":15},{"g":0,"v":1}]},
      "1":{"r":[{"g":15,"v":1},{"g":0}]},
      "b":[{"g":13}]
    },{
      "t":75,
      "c0":5,
      "c1":4,
      "sl":12,
      "vf":0.13334,
      "cf":0.01295,
      "pf":1.5312,
      "y0":[{"v":245,"0":{"m":[{"g":1}]}}],
      "y1":[{"v":15,"0":{"m":[{"g":1}]}}]
    }
  ]
}

This is an example of a Gosund SP111 v1.1 with over voltage (245VAC) and over current (15A) protection.

See Measurement Calibration for setting "vf", "cf" & "pf" factors.

Example 2

{
  "c": {"n":"2nice-1aptop","l":1,"b":[{"g":3,"t":5}],"u":1},
  "a": [{
    "t": 2,
    "0": {"r":[{"g":14,"v":0},{"g":13,"v":1}]},
    "1": {"r":[{"g":14,"v":1},{"g":13,"v":0}]},
    "b": [{"g":3}]
    },{
      "t": 75,
      "h": 0,
      "n": 0,
      "c0": 4,
      "c1": 5,
      "sl": 12,
      "j": 60,
      "vf": 0.1674,
      "cf": 0.01768,
      "pf": 2.474,
      "y2":[
        {
          "v": 0,
          "r": 1,
          "0": {"h":[{"h":"mynas.local","p": 8086,"m": 2,"u": "write?db=outletdb","c": "sensor,device=2nice-laptop,type=BL0937,location=hall voltage=#HAA@0001,current=#HAA@0002,power=#HAA@0003"}]}
        },
        {
          "v": 2900,
          "0":{"m":[{"g":1,"v":0}]}
        }
      ]
    },{
    "t": 1,
    "i":0.5,
    "1":{"s":[{"a":1}]}
  }]
}

This is an example of a 2nice UP111 WiFi smart plug with over voltage (245VAC) and over current (13A) protection.

See Measurement Calibration for setting "vf", "cf" & "pf" factors.

Note the first entry in Wildcard "y2" sends an entry containing the voltage, current and power readings to an influx database every 60 seconds ("j":60). The second entry in the wildcard turns off the outlet if is consuming more than 2.9KW of power.

This example also makes use the HomeKit Visibility option added in firmware v3.0.0 to hide the sensor from HomeKit, but keep it enabled for sending readings to an influx database.

Chip Type

Two chip types are currently supported; HLW8012 & BL0937.

Key Value Description
"n" 0 HLW8012/BL0937 with Sel1 GPIO LOW to read current (_default)
1 HLW8012/BL0937 with Sel1 GPIO HIGH to read current

The Digital Outputs "r": [{}] for each should be configured to attain the desired state.

Chip GPIOs

The following GPIO settings are mandatory and need defining for readings to be taken from the power sensor.

Key Value Description
"c0" GPIO # Chip CF signal
"c1" GPIO # Chip CF1 signal
"sl" GPIO # Chip Sel signal

Reading Period

The option "j" can be set to define the period of time to take between each sensor reading. If this option is omitted the default value of 5 will be used. State inputs "f[n]" & Status Inputs "g[n]" are supported by these accessories.

Factors and Offsets

Each of the measurement types Voltage, Current & Power need to be calibrated before the sensor will return accurate and meaningful readings. See the Measurement Calibration section on how to go about calibrating a sensor.

Once calibrated the "vf", "vo", "cf", "co", "pf" & "po" options need to be set within the service definition.

NOTE: Currently, only the factor options need to be set. The offset options are not required for the currently supported chip types.

Wildcard Actions

Wildcard Actions "y[n]" are supported by these accessories. The supported list is:

Key Action
"y0" Trigger action when service reaches a specific voltage
"y1" Trigger action when service reaches a specific current
"y2" Trigger action when service reaches a specific power

Refer to Wildcard Actions for more detail.

Measurement Calibration

In order for the device to return accurate measurements it must be calibrated. To calibrate the device you will require:

  • An AC capable, calibrated multi-meter
  • A known wattage load with a power factor as close to 1 as possible e.g. a resistive load such as a incandescent or halogen light bulb.

NOTE: Equipment such as an electric kettle, heater, or blow dryer are also options but you will also need a power meter since the power draw could vary.

Before attempting to calibrate set the service configuration to:

{"t":75, "j":10, "vf":0.1, "cf":0.1, "pf":1}

NOTE You will also need to include values for "c0", "c1" & "sl".

## Calibrate the Voltage Factor

Run the device in debug mode and watch the debug output. Look for a statement like PM Acc 2: V = 250.22, C = 0, P = 0 To set the voltage factor:

  1. Measure the mains voltage on the socket using the multimeter: we will call this the real value
  2. While measuring the real value record the 'V' value from the debug log output: we will call this the sensor value
  3. Get a few readings and take the average of both the real and sensor values
  4. To calculate the offset:
vf = real value average / (sensor value average * 10)

## Calibrate the Power Factor

Run the device in debug mode and watch the debug output. Look for a statement like PM Acc 2: V = 250.22, C = 0, P = 0 To set the power factor:

  1. Turn on the constant current device
  2. Record at least 5 values of the 'P' measurement: call this the sensor value and take the average
  3. Record the value of the constant current device e.g. 60 and call this the real value
  4. To calculate the offset:
pf = real value / sensor value average

## Calibrate the Current Factor

Run the device in debug mode and watch the debug output. Look for a statement like PM Acc 2: V = 250.22, C = 0, P = 0 To set the current factor:

  1. Turn on the constant current device
  2. Record at least 5 values of the 'C' measurement: call this the sensor value and take the average
  3. Use the multimeter to record the real voltage reading: call this the real voltage value
  4. Record the power value of the constant current device e.g. 60 and call this the real power value
  5. To calculate the offset:
cf = (real power value / real voltage value) / (sensor value average * 10)
Clone this wiki locally