ESPHome Martin Jerry SD01

I have 8 SD01 switches. That all work well.

What I would like to change is the amount of time that when it is to be turned off not have a delay.
It seems that there is a 1-3 second delay before the light turns off.
I am unsure which part of the code to fiddle with, because I usually mess it up.

substitutions:
  device_name: hall-light
  friendly_name: Hall Light
  pwm_min_power: 15%      # keep dimming functional at lowest levels
  no_delay: 0s            # transition when changing dimmer_lvl & relay delay
  transition_length: .5s  # transition when turning on/off
  long_press_min: .4s     # minimum time to activate long-press action
  long_press_max: 2s      # maximum time to activate long-press action
  long_press_up: 100%     # long press brightness
  long_press_down: 33%    # long press brightness
  long_press_main: 50%    # long press brightness

My thinking that it is the transition length. But if I set it to “0” what other affects it might have.

Thank you

We simply can’t know as you don’t provide the minimum necessery infromations like including your yaml :man_shrugging:

Here is the full yaml for the switch, less the wifi login data

substitutions:
  #   # https://esphome.io/guides/configuration-types.html#substitutions
  device_name: switch-office-dimmer # hostname & entity_id
  friendly_name: Switch Office Dimmer # Displayed in HA frontend
  ip_address: !secret switch_office_dimmer # use /config/esphome/secrets.yaml
  pwm_min_power: 5% # keep dimming functional at lowest levels
  no_delay: 0s # transition when changing dimmer_lvl & relay delay
  transition_length: .5s # transition when turning on/off
  long_press_min: .4s # minimum time to activate long-press action
  long_press_max: 2s # maximum time to activate long-press action
  long_press_up: 100% # long press brightness
  long_press_down: 33% # long press brightness
  long_press_main: 50% # long press brightness
  # Number of incremental steps between 0 and 100% intensity with the up/down
  # buttons.
  steps: "8"
  gamma_correct: "2.0" # Default gamma of 2.8 is generally too high.

binary_sensor:
  - platform: gpio
    # https://esphome.io/components/binary_sensor/gpio.html
    #name: "${friendly_name} Up Button"
    id: up_button
    pin:
      number: GPIO0
      inverted: True
      mode: INPUT_PULLUP
    on_press:
      # https://esphome.io/components/binary_sensor/index.html#on-press
      - if:
          condition:
            light.is_on: dimmer
          then:
            - lambda: !lambda |-
                // Similar to light.dim_relative but add the flashing.
                auto val = id(dimmer).remote_values.get_brightness();
                if (val >= (${steps}.0f-1.0f)/${steps}.0f) {
                  val = 1.0f;
                } else {
                  val += 1.0f/${steps}.0f;
                }
                auto call = id(dimmer).turn_on();
                call.set_brightness(val);
                call.perform();
                if (val == 1.f) {
                  id(flash_lights).execute();
                }
          else:
            - light.turn_on:
                id: dimmer
                brightness: "${long_press_up}"
    on_click:
      # https://esphome.io/components/binary_sensor/index.html#on-click
      min_length: ${long_press_min}
      max_length: ${long_press_max}
      then:
        - light.turn_on:
            id: dimmer
            brightness: "${long_press_up}"
  - platform: gpio
    # https://esphome.io/components/binary_sensor/gpio.html
    #name: "${friendly_name} Down Button"
    id: down_button
    pin:
      number: GPIO1
      inverted: True
      mode: INPUT_PULLUP
    on_press:
      # https://esphome.io/components/binary_sensor/index.html#on-press
      - if:
          condition:
            light.is_on: dimmer
          then:
            - lambda: !lambda |-
                // Similar to light.dim_relative but add the flashing.
                auto val = id(dimmer).remote_values.get_brightness();
                if (val <= 1.0f/${steps}.0f) {
                  val = .01f;
                } else {
                  val -= 1.0f/${steps}.0f;
                }
                auto call = id(dimmer).turn_on();
                call.set_brightness(val);
                call.perform();
                if (val == 0.01f) {
                  id(flash_lights).execute();
                }
          else:
            - light.turn_on:
                id: dimmer
                brightness: "${long_press_down}"
    on_click:
      # https://esphome.io/components/binary_sensor/index.html#on-click
      min_length: ${long_press_min}
      max_length: ${long_press_max}
      then:
        - light.turn_on:
            id: dimmer
            brightness: "${long_press_down}"
  - platform: gpio
    # https://esphome.io/components/binary_sensor/gpio.html
    #name: ${friendly_name} Main Button
    id: main_button
    pin:
      number: GPIO15
      mode: INPUT_PULLUP
    on_press:
      # TODO: Use "light.toggle: dimmer" instead of the code below if you want
      # to keep the previous brightness by default.
      # https://esphome.io/components/binary_sensor/index.html#on-press
      - if:
          condition:
            light.is_on: dimmer
          then:
            - light.turn_off: dimmer
          else:
            - light.turn_on:
                id: dimmer
                brightness: "${long_press_main}"
    on_click:
      # https://esphome.io/components/binary_sensor/index.html#on-click
      min_length: ${long_press_min}
      max_length: ${long_press_max}
      then:
        - light.turn_on:
            id: dimmer
            brightness: "${long_press_main}"

light:
  - platform: status_led
    id: ledred
    pin:
      number: GPIO4
      inverted: True
  - platform: monochromatic
    # https://esphome.io/components/light/monochromatic.html
    name: "${friendly_name}"
    id: dimmer
    output: pwm
    default_transition_length: ${no_delay}
    gamma_correct: "${gamma_correct}"
    effects:
      - flicker:
          name: "Flicker"
          alpha: 90%
          intensity: 25%
      - strobe:
          name: "Fast Pulse"
          colors:
            - state: true
              brightness: 100%
              duration: 500ms
            - brightness: 1%
              duration: 750ms
    on_state:
      - script.execute: set_lights

script:
  - id: set_lights
    then:
      - lambda: |-
          if (id(dimmer).remote_values.get_state() == 0.f) {
            id(led2).turn_off();
            id(led3).turn_off();
            id(led4).turn_off();
            id(led5).turn_off();
            // Comment the following line out if you don't want the red LED when
            // the dimmer is off.
            id(ledred).turn_on().perform();
            return;
          }
          id(ledred).turn_off().perform();
          auto val = id(dimmer).remote_values.get_brightness();
          if (val >= .1f) {
            id(led2).turn_on();
          } else {
            id(led2).turn_off();
          }
          if (val >= .36f) {
            id(led3).turn_on();
          } else {
            id(led3).turn_off();
          }
          if (val >= .73f) {
            id(led4).turn_on();
          } else {
            id(led4).turn_off();
          }
          if (val >= .9f) {
            id(led5).turn_on();
          } else {
            id(led5).turn_off();
          }
  - id: flash_lights
    then:
      - output.turn_on: led2
      - output.turn_on: led3
      - output.turn_on: led4
      - output.turn_on: led5
      - delay: 150ms
      - output.turn_off: led2
      - output.turn_off: led3
      - output.turn_off: led4
      - output.turn_off: led5
      - delay: 150ms
      - output.turn_on: led2
      - output.turn_on: led3
      - output.turn_on: led4
      - output.turn_on: led5
      - delay: 150ms
      - output.turn_off: led2
      - output.turn_off: led3
      - output.turn_off: led4
      - output.turn_off: led5
      - delay: 150ms
      - script.execute: set_lights

output:
  - platform: esp8266_pwm
    # https://esphome.io/components/output/esp8266_pwm.html
    power_supply: relay
    pin: GPIO13
    id: pwm
    # Even lower frequency can be used. 120 Hz works fine in 60 Hz countries.
    frequency: 300 Hz
    min_power: ${pwm_min_power}
  - platform: gpio
    # https://esphome.io/components/output/gpio.html
    id: led2
    pin: GPIO14
    inverted: true
  - platform: gpio
    id: led3
    pin: GPIO12
    inverted: true
  - platform: gpio
    id: led4
    pin: GPIO5
    inverted: true
  - platform: gpio
    id: led5
    pin: GPIO3
    inverted: true

power_supply:
  - id: relay
    # https://esphome.io/components/power_supply.html
    pin:
      number: GPIO16
      inverted: True
    enable_time: ${no_delay}
    keep_on_time: ${no_delay}    

Did you ever find an answer to this?
I have a bunch of MJ-SD01 switches and still have them all on tasmota because of this issue.
Setting the transition to 0 makes no difference, it still pauses for a second before it actually shuts off.
I have found some other threads on this, some people say it may be because of the power supply, but none have found a solution.
Since it shuts off immediately using tasmota/mqtt I don’t think it is a hardware issue.

I did not find a solution.
Though I have gotten used to the delay of a few seconds, it at least allows me to exit the room before it turns dark.

@carltonb I actually found the solution to this while looking at other threads.
There is a setting in my config “pwm_min_power” which was set at 15% by default.
I set this to 5% and I no longer have the delay. I guess it has something to do with how it does the dim down cycle before powering off.

  device_name: office-lights # hostname & entity_id
  friendly_name: Office Lights # Displayed in HA frontend
  pwm_min_power: 5% # keep dimming functional at lowest levels
  no_delay: 0s # transition when changing dimmer_lvl & relay delay
  transition_length: 0s # transition when turning on/off
  long_press_min: .4s # minimum time to activate long-press action
  long_press_max: 2s # maximum time to activate long-press action
  long_press_up: 100% # long press brightness
  long_press_down: 20% # long press brightness
  long_press_main: 50% # long press brightness

Thank you I will give it a try.