Toggle random lights from a single button

I’m prototyping a magic wand (wemos d1, accelerometer, battery - using esphome) for my daughter, the idea being she can wave it around, and lights will magically turn on and off.

So i’d like to have a button (or script, or something I can trigger) which will toggle lights from a given list. I’ve found lots of posts about having random length delays and such, but nothing where the entities are actually randomised.

Any pointers on how I would get started with this? Thanks!

trigger:
  - platform: state
    entity_id: binary_sensor.wand
    to: 'on'
condition: []
action:
  - variables:
      lights:
        - light.living_room
        - light.bedroom
  - service: light.toggle
    target:
      entity_id: "{{ lights|random }}"
1 Like

perfect! thank you!