name: Energy meter
products:
  - id: kmnzgh4yn8pa0lqh
    manufacturer: Tongou
    model: TO-Q-SYS-WT
entities:
  - entity: sensor
    class: energy
    category: diagnostic
    dps:
      - id: 1
        type: integer
        name: sensor
        unit: kWh
        class: total_increasing
        mapping:
          - scale: 100
      - id: 125
        type: integer
        name: fap_a
        mapping:
          - scale: 100
      - id: 138
        type: string
        name: cycle_time
  - entity: sensor
    class: voltage
    category: diagnostic
    dps:
      - id: 6
        type: base64
        name: sensor
        optional: true
        unit: V
        mask: "FFFF000000000000"
        mapping:
          - scale: 10
  - entity: sensor
    class: current
    category: diagnostic
    dps:
      - id: 6
        type: base64
        name: sensor
        optional: true
        unit: A
        mask: "0000FFFFFF000000"
        mapping:
          - scale: 1000
  - entity: sensor
    class: power
    category: diagnostic
    dps:
      - id: 6
        type: base64
        name: sensor
        optional: true
        unit: kW
        mask: "0000000000FFFFFF"
        mapping:
          - scale: 1000
  - entity: switch
    name: Prepay
    icon: "mdi:cash"
    category: config
    dps:
      - id: 11
        type: boolean
        name: switch
  - entity: button
    name: Clear energy
    category: config
    dps:
      - id: 12
        type: boolean
        name: button
        optional: true
  - entity: sensor
    name: Balance energy
    class: energy_storage
    category: diagnostic
    dps:
      - id: 13
        type: integer
        optional: true
        name: sensor
        unit: kWh
        class: measurement
        mapping:
          - scale: 100
  - entity: number
    name: Charge energy
    category: config
    class: energy_storage
    dps:
      - id: 14
        type: integer
        optional: true
        name: value
        unit: kWh
        range:
          min: 0
          max: 999999
        mapping:
          - scale: 100
  - entity: switch
    name: Breaker
    icon: "mdi:fuse"
    dps:
      - id: 16
        type: boolean
        name: switch
  - entity: select
    translation_key: breaker_trigger_action
    translation_placeholders:
      trigger: Prepay shortage
    icon: "mdi:cash"
    category: config
    dps:
      - id: 101
        type: string
        name: option
        mapping:
          - dps_val: Closed
            value: ignore
          - dps_val: Alarm
            value: alarm
  - entity: select
    translation_key: breaker_trigger_action
    translation_placeholders:
      trigger: Over voltage
    category: config
    dps:
      - id: 102
        type: string
        name: option
        mapping:
          - dps_val: Closed
            value: ignore
          - dps_val: Alarm
            value: alarm
          - dps_val: Trip
            value: trip_breaker
  - entity: select
    translation_key: breaker_trigger_action
    translation_placeholders:
      trigger: Undervoltage
    category: config
    dps:
      - id: 103
        type: string
        name: option
        mapping:
          - dps_val: Closed
            value: ignore
          - dps_val: Alarm
            value: alarm
          - dps_val: Trip
            value: trip_breaker
  - entity: select
    translation_key: breaker_trigger_action
    translation_placeholders:
      trigger: Over current
    category: config
    dps:
      - id: 104
        type: string
        name: option
        mapping:
          - dps_val: Closed
            value: ignore
          - dps_val: Alarm
            value: alarm
          - dps_val: Trip
            value: trip_breaker
  - entity: select
    translation_key: breaker_trigger_action
    translation_placeholders:
      trigger: Over power
    category: config
    dps:
      - id: 105
        type: string
        name: option
        mapping:
          - dps_val: Closed
            value: ignore
          - dps_val: Alarm
            value: alarm
          - dps_val: Trip
            value: trip_breaker
  - entity: select
    translation_key: breaker_trigger_action
    translation_placeholders:
      trigger: High temperature
    category: config
    dps:
      - id: 107
        type: string
        name: option
        mapping:
          - dps_val: Closed
            value: ignore
          - dps_val: Alarm
            value: alarm
          - dps_val: Trip
            value: trip_breaker
  - entity: binary_sensor
    class: connectivity
    category: diagnostic
    dps:
      - id: 109
        type: string
        name: sensor
        mapping:
          - dps_val: online
            value: true
          - dps_val: offline
            value: false
  - entity: sensor
    translation_key: status
    class: enum
    category: diagnostic
    dps:
      - id: 110
        type: string
        name: sensor
        mapping:
          - dps_val: Normal
            value: normal
          - dps_val: Over_Current_Trip
            value: tripped_over_current
          - dps_val: Over_Power_Trip
            value: tripped_over_power
          - dps_val: High_Temp_Trip
            value: tripped_high_temperature
          - dps_val: Over_Voltage_Trip
            value: tripped_over_voltage
          - dps_val: Under_Voltage_Trip
            value: tripped_under_voltage
          - dps_val: Over_Current_Alarm
            value: over_current_alarm
          - dps_val: Over_Power_Alarm
            value: over_power_alarm
          - dps_val: High_Temp_Alarm
            value: high_temperature_alarm
          - dps_val: Over_Voltage_Alarm
            value: over_voltage_alarm
          - dps_val: Under_Voltage_Alarm
            value: under_voltage_alarm
          - dps_val: Remote_ON
            value: remote_on
          - dps_val: Remote_OFF
            value: remote_off
          - dps_val: Manual_ON
            value: manual_on
          - dps_val: Manual_OFF
            value: manual_off
          - dps_val: Leakage_Trip
            value: tripped_earth_leak
          - dps_val: Leakage_Alarm
            value: earth_leak_alarm
          - dps_val: Restore_Default
            value: restore_default
          - dps_val: Automatic_Closing
            value: auto_reset
          - dps_val: Electricity_Shortage
            value: prepay_low
          - dps_val: Electricity_Shortage_Alarm
            value: prepay_low_alarm
          - dps_val: Timing_switch_ON
            value: timer_on
          - dps_val: Timing_switch_OFF
            value: timer_off
  - entity: switch
    name: Report state changes
    icon: "mdi:toggle-switch"
    category: config
    dps:
      - id: 111
        type: boolean
        name: switch
  - entity: switch
    name: Auto reset
    icon: "mdi:refresh-auto"
    category: config
    dps:
      - id: 112
        type: boolean
        name: switch
  - entity: number
    name: Over current threshold
    category: config
    class: current
    dps:
      - id: 114
        type: integer
        name: value
        unit: A
        range:
          min: 1
          max: 50
  - entity: number
    name: Over voltage threshold
    category: config
    class: voltage
    dps:
      - id: 115
        type: integer
        name: value
        unit: V
        range:
          min: 100
          max: 280
  - entity: number
    name: Under voltage threshold
    category: config
    class: voltage
    dps:
      - id: 116
        type: integer
        name: value
        unit: V
        range:
          min: 100
          max: 280
  - entity: number
    name: Temperature threshold
    category: config
    class: temperature
    dps:
      - id: 118
        type: integer
        optional: true
        name: value
        unit: C
        range:
          min: -250
          max: 800
        mapping:
          - scale: 10
  - entity: number
    name: Over power threshold
    category: config
    class: power
    dps:
      - id: 119
        type: integer
        name: value
        unit: W
        range:
          min: 10
          max: 12500
        mapping:
          - step: 10
  - entity: number
    name: Prepay shortage threshold
    category: config
    class: energy_storage
    dps:
      - id: 120
        type: integer
        name: value
        unit: kWh
        range:
          min: 10
          max: 500
  - entity: sensor
    class: temperature
    category: diagnostic
    dps:
      - id: 131
        type: integer
        name: sensor
        unit: C
        class: measurement
        mapping:
          - scale: 10
  - entity: number
    name: Report frequency
    category: config
    icon: "mdi:send-clock"
    dps:
      - id: 137
        type: integer
        name: value
        unit: s
        range:
          min: 60
          max: 600
  - entity: light
    class: display
    category: config
    dps:
      - id: 141
        name: switch
        type: boolean
        mapping:
          - dps_val: true
            value: false
          - dps_val: false
            value: true
      - id: 140
        name: brightness
        type: integer
        range:
          min: 1
          max: 5
  - entity: select
    translation_key: initial_state
    category: config
    dps:
      - id: 142
        type: string
        name: option
        mapping:
          - dps_val: "off"
            value: "off"
          - dps_val: "on"
            value: "on"
          - dps_val: memory
            value: memory
