name: ddsu666
description: CHINT DDSU666 single-phase smart meter
function_code: 3          # holding registers (FC03) — DDSU666 has NO input registers (no FC04)
word_order: big           # high register first — ASSUMED; verify with a known voltage reading
byte_order: big           # high byte first within each register (confirmed by manual CRC example)

# NOTE: the manual gives no worked float-decode example, so word_order is a best-guess
# (standard big-endian, high register first, matching sdm120).  After wiring the meter,
# read 0x2000 (voltage) — it should decode to ~230 V.  If it decodes to garbage, the
# device uses the opposite word order and this profile (and the decoder) need adjusting.
# Byte order is confirmed big-endian from the manual (Appendix A, Table A.4: 0x1388 -> 13 88).

blocks:
  # Instantaneous quantities 0x2000–0x200F: voltage, current, P, Q, (rsv), PF, (rsv), Freq.
  # 16 contiguous registers — single bulk read.  (DDSU666 manual Table 9.)
  - { start: 0x2000, count: 0x0010 }
  # Active energy — import (0x4000) and export (0x400A) read as two small blocks rather
  # than one span, to avoid touching the undocumented/reserved 0x4002–0x4009 gap.
  - { start: 0x4000, count: 0x0002 }
  - { start: 0x400A, count: 0x0002 }

metrics:
  # Addresses are the raw Modbus protocol addresses (hex) from DDSU666 manual Table 9,
  # read via FC03.  Each float32 occupies two consecutive 16-bit registers.

  - key: voltage
    address: 0x2000        # U — Voltage (V)
    type: float32
    unit: "V"
    device_class: voltage
    ha_component: sensor

  - key: current
    address: 0x2002        # I — Current (A)
    type: float32
    unit: "A"
    device_class: current
    ha_component: sensor

  - key: active_power
    address: 0x2004        # P — Active power.  Manual unit is kW (NOT W like sdm120).
    type: float32
    unit: "kW"
    device_class: power
    ha_component: sensor

  - key: reactive_power
    address: 0x2006        # Q — Reactive power (kvar)
    type: float32
    unit: "kvar"
    device_class: reactive_power
    ha_component: sensor

  - key: power_factor
    address: 0x200A        # PF — Power factor (dimensionless)
    type: float32
    unit: ""
    device_class: power_factor
    ha_component: sensor

  - key: frequency
    address: 0x200E        # Freq — Frequency (Hz)
    type: float32
    unit: "Hz"
    device_class: frequency
    ha_component: sensor

  - key: import_energy
    address: 0x4000        # Ep — positive/forward active energy (kWh)
    type: float32
    unit: "kWh"
    device_class: energy
    state_class: total_increasing
    ha_component: sensor

  - key: export_energy
    address: 0x400A        # -Ep — reverse active energy (kWh)
    type: float32
    unit: "kWh"
    device_class: energy
    state_class: total_increasing
    ha_component: sensor
