ATorch GR2PWS ESPHome Integration [CB2S] [Power Meter/Relay/Switch]

Hey folks,

Last night I took apart my ATorch GR2PWS and flashed the chip inside to cut it off from tuya. I went down a long route to do this - taking the chip out at first, then flashing it with Owner avatar OpenBK7231T_App first. Before doing all that, I dumped the whole firmware, and got all the TuyaMCU pins using the tuya cloud integration trick.

Anyway, here is the ESPHome YAML that works for my situation (There are a few things im not sure on, they will be labeled with (Unconfirmed).

EDIT: forgot to say, I got this using the ltchiptool 4.11.1 => UPK2ESPHome => ESPHome YAML, made it suuuuper easy

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  name_add_mac_suffix: true

bk72xx:
  board: generic-bk7231n-qfn32-tuya

# Enable logging
logger:

# Example configuration entry
web_server:
  port: 80

captive_portal:

mdns:
  disabled: false

# Enable Home Assistant API
api:
  encryption:
    key: ${api_encryption}

ota:
  password: ${ota_password}

time:
  - platform: homeassistant
    id: homeassistant_time

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  use_address: ${ip}

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: ${ap_ssid}
    password: ${ap_password}

button:
  - platform: restart
    name: Restart

debug:
  update_interval: 30s

text_sensor:
  - platform: debug
    reset_reason:
      name: Reset Reason
  - platform: libretiny
    version:
      name: LibreTiny Version

sensor:
  - platform: uptime
    name: Uptime
    
  - platform: tuya
    sensor_datapoint: 18
    name: Current
    unit_of_measurement: A
    accuracy_decimals: 3
    filters:
      - multiply: 0.001
      
  - platform: tuya
    sensor_datapoint: 19
    name: Power
    unit_of_measurement: W
    accuracy_decimals: 2
    filters:
      - multiply: 0.01
      
  - platform: tuya
    sensor_datapoint: 20
    name: Voltage
    unit_of_measurement: V
    accuracy_decimals: 2
    filters:
      - multiply: 0.01
      
  - platform: tuya
    sensor_datapoint: 102
    name: Cost
    accuracy_decimals: 3
    filters:
      - multiply: 0.001
      
  - platform: tuya
    sensor_datapoint: 103
    name: Add'l Cost
    accuracy_decimals: 2
    filters:
      - multiply: 0.01
      
  - platform: tuya
    sensor_datapoint: 122
    name: Electricity leakage
    unit_of_measurement: kw.h
    accuracy_decimals: 3
    filters:
      - multiply: 0.001
      
  - platform: tuya
    sensor_datapoint: 123
    name: Total Electricity
    unit_of_measurement: kw.h
    accuracy_decimals: 3
    filters:
      - multiply: 0.001
      
  - platform: tuya
    sensor_datapoint: 133
    name: Frequency
    unit_of_measurement: Hz
    accuracy_decimals: 2
    filters:
      - multiply: 0.01
      
  - platform: tuya
    sensor_datapoint: 134
    name: Power Factor
    unit_of_measurement: PF
    accuracy_decimals: 2
    filters:
      - multiply: 0.01
      
  - platform: tuya
    sensor_datapoint: 135
    name: CPU Temp
    unit_of_measurement: ""
    
  - platform: tuya
    sensor_datapoint: 140
    name: Balance Energy
    unit_of_measurement: kWh
    accuracy_decimals: 2
    filters:
      - multiply: 0.01

uart:
  rx_pin: RX1
  tx_pin: TX1
  baud_rate: 9600

tuya:
  time_id: homeassistant_time
  # DPIDs processed from schema model: exvou0

switch:
  - platform: tuya
    switch_datapoint: 1
    name: Switch State
    
  - platform: tuya
    switch_datapoint: 111
    name: Key Beep
    
  - platform: tuya
    switch_datapoint: 113
    name: Data Reset
    
  - platform: tuya
    switch_datapoint: 114
    name: Wifi Reset
    
  - platform: tuya
    switch_datapoint: 115
    name: Factory Reset
    
  - platform: tuya
    switch_datapoint: 116
    name: Screen Rotation
    
  - platform: tuya
    switch_datapoint: 120
    name: Overrun Control
    
  - platform: tuya
    switch_datapoint: 126
    name: Real Time Data Refresh
    
  - platform: tuya
    switch_datapoint: 139
    name: Prepayment Switch
    
  - platform: tuya
    switch_datapoint: 141
    name: Clear Remaining Available Power

number:
  - platform: tuya
    number_datapoint: 9
    name: Countdown
    unit_of_measurement: s
    min_value: 0
    max_value: 360000
    step: 1
    mode: box
    
  - platform: tuya
    number_datapoint: 17
    name: Add Electricity
    unit_of_measurement: kwh
    min_value: 0
    max_value: 5000000
    step: 1
    
  - platform: tuya
    number_datapoint: 101
    name: Price
    min_value: 0
    max_value: 99999
    step: 1
    mode: box
    
  - platform: tuya
    number_datapoint: 104
    name: Over Voltage Protection
    unit_of_measurement: V
    min_value: 1
    max_value: 3200
    step: 1
    mode: box
    
  - platform: tuya
    number_datapoint: 105
    name: Over Current Protection
    unit_of_measurement: A
    min_value: 1
    max_value: 1000
    step: 1
    mode: box
    
  - platform: tuya
    number_datapoint: 106
    name: Over Power Protection
    unit_of_measurement: W
    min_value: 1
    max_value: 32000
    step: 1
    mode: box   
    
  - platform: tuya
    number_datapoint: 108
    name: Display Brightness
    min_value: 1
    max_value: 9
    step: 1
    
  - platform: tuya
    number_datapoint: 109
    name: Standby Brightness
    min_value: 0
    max_value: 9
    step: 1
    
  - platform: tuya
    number_datapoint: 110
    name: Standby Time
    unit_of_measurement: s
    min_value: 3
    max_value: 99
    step: 1
    mode: box
    
  - platform: tuya
    number_datapoint: 119
    name: Low Voltage Protection
    unit_of_measurement: V
    min_value: 1
    max_value: 3200
    step: 1
    mode: box
    
  - platform: tuya
    name: (Unconfirmed) Olcp
    number_datapoint: 121
    unit_of_measurement: A
    min_value: 10
    max_value: 100
    step: 1
    
  - platform: tuya
    number_datapoint: 124
    name: Leakage Current
    unit_of_measurement: A
    min_value: 0
    max_value: 120000
    step: 1
    
  - platform: tuya
    number_datapoint: 125
    name: Reporting Interval
    unit_of_measurement: S
    min_value: 1
    max_value: 90
    step: 1
    mode: box
    
  - platform: tuya
    number_datapoint: 137
    name: (Unconfirmed) Over Time
    unit_of_measurement: min
    min_value: 0
    max_value: 99
    step: 1
    
  - platform: tuya
    number_datapoint: 142
    name: Energy Charge
    unit_of_measurement: kWh
    min_value: 0
    max_value: 500000
    step: 1
    
  - platform: tuya
    number_datapoint: 143
    name: Power electricity not enough alarm
    unit_of_measurement: kWh
    min_value: 10
    max_value: 500
    step: 1

select:
  - platform: tuya
    enum_datapoint: 107
    name: Device Language
    optimistic: true
    options:
      0: Chinese
      1: English
      
  - platform: tuya
    enum_datapoint: 112
    name: Switch Mode
    optimistic: true
    options:
      0: Controlled
      1: Normally_Open
      
  - platform: tuya
    enum_datapoint: 117
    name: Standby Screen
    optimistic: true
    options:
      0: Original
      1: Measurement
      
  - platform: tuya
    enum_datapoint: 118
    name: Device Interface
    optimistic: true
    options:
      0: Front
      1: Back
      2: Display_Off
      
  - platform: tuya
    enum_datapoint: 132
    name: Warning Flag
    optimistic: true
    options:
      0: "Off"
      1: Ovp
      2: Ocp
      3: Opp
      4: Lvp
      5: Le
      6: Olcp
      
  - platform: tuya
    enum_datapoint: 136
    name: Price Mode
    optimistic: true
    options:
      0: Single_Rate
      1: Stair
      2: Peak_Valley_Stair
      
  - platform: tuya
    enum_datapoint: 138
    name: Device Power-Up Switch Status
    optimistic: true
    options:
      0: Memory

{
  "1": "Switch state",
  "9": "Countdown",
  "17": "Add Electricity",
  "18": "Current",
  "19": "Power",
  "20": "Voltage",
  "101": "Price",
  "102": "Bill",
  "103": "Add Bill",
  "104": "OVP",
  "105": "OCP",
  "106": "OPP",
  "107": "Device Language",
  "108": "Display Brightness",
  "109": "Standby Brightness",
  "110": "Enter standby time",
  "111": "Key Beep",
  "112": "Switch Mode",
  "113": "Data Zero",
  "114": "Wi-Fi Device Reset",
  "115": "System All Default Settings",
  "116": "Screen rontation",
  "117": "Standby Screen",
  "118": "Device Interface",
  "119": "LVP",
  "120": "Overrun Control Enable",
  "121": "Leakage valve value:",
  "122": "Electricity leakage",
  "123": "Total Ele",
  "124": "Leakage Current",
  "125": "Data refresh interval time",
  "126": "Real time data refresh switch",
  "127": "ON",
  "128": "OFF",
  "129": "CDON",
  "130": "CDOFF",
  "131": "Switch",
  "132": "Alarm flag or Warning flag.",
  "133": "Frequency",
  "134": "Factor",
  "135": "CPU Temp",
  "136": "Price Mode:",
  "137": "Volt recover delay time:",
  "138": "Device Power-up switch status:",
  "139": "Prepayment switch",
  "140": "Balance energy",
  "141": "剩余可用电量清零",
  "142": "Energy charge",
  "143": "Power electricity not enough alarm"
}