Tuya Dimmer and Strange On/Off Functionality

Ok, here is my issue. Tried everything I can think of and time to come to the experts. I am using espHome on a Tessan Dimmer, there are a bunch of little lights/buttons etc but the main controls are a switch that physically turns the device on and off on pin 16 and a PWM output that controls the lights dim level on pin 13.

Here is the relevant portion of my configuration that shows these:

switch:
  - platform: gpio
    pin: 16
    name: ${upper_devicename}
    id: relay1
    restore_mode: ALWAYS_OFF
    inverted: True
    on_turn_on:
      - light.turn_on: 
          id: light
    on_turn_off:
      - light.turn_off: 
          id: light
    
light:
  - platform: monochromatic
    name: ${devicename}_light
    id: light
    output: lightPWM

output:
  - platform: esp8266_pwm
    id: lightPWM
    pin: 13

When I pull these devices into home assistant (or use the built in web server) the switch turns the device on and off as expected and the slider on the light works as expected as well. The problem is with the light toggle. If the toggle is “Off” then the light is at its lowest dim instead of being off and if the light toggle is “On” then the light is at whatever dim level is set (ie the correct functionality).

HASS_Light

Am I missing something here? Is the light toggle supposed to turn the light off or just put its lowest dim level? I am thinking this may be a hardware issue (the light is just set up as separate parts, dim level/on-off toggle). If this is the case is there any way to set the switch to turn on/off when the light is toggled, a trigger similar to the switch one (as an example: light.on_turn_on/light.on_turn_off).

Thanks in advance, I really hope I am not missing something silly!

So as of now there is no trigger for lights. The advised route is to add an interval lambda to check on the state of the light

if (id(my_light).get_current_values().get_state()) {
  // only turn on when not already on (to avoid spamming logs)
  if (!id(my_switch).state) id(my_switch).turn_on();
} else {
  if (!d(my_switch).state) id(my_switch).turn_off();
}

Going to give this a try and see if it meets my requirements. Thanks @OttoWinter

Final solution ended up looking like this:

switch:
  - platform: gpio
    pin: 16
    id: relay1
    restore_mode: ALWAYS_OFF
    inverted: True
    on_turn_on:
      - light.turn_on: 
          id: light
    on_turn_off:
      - light.turn_off: 
          id: light
    
light:
  - platform: monochromatic
    name: ${devicename}_light
    id: light
    output: lightPWM

output:
  - platform: esp8266_pwm
    id: lightPWM
    pin: 13

interval:
  - interval: .5sec
    then:
      - lambda: |-
          if (id(light).get_current_values().get_state()) {
            if (!id(relay1).state) {
              id(relay1).turn_on();
            }
          } else {
            if (id(relay1).state) {
              id(relay1).turn_off();
            }
          }

works perfectly and I don’t need the switch itself exposed anymore.

How can I get this code working for this Tuya EU Dimmer? How can I get the right GPIO pins. I cant find anything to this dimmer.
Thanks for help :slight_smile: