[ST Edge] Issue with the powerMeter ST library

The default handler for SimpleMetering - InstantaneousDemand in st\zigbee\defaults\powerMeter_defaults.lua is calculating power as raw_value * multiplier/divisor = W, whereas the Zigbee spec has the calculation as raw_value * multiplier/divisor = kW. As a result, the power values in the events generated by the handler are 1000x too small.

function powerMeter_defaults.instantaneous_demand_handler(driver, device, value, zb_rx)
  local raw_value = value.value
  --- demand = demand received * Multipler/Divisor
  local multiplier = device:get_field(constants.SIMPLE_METERING_MULTIPLIER_KEY) or 1
  local divisor = device:get_field(constants.SIMPLE_METERING_DIVISOR_KEY) or 1
  raw_value = raw_value * multiplier/divisor
  device:emit_event_for_endpoint(zb_rx.address_header.src_endpoint.value, capabilities.powerMeter.power({value = raw_value, unit = "W" }))
1 Like

Thank you for sharing your findings, @philh30. I’ll report it right away!

1 Like