ESPHome configuration yaml for UltraPro toggle dimmer switch

I’m very new to ESPHome.

I decided to give tuya-cloudcutter a try on one of my switches, and now I’m stuck.

The switch in question is this:
Amazon link

Ultrapro Wifi Toggle Dimmer 51427

I got a raspberry pi 5, with latest raspberry os 64 bit.
I loaded and successfully ran the tuya cloudcutter process on this switch.
The switch now has the kickstart firmware and is on my home wifi network, and I can access its webpage at 192.168.4.1.

I then downloaded LTChipTool and found a profile for this switch on that application, and copied the yaml code it produced, and pasted it into ESPHome Device Builder.
I also tried the yaml code I got from UPK2ESPHome.

But when I clicked install in ESPHome Device Builder and chose “manual” (I planned to upload it through kickstart at 192.168.4.1), it gave me this error message:

Failed config

output.libretiny_pwm: [source /config/esphome/basement-toy-area.yaml:34]
  platform: libretiny_pwm
  id: output_red
  
  Pin number '19' is not usable for board generic-bk7231n-qfn32-tuya.
  pin: P19

I have a feeling that this config code is not the right code for this switch, but not sure.

Any suggestions?

This is the config code I pasted into ESPHome Device Builder:

esphome:
  name: upk2esphome-bk7231n

bk72xx:
  board: generic-bk7231n-qfn32-tuya

logger:

web_server:

captive_portal:

mdns:

api:
  password: ""

ota:
  platform: esphome
  password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:

text_sensor:
  - platform: libretiny
    version:
      name: LibreTiny Version

output:
  - platform: libretiny_pwm
    id: output_red
    pin: P19
  - platform: libretiny_pwm
    id: output_green
    pin: P18
  - platform: libretiny_pwm
    id: output_blue
    pin: P8
  - platform: libretiny_pwm
    id: output_cold
    pin: P7
  - platform: libretiny_pwm
    id: output_warm
    pin: P6

light:
  - platform: rgbww
    id: light_rgbww
    name: Light
    color_interlock: true
    cold_white_color_temperature: 6500 K
    warm_white_color_temperature: 2700 K
    red: output_red
    green: output_green
    blue: output_blue
    cold_white: output_cold
    warm_white: output_warm

And I think if you fix that you will find you get the same error for P18.

Have a look at the pinout and maybe try some valid pins. Not sure what you can break unfortunately.

You could also have a look at the circuit board if you can get it apart…. Post some photos if you do.

I used the kickstart webpage to scan all the pins.
The only pins that responded were 8 and 14.
When I selected pin 8, there was a response on a downpress of the toggle switch.
When I selected pin 14, then it just shows continuous responses, no need for me to touch the actual switch.

There are the only responses I got from the pins from the kickstart webpage.

Any luck figuring this out? I have a similar switch (WFD4001) that I was planning to flash the same way.

This is config that ended up working for me:

esphome:
  name: 
  friendly_name: 
  on_boot: #this starts the blue LED on and blinking while it connects to wifi. on_connect for wifi will change it. 
    priority: 600
    then: 
      - light.turn_on:
          id: blue_led
          effect: strobe

substitutions:
  project_name: "UltraPro.WFD3001_CB3S_Serial_PWM_Dimmer_Switch"
  project_version: "0.0.1"
  hardware_info: "UltraPro WFD3001 CB3S Serial PWM Dimmer Switch"
  detach_relay: "false"
  status_light_follows_primary_light_state: "false"
  status_inverted: "false"
  min_power: "0.1"
  max_power: "1.0"
  restore_mode_light: RESTORE_DEFAULT_OFF

globals:
- id: detach_relay_value
  type: bool
  initial_value: ${detach_relay}
- id: status_light_follows_primary_light_state_value
  type: bool
  initial_value: ${status_light_follows_primary_light_state}

bk72xx:
  board: cb3s

# Enable logging
logger:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap: 
  on_connect: # change the blue led status LED based on Wifi connections
              # NOTE: when in AP mode, it will show as "connected"
              # this is more to show if/when locally if the wifi has connected during boot up

 # need a condition here to either turn off or just turn off the effect so it matches the state of the LED
    - light.turn_on: 
        id: blue_led
        effect: none
  on_disconnect:
    - light.turn_on: 
        id: blue_led
        effect: strobe

# Enable Home Assistant API
api:
  
ota:
  platform: esphome
  
captive_portal:

web_server:
  port: 80
  version: 3
  id: id_web_server

sensor:
  - platform: wifi_signal
    name: WiFi Signal
    update_interval: 60s

  - platform: uptime
    name: Uptime

#-------------- UART output setup to control PWM MCU for dimmer --------------------------
uart:
  baud_rate: 115200
  tx_pin: GPIO11
  rx_pin: GPIO10
  # debug:
  #   direction: BOTH
  #   dummy_receiver: false
  #   after:
  #     delimiter: "\n"
  #   sequence:
  #     - lambda: UARTDebug::log_string(direction, bytes);


output:
  #-------------- Blue Status LED output control --------------------------
  - id: blue_ledout
    platform: gpio
    pin: P24    #D3/P24 = Blue LED
 
  #-------------- Main Light output control --------------------------
  - platform: template
    id: output_template
    type: float
    min_power: 0.1
    zero_means_zero: true
    write_action:
      # - logger.log:
      #     format: "%f"
      #     args: [state]
      - uart.write: !lambda return {0x65, 0xAA, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, (uint8_t)(state * 255), 0x00, (uint8_t)((277 + (uint8_t)(state * 255)) % 256)};
light:
  #-------------- Blue Statue LED at bottom of switch --------------------------
  # after creating this, found out there is a status_led platform: https://esphome.io/components/light/status_led.html
  #                                                                https://esphome.io/components/status_led.html
  - platform: binary
    id: blue_led
    output: blue_ledout
    restore_mode: ALWAYS_ON 
    # NOTE: can use effects... https://esphome.io/components/light/#light-effects
    effects:
      - strobe:

  #-------------- Primary Light --------------------------
  - platform: monochromatic
    name: "Light"
    id: light_primary
    output: output_template
    #gamma_correct: 1.0
    #default_transition_length: 0s
    on_turn_on: # turn on/off blue led status led based on switch state (on while off so it can be seen in the dark)
      then:
        - light.turn_off: blue_led
    on_turn_off:
      then:
        - light.turn_on: blue_led

binary_sensor:
  #-------------- On Botton (upper paddle) --------------------------
  - platform: gpio
    id: button_on 
    pin:
      number: P7 # On Button
      inverted: true
    
    on_multi_click:
      - timing: #------------ double click on button ------------
          - ON for at most 350ms
          - OFF for at most 350ms
          - ON for at most 350ms
          - OFF for at least 350ms
        then:
          #S- logger.log: "On Double Clicked"
          - light.turn_on: 
              id: light_primary
              brightness: 50%
      
      - timing: #------------ single click on button ------------
          - ON for at most 350ms
          - OFF for at least 500ms
        then:
          #- logger.log: "Single Short Clicked"
          if:
            condition:
                light.is_on: light_primary
            then:
              - light.turn_on: 
                  id: light_primary
                  brightness: 100%
            else:
              - light.turn_on: light_primary
    
    on_press: #------------ press and hold on button ------------
      - delay: 0.35s
      - while:
          condition:
            binary_sensor.is_on: button_on
          then:
            - light.dim_relative:
                id: light_primary
                relative_brightness: 5%
                transition_length: 0.1s
            - delay: 0.1s
  

  #-------------- Off Botton (lower paddle) --------------------------
  - platform: gpio
    id: button_off
    pin:
      number: P8 # Off Button
      inverted: true

    on_multi_click:
      - timing: #------------ double click off button ------------
          - ON for at most 350ms
          - OFF for at most 350ms
          - ON for at most 350ms
          - OFF for at least 350ms
        then:
          #- logger.log: "Off Double Clicked"
          if:    #if light is on, turn off slowly, else turn on light to 1%
            condition:
                light.is_on: light_primary
            then:
              - light.turn_on: #change light immediately for feedback of the doubleclick action
                  id: light_primary
                  transition_length: .5s
                  brightness: !lambda 'return( id(light_primary).remote_values.get_brightness() / 2 );'
              - light.turn_off: #turn off light over 10 seconds
                  id: light_primary
                  transition_length: 10s
            else:
              - light.turn_on: 
                  id: light_primary
                  brightness: 1%

      - timing: #------------ single click off button ------------
          - ON for at most 350ms
          - OFF for at least 500ms
        then:
          #- logger.log: "Off Single Clicked"
          - light.turn_off: light_primary #transition_length if you want transition time changed
        
    on_press: #------------ press and hold off button ---------------
      - delay: 0.35s
      - while:
          condition:
            binary_sensor.is_on: button_off
          then:
            if: #keep brightness at a minimum of 1% so it does not turn off the light when dimming locally 
              condition:
                  lambda: 'return(id(light_primary).remote_values.get_brightness() < 0.06);'
              then:
                #- logger.log: "dimming to 1%...."
                - light.turn_on: 
                    id: light_primary
                    brightness: 1%
                - delay: 0.1s
              else:
                - light.dim_relative:
                    id: light_primary
                    relative_brightness: -5%
                    transition_length: 0.1s
                - delay: 0.1s
  
  #-------------- Reset Botton (behind wall plate) --------------------------
  - platform: gpio
    id: button_reset
    pin:
      number: P6 # Reset Button
      inverted: true
    #on_click:
    #- TODO