ESPhome: Treatlife Smart Dimmer Switch DS02S

I finally took the time to convert the Treatlife Single Pole Smart Dimmer Switch (DS02S) to ESPhome after a bunch of searching and trial and error I finally have a good configuration that gives me all of the same control and options just without the connection to Tuya/Treatlife.

I purchased the DS02S in July 2022, the version that I received has a board version 2.1 with a date code of 2020/06/23. It does have the WB3S module and the Nuvoton (TuyaMCU) controller. I was able to use tuya-cloudcutter to load ESPhome to the board. Below is the YAML file I have loaded and operating on this switch. Some of the text sensors might be too much information so you can always comment it out.

substitutions:
  device_name: basement_lights
  device_friendly_name: Basement Lights
  device_description: "Treatlife Single Pole Smart Dimmer Switch DS02S"
  icon: "mdi:light-switch"
  update_interval_wifi: "60s"

# Esphome core information
esphome:
  name: ${device_name}
  friendly_name: ${device_friendly_name}
  comment: ${device_description}
  on_boot:
    priority: 600
    then:
      lambda: |-
        int value = 0;
        auto call = id(led_indicator).make_call();
        call.set_value(value);
        call.perform();
        id(light1).remote_values.set_brightness(100);

# The board type for this device
bk72xx:
  board: generic-bk7231t-qfn32-tuya
  framework:
    version: dev

# Automatically logs all log messages, By default, all logs with a severity DEBUG or higher will be shown
# Increasing the log level severity (to e.g INFO or WARNING) can help with the performance of the application and memory size.
logger:
  level: INFO
  baud_rate: 0

# Creata a simple web server on the node that can be accessed through any browser and a simple REST API
web_server:

# Make the node announce itself on the local network using the multicast DNS (MDNS)
mdns:

# ESPHome native API is used to communicate with clients directly, required for openHAB functionality
api:
  encryption:
    key: !secret api_password

# Permit OTA (Over The Air) updates
ota:
  - platform: esphome
    password: !secret esphome_password

# Setup the wifi connection, and configure a possible local access point
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  domain: !secret wifi_domain
  power_save_mode: NONE
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: ${device_name}
    password: !secret ap_password

# After 1 minute of unsuccessful WiFi connection attempts, the ESP will start a WiFi hotspot (with the credentials from ap configuration above)
captive_portal:

# Provide buttons to restart device in normal and Safe modes.
button:
  - platform: restart
    name: "Restart"
    id: restart_normal

  - platform: safe_mode
    name: "Restart (Safe Mode)"
    id: restart_safe

debug:
  update_interval: 30s

# Report various information about the device and the WiFi connection
text_sensor:
  - platform: debug
    reset_reason: 
      name: Reset Reason

  - platform: version
    name: Version

  - platform: libretiny
    version: 
      name: LibreTiny Version

  - platform: wifi_info
    ip_address:
      name: ${device_friendly_name} IP Address
      icon: "mdi:ip-outline"
      update_interval: ${update_interval_wifi}
    ssid:
      name: Connected SSID
      icon: "mdi:wifi-settings"
      update_interval: ${update_interval_wifi}
    bssid:
      name: Connected BSSID
      icon: "mdi:wifi-settings"
      update_interval: ${update_interval_wifi}
    mac_address:
      name: ${device_friendly_name} WiFi MAC Address
      icon: "mdi:network-outline"

# Set the
time:
  - platform: sntp
    servers: xx.xx.xx.x
    id: sntp_time

# Loads TUYA library to communicate with MCU and sends the time to the MCU
tuya:
  time_id: sntp_time

# Sets the communication details to MCU
uart:
  rx_pin: GPIO10
  tx_pin: GPIO11
  baud_rate: 115200

# This defines the white led
number:
  - platform: tuya
    id: "led_indicator"
    number_datapoint: 104
    min_value: 0
    max_value: 1
    step: 1

# Report the WiFi Signal Strength and Uptime  
sensor:
  - platform: wifi_signal
    name: ${device_friendly_name} WiFi Signal
    update_interval: 60s
    filters: 
      - delta: 0.01
      - throttle: 300s

  - platform: uptime
    name: ${device_friendly_name} Uptime
    unit_of_measurement: minutes
    filters:
      - lambda: return x / 60.0;
      
light:
  - platform: "tuya"
    name: ${device_friendly_name}
    id: light1
    icon: ${icon}
    dimmer_datapoint: 2
    switch_datapoint: 1
    min_value: 10
    max_value: 1000
    restore_mode: RESTORE_AND_ON

# This allows you to control the Dimming Mode and how the led operates when the load is on or off.
select:
  - platform: "tuya"
    id: "dimmer_mode"
    name: "Dimming Mode"
    enum_datapoint: 4
    options:
      0: LED # Index 0
      1: Incandescent # Index 1
      2: Halogen # Index 2
  
  - platform: template
    name: "LED indicator vs load"
    optimistic: true
    options:
      - Follow
      - Opposite
    set_action:
      then:
        lambda: |-
          int value = 0;
          if( x == "Opposite" ) { value = 0; } else if( x == "Follow") { value = 1; } 
          auto call = id(led_indicator).make_call();
          call.set_value(value);
          call.perform();

#1 - switch
#2 - dimmer = 763
#3 - brightness min = 100 Diming Range 10%= 100, 100%=1000
#4 - dimming mode = LED, incandescent, halogen
#101 - led_bright low/ wake_up value=AAAA
#102 - count_down value=0
#103 - bright_value_3 = 10
#104 - led indicator
#105 - random time

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top