Light Effect - Random On/Off

I thought this would be easy, but for the life of me I cannot come anywhere close. I want to set up several monochromatic lights each having a random on/off effect. I.e. they would fade on, stay on for some random seconds, fade off, stay off for some random seconds, repeat. Alternately, they could just fade to a low brightness, if “off” within an effect is an issue…

I get as far as having a light that does turn on/off from HA. I’ve toyed with versions of the effect below, which would be a fixed 3 second cycle, as the next step. The effect does nothing other than sometimes changing the state in HA (the physical light does nothing).

  - platform: monochromatic
    name: "Light1"
    id: light_1
    output: led_white_output_1    
    effects:
      - lambda:
          name: "Random On/Off"
          lambda: |-
            id(light_1).turn_on().set_brightness(1.0).set_transition_length(1000).perform();
            esphome::delay_microseconds_safe(3000000);
            id(light_1).turn_on().set_brightness(0.1).set_transition_length(1000).perform();
            esphome::delay_microseconds_safe(3000000);

What am I doing wrong?

can you create two helpers, one Random, and then a Timer that is based on the Random?

You can just create an helper as Random → Random Sensor → name it, give the minimum minutes, maximum minutes, set device class as duration, set unit of measurement to min.

Now you have an entity that updates between minimum and maximum randomly. Use that value at the time of kicking off the timer.

Thanks for the suggestion, but I really want to keep all the logic on the ESP32 chip. In the end, I’ll probably just expose a switch to HA to turn on/off the effect but let the randomization run by ESPHome, so that that traffic is kept to a minimum.

Which leads me to think…maybe I’ll just try a script in ESPHome and not bother with the effects configuration.