Can someone help me with a switch configuration to control lighting that doesn't seem to be working

I’ve got a very custom high current/voltage lighting system for a tropical environment that houses a lot of reptiles. I built my own controller for that side and it works great. I take a PWM input so that I can feed it control signal from basically anything. So I started to look at porting the logic over to ESPHome because it gives me such a convenient way to manage it all and everything I’ve done already has been 8266/32 based. Ok. so here is where I am:

# Main terrarium lights
output:
  - platform: ledc
    pin: GPIO23
    id: terrarium_light_output
    frequency: "1000Hz"

light:
  - platform: monochromatic
    name: "Terrarium Lights - Fade"
    id: terrarium_lights_fade
    output: terrarium_light_output
    default_transition_length: 1800s
  - platform: monochromatic
    name: "Terrarium Lights - Fast"
    id: terrarium_lights_fast
    output: terrarium_light_output
    default_transition_length: 1s

# AC controlled basking lights TODO

## Override Buttons for terrarium lights##
binary_sensor:
  # Lights On
  - platform: gpio
    pin:
      number: 22
      mode: INPUT_PULLUP
      inverted: True
    name: "swFASTON"
    filters:
      - delayed_on: 10ms  
    on_press:
      then:
        - light.turn_on: terrarium_lights_fast

The long fade is to emulate dusk and dawn and that works pretty good. But I need a series of buttons that will allow me to override the state. The obvious two at the moment are ON and OFF. On immediately setting the lights to full brightness and OFF turning them all off immediately. I’ve been experimenting with binary switches because they seem like the obvious choice. But what I get is on button push, the light immediately turns on. But as soon as I release the button it turns off. And I can see that in my logs:

** push the button **
[20:37:01][D][binary_sensor:036]: 'swFASTON': Sending state ON
[20:37:01][D][light:036]: 'Terrarium Lights - Fast' Setting:
[20:37:01][D][light:047]:   State: ON
[20:37:01][D][light:085]:   Transition length: 1.0s
** release the button **
[20:37:01][D][binary_sensor:036]: 'swFASTON': Sending state OFF

Could anyone guide me in the right direction?

That should not happen. You have no on_release action defined so nothing should happen when you release the button.

binary_sensor:
  # Lights On
  - platform: gpio
    pin:
      number: 22
      mode: INPUT_PULLUP
      inverted: True
    name: "swFASTON"
    filters:
      - delayed_on: 10ms  
    on_press:
      then:
        - light.turn_on: terrarium_lights_fast

Not sure what is going on but I’d change that debounce filter to - delayed_off: 10ms it will acheive the same thing, but faster.

well after hammering on this again I basically just started all over. Deleted the device and everything. I don’t know what changed but when I added it all back in it started working again. hmm.

However I have now discovered a different problem. When the state is transitioning on or off, the button push turns the light on as expected but then the light is immediately put back into wherever the long “on” transition is at. Is it possible so that the button push overrides an ongoing transition? It looks like the transition state isn’t like “transitioning” it’s just “on” so I can’t just alter the state with like a lambda.

Hmm. I don’t think it is possible.

You could change your light entities to light effects and just have one light. That way when you start a new effect (i.e. fast on) it should override the existing effect (slow on).