[ESPHOME] Light random effect on time / Mqqt topic subscribe

Hello,

i got 2 questions.

(Question 1)

I have got an Wemos and Led strip Ws2812b. i added some effects to it and i can controll it nicely.
i added this 2 “tasks” to turn an effect to ON at a specific time and set it to OFF after some seconds:

time:
  - platform: sntp
    id: sntp_time
    timezone: "Europe/Berlin"
    servers:
      - 0.pool.ntp.org
      - 1.pool.ntp.org
      - 2.pool.ntp.org

    on_time:
      - seconds: 0
        minutes: 0
        hours: '*'
        then:
        - light.turn_on:
            id: light_ring
            effect: "Rainbow Effect With Custom Values"

      - seconds: 5
        minutes: 0
        hours: '*'
        then:
        - light.turn_on:
            id: light_ring
            effect: "None"

but i would like to get and random effect from the list of effects i defined and not always “Rainbow Effect With Custom Values”

so is there a way to do that?

also it would be nice if the light would return to the state it was before the effect, so if it was off before the effect, turn if off again afterwards

somthing like:

  • 17:00:00 oclock
  • check light state, remember the state
  • do a random effect
  • 17:00:05 set effect to “None” and set rememberd state

(Question 2)

sofar i have got:

# Example configuration entry
mqtt:
  broker: 192.168.0.11
  port: 1885
  client_id: "TestLamp"
  topic_prefix: "TestLamp"

i would like to subscibe via mqqt to an topic i.e. “Wemos/OnOffState”.
values for OnOffState are “true” “false”.

if the topic “Wemos/OnOffState” is set to false, turn the light to off

i hope someone can help me, im a total beginner in EspHome and Home Assistant, and need to learn a lot

Thanks

ok i got the mqtt solved. i still need help with the first question.

if anyone new as me is interested, this is how i solved it:

mqtt:
  broker: 192.168.0.11
  port: 1885
  client_id: "TestLamp"
  topic_prefix: "TestLamp"
  on_message:
    topic: Wemos/OnOffState
    qos: 1
    then:
      - if:
          condition:
            lambda: 'return x == "true";'
          then:
            - light.turn_on:
                id: light_ring
          else:
            - light.turn_off: light_ring

ok i also got the “remember last state”:

globals:
  - id: led_off
    type: bool
    initial_value: 'true'


time:
  - platform: sntp
    id: sntp_time
    timezone: "Europe/Berlin"
    servers:
      - 0.pool.ntp.org
      - 1.pool.ntp.org
      - 2.pool.ntp.org

    on_time:
      - seconds: 0
        minutes: '*'
        hours: '*'
        then:
        - if:
            condition:
              light.is_on: light_ring
            then:
              - lambda: |-
                  id(led_off) = true;
            else:
              - lambda: |-
                  id(led_off) = false;
        - light.turn_on:
            id: light_ring
            effect: "Rainbow Effect With Custom Values"
        - delay: 5s
        - light.turn_on:
            id: light_ring
            effect: "None"
        - if:
            condition:
              - lambda: 'return id(led_off) == false;'
            then:
            - delay: 1s
            - light.turn_off:
                id: light_ring

now i only need to get an random effect from all effects i have set. hopefully someone can help, since im really dont know how to do that