Flashing a light output relay

ok, I feel really dumb here, I just cannot get a binary output light to have an effect where it flashes on and off continuously. I have a traffic light, with 3 relays, and it’s all working great aside from the effects.

My working code without flashing is at home-assistant-config/esphome/traffic-light.yaml at 57f4c801b56838a73fb2a3f8d2cc892b12a44deb · kylegordon/home-assistant-config · GitHub

When I add the following stanza, it performs the steps up to any point where light.turn_off is called

  - automation:
      name: Amber Flashing
      sequence:
        - light.turn_on: amber
        - delay: 5s
        - light.turn_off: amber
        - delay: 5s

I can’t use pulse on a binary output light, and using switch.turn_off to change the underlying relay/gpio results in inheritance errors

Any thoughts?

I thought I would just add some ‘flashing red’ ‘flashing amber’ effects to the traffic light, but I’m wondering if those effects will rather have to be built into a switch that manipulates the light, instead of an effect within the light.

I would use a script:

script:
  - id: amber_flash
    then:
    - while:
        # forever
        condition:
          lambda: |-
            return true;  
        then:
          - light.turn_on: amber
          - delay: 5s
          - light.turn_off: amber
          - delay: 5s

Start the script when required:

on_...:
  then:
    - script.start: amber_flash

Then stop it when no longer required, remembering to turn off the amber as the state may be on:

on_...:
  then:
    - script.stop: amber_flash
    - light.turn_off: amber
1 Like