name: Energy meter
products:
  - id: g5n4t0
    manufacturer: Zemismart
    model_id: SPM02-D2TW
    model: 3-Phase Energy Meter
entities:
  # Total energy consumed
  - entity: sensor
    translation_key: energy_consumed
    class: energy
    dps:
      - id: 1
        type: integer
        name: sensor
        unit: kWh
        class: total_increasing
        mapping:
          - scale: 100
  # Total energy produced
  - entity: sensor
    translation_key: energy_produced
    class: energy
    dps:
      - id: 23
        type: integer
        name: sensor
        unit: kWh
        class: total_increasing
        mapping:
          - scale: 100
  # Total active power
  - entity: sensor
    class: power
    dps:
      - id: 29
        name: sensor
        unit: W
        class: measurement
        type: integer
  # Active power L1
  - entity: sensor
    translation_key: power_x
    translation_placeholders:
      x: L1
    class: power
    dps:
      - id: 105
        name: sensor
        unit: W
        class: measurement
        type: integer
  # Active power L2
  - entity: sensor
    translation_key: power_x
    translation_placeholders:
      x: L2
    class: power
    dps:
      - id: 114
        name: sensor
        unit: W
        class: measurement
        type: integer
  # Active power L3
  - entity: sensor
    translation_key: power_x
    translation_placeholders:
      x: L3
    class: power
    dps:
      - id: 123
        name: sensor
        unit: W
        class: measurement
        type: integer
  # Voltage L1
  - entity: sensor
    translation_key: voltage_x
    translation_placeholders:
      x: L1
    class: voltage
    category: diagnostic
    dps:
      - id: 103
        name: sensor
        unit: V
        class: measurement
        type: integer
        mapping:
          - scale: 10
  # Voltage L2
  - entity: sensor
    translation_key: voltage_x
    translation_placeholders:
      x: L2
    class: voltage
    category: diagnostic
    dps:
      - id: 112
        name: sensor
        unit: V
        class: measurement
        type: integer
        mapping:
          - scale: 10
  # Voltage L3
  - entity: sensor
    translation_key: voltage_x
    translation_placeholders:
      x: L3
    class: voltage
    category: diagnostic
    dps:
      - id: 121
        name: sensor
        unit: V
        class: measurement
        type: integer
        mapping:
          - scale: 10
  # Current L1
  - entity: sensor
    translation_key: current_x
    translation_placeholders:
      x: L1
    class: current
    category: diagnostic
    dps:
      - id: 104
        name: sensor
        unit: A
        class: measurement
        type: integer
        mapping:
          - scale: 1000
  # Current L2
  - entity: sensor
    translation_key: current_x
    translation_placeholders:
      x: L2
    class: current
    category: diagnostic
    dps:
      - id: 113
        name: sensor
        unit: A
        class: measurement
        type: integer
        mapping:
          - scale: 1000
  # Current L3
  - entity: sensor
    translation_key: current_x
    translation_placeholders:
      x: L3
    class: current
    category: diagnostic
    dps:
      - id: 122
        name: sensor
        unit: A
        class: measurement
        type: integer
        mapping:
          - scale: 1000
  # Power factor L1
  - entity: sensor
    name: Power factor L1
    class: power_factor
    category: diagnostic
    dps:
      - id: 108
        name: sensor
        unit: "%"
        class: measurement
        type: integer
  # Power factor L2
  - entity: sensor
    name: Power factor L2
    class: power_factor
    category: diagnostic
    dps:
      - id: 117
        name: sensor
        unit: "%"
        class: measurement
        type: integer
  # Power factor L3
  - entity: sensor
    name: Power factor L3
    class: power_factor
    category: diagnostic
    dps:
      - id: 126
        name: sensor
        unit: "%"
        class: measurement
        type: integer
  # Total power factor
  - entity: sensor
    class: power_factor
    category: diagnostic
    dps:
      - id: 50
        name: sensor
        type: integer
        unit: "%"
        class: measurement
  # Energy consumed L1
  - entity: sensor
    translation_key: energy_consumed_x
    translation_placeholders:
      x: L1
    class: energy
    category: diagnostic
    dps:
      - id: 109
        type: integer
        name: sensor
        unit: kWh
        class: total_increasing
        mapping:
          - scale: 100
  # Energy produced L1
  - entity: sensor
    translation_key: energy_produced_x
    translation_placeholders:
      x: L1
    class: energy
    category: diagnostic
    dps:
      - id: 110
        type: integer
        name: sensor
        unit: kWh
        class: total_increasing
        mapping:
          - scale: 100
  # Energy consumed L2
  - entity: sensor
    translation_key: energy_consumed_x
    translation_placeholders:
      x: L2
    class: energy
    category: diagnostic
    dps:
      - id: 118
        type: integer
        name: sensor
        unit: kWh
        class: total_increasing
        mapping:
          - scale: 100
  # Energy produced L2
  - entity: sensor
    translation_key: energy_produced_x
    translation_placeholders:
      x: L2
    class: energy
    category: diagnostic
    dps:
      - id: 119
        type: integer
        name: sensor
        unit: kWh
        class: total_increasing
        mapping:
          - scale: 100
  # Energy consumed L3
  - entity: sensor
    translation_key: energy_consumed_x
    translation_placeholders:
      x: L3
    class: energy
    category: diagnostic
    dps:
      - id: 127
        type: integer
        name: sensor
        unit: kWh
        class: total_increasing
        mapping:
          - scale: 100
  # Energy produced L3
  - entity: sensor
    translation_key: energy_produced_x
    translation_placeholders:
      x: L3
    class: energy
    category: diagnostic
    dps:
      - id: 128
        type: integer
        name: sensor
        unit: kWh
        class: total_increasing
        mapping:
          - scale: 100
  # Frequency
  - entity: sensor
    class: frequency
    category: diagnostic
    dps:
      - id: 32
        name: sensor
        unit: Hz
        class: measurement
        type: integer
        mapping:
          - scale: 100
  # Phase current imbalance
  - entity: sensor
    name: Current imbalance
    category: diagnostic
    dps:
      - id: 130
        name: sensor
        type: integer
        unit: "%"
        class: measurement
  # Fault status
  - entity: binary_sensor
    class: problem
    category: diagnostic
    dps:
      - id: 9
        type: bitfield
        name: sensor
        mapping:
          - dps_val: 0
            value: false
          - value: true
      - id: 9
        type: bitfield
        name: fault_code
      - id: 9
        type: bitfield
        name: description
        mapping:
          - dps_val: 0
            value: ok
          - dps_val: 1
            value: short_circuit
          - dps_val: 2
            value: surge
          - dps_val: 4
            value: overload
          - dps_val: 8
            value: earth_leak
          - dps_val: 16
            value: temperature_difference
          - dps_val: 32
            value: fire
          - dps_val: 64
            value: high_power
          - dps_val: 128
            value: self_test
          - dps_val: 256
            value: over_current
          - dps_val: 512
            value: unbalanced
          - dps_val: 1024
            value: over_voltage
          - dps_val: 2048
            value: under_voltage
          - dps_val: 4096
            value: miss_phase
          - dps_val: 8192
            value: outage
          - dps_val: 16384
            value: magnetism
          - dps_val: 32768
            value: credit_low
          - dps_val: 65536
            value: credit_expired
  # Clear energy counters
  - entity: button
    name: Reset energy
    class: restart
    category: config
    dps:
      - id: 12
        type: boolean
        name: button
  # Report interval
  - entity: number
    name: Reporting interval
    category: config
    class: duration
    icon: "mdi:timer-cog"
    dps:
      - id: 102
        type: integer
        name: value
        unit: s
        range:
          min: 5
          max: 3600
