name: EV charger
products:
  - id: bktb3jskdic1ar2t
    name: Nine 32A EV charger
primary_entity:
  entity: sensor
  name: Charger State
  icon: "mdi:ev-station"
  class: enum
  dps:
    - id: 3  # work_state
      type: string
      name: sensor
      mapping:
        - dps_val: charger_charging
          value: Charging
        - dps_val: charger_free
          value: Available
        - dps_val: charger_insert
          value: Plugged in
        - dps_val: charger_free_fault
          value: Fault
        - dps_val: charger_wait
          value: Plugged in, not charging
        - dps_val: charger_pause
          value: Paused
        - dps_val: charger_end
          value: Charge finished
        - dps_val: charger_fault
          value: Fault (plugged in)
    - id: 23  # system_version
      type: string
      name: system_version
secondary_entities:
  - entity: number
    name: Charging current
    category: config
    class: current
    icon: "mdi:ev-plug-type2"
    dps:
      - id: 4  # charge_cur_set
        type: integer
        name: value
        unit: A
        optional: true
        range:
          min: 6
          max: 80
  - entity: sensor
    class: power
    category: diagnostic
    dps:
      - id: 9
        type: integer
        optional: true
        name: sensor
        unit: kW
        class: measurement
        mapping:
          - scale: 1000
  - entity: binary_sensor
    class: problem
    category: diagnostic
    dps:
      - id: 10  # fault sensor
        type: bitfield
        name: sensor
        optional: true
        mapping:
          - dps_val: 0
            value: false
          - value: true
      - id: 10  # fault code
        type: bitfield
        name: fault_code
        optional: true
      - id: 10  # fault desc
        type: bitfield
        name: description
        optional: true
        mapping:
          - dps_val: 0
            value: "Ok"
          - dps_val: 1
            value: "Ov2 Cr Fault"
          - dps_val: 2
            value: "Overvoltage alarm"
          - dps_val: 4
            value: "Undervoltage alarm"
          - dps_val: 8
            value: "Contactor adhesion"
          - dps_val: 16
            value: "Contactor fault"
          - dps_val: 32
            value: "Earth fault"
          - dps_val: 64
            value: "Meter Hardware alarm"
          - dps_val: 128
            value: "Scram fault"
          - dps_val: 256
            value: "CP fault"
          - dps_val: 512
            value: "Meter Commu fault"
          - dps_val: 1024
            value: "Card reader fault"
          - dps_val: 2048
            value: "Cir short fault"
          - dps_val: 4096
            value: "Adhesion fault"
          - dps_val: 8192
            value: "Self test alarm"
          - dps_val: 16384
            value: "Leakage current fault"
  - entity: select
    name: Charging mode
    icon: "mdi:ev-station"
    category: config
    dps:
      - id: 14  # work_mode
        type: string
        optional: true
        name: option
        mapping:
          - dps_val: charge_now
            value: Always on
          - dps_val: charge_energy
            value: Charge energy limit
          - dps_val: charge_schedule
            value: Scheduled charge
          - dps_val: charge_pct
            value: Charge percent limt
          - dps_val: charge_delay
            value: Delayed charge
  - entity: sensor
    name: Voltage A
    class: voltage
    dps:
      - id: 6  # phase_1
        type: base64
        name: sensor
        optional: true
        unit: V
        mapping:
          - mask: "FFFF0000000000"
            scale: 10
  - entity: sensor
    name: Current A
    class: current
    dps:
      - id: 6  # phase_1
        type: base64
        name: sensor
        optional: true
        unit: A
        mapping:
          - mask: "0000FFFFFF0000"
            scale: 1000
  - entity: sensor
    name: Power A
    class: power
    dps:
      - id: 6  # phase_1
        type: base64
        name: sensor
        optional: true
        unit: kW
        mapping:
          - mask: "0000000000FFFF"
            scale: 1000
  - entity: sensor
    name: Voltage B
    class: voltage
    dps:
      - id: 7  # phase_1
        type: base64
        name: sensor
        optional: true
        unit: V
        mapping:
          - mask: "FFFF000000000000"
            scale: 10
  - entity: sensor
    name: Current B
    class: current
    dps:
      - id: 7  # phase_1
        type: base64
        name: sensor
        optional: true
        unit: A
        mapping:
          - mask: "0000FFFFFF000000"
            scale: 1000
  - entity: sensor
    name: Power B
    class: power
    dps:
      - id: 7  # phase_1
        type: base64
        name: sensor
        optional: true
        unit: kW
        mapping:
          - mask: "0000000000FFFFFF"
            scale: 1000
  - entity: sensor
    name: Voltage C
    class: voltage
    dps:
      - id: 8  # phase_1
        type: base64
        name: sensor
        optional: true
        unit: V
        mapping:
          - mask: "FFFF000000000000"
            scale: 10
  - entity: sensor
    name: Current C
    class: current
    dps:
      - id: 8  # phase_1
        type: base64
        name: sensor
        optional: true
        unit: A
        mapping:
          - mask: "0000FFFFFF000000"
            scale: 1000
  - entity: sensor
    name: Power C
    class: power
    dps:
      - id: 8  # phase_1
        type: base64
        name: sensor
        optional: true
        unit: kW
        mapping:
          - mask: "0000000000FFFFFF"
            scale: 1000
  - entity: number
    name: Charge time
    category: config
    icon: "mdi:timer"
    dps:
      - id: 19
        type: integer
        optional: true
        name: value
        unit: min
        range:
          min: 1
          max: 1440
  - entity: sensor
    name: Last session energy
    class: energy_storage
    dps:
      - id: 25  # charge_energy_once
        type: integer
        name: sensor
        optional: true
        unit: kWh
        class: measurement
        mapping:
          - scale: 100
  - entity: switch
    icon: "mdi:ev-station"
    dps:
      - id: 18  # switch
        type: boolean
        name: switch
