Some time back I mounted some addressable LED’s under my daughters bed, connected via a PIR so when our daughter got out of bed at night the lights would act as a night light. The code I created is average but it works.
Recently I’ve tried to create some new code, with the idea that when the PIR activates the LED’s they use a random lighting pattern. Despite some weeks of trying… I cannot get the code to work.
Here’s the code to activate the LED’s below…
light:
- platform: neopixelbus
variant: WS2812
pin: D1
num_leds: 54
type: GRB
name: "FastLED WS2812B Light"
id: bdrm_led_lights
default_transition_length: 7.5s
binary_sensor:
- platform: gpio
pin: D5
id: bdrm_pir
name: "Bdrm PIR Sensor"
device_class: motion
on_press:
then:
- if:
condition:
and:
# If it's night time
- sun.is_below_horizon:
- lambda: |-
auto hour = id(my_time).now().hour;
return hour > 12 || hour < ${off_hour};
then:
#Turn on the LED lights
- light.turn_on:
id: bdrm_led_lights
brightness: 40%
effects:
- random:
- random:
name: "Slow Random Effect"
transition_length: 30s
update_interval: 20s
- random:
name: "Fast Random Effect"
transition_length: 4s
update_interval: 5s
- pulse:
- pulse:
name: "Fast Pulse"
transition_length: 0.5s
update_interval: 0.5s
- pulse:
name: "Slow Pulse"
# transition_length: 1s # defaults to 1s
update_interval: 2s
- addressable_rainbow:
- addressable_rainbow:
name: "Rainbow Effect"
speed: 10
width: 50
- addressable_color_wipe:
- addressable_color_wipe:
name: "Color Wipe Effect"
colors:
- red: 10%
green: 90%
blue: 25%
num_leds: 5
- red: 35%
green: 15%
blue: 60%
num_leds: 1
add_led_interval: 100ms
reverse: false
- addressable_fireworks:
- addressable_fireworks:
name: "Fireworks Effect"
update_interval: 32ms
spark_probability: 10%
use_random_color: true
fade_out_rate: 120
- addressable_scan:
- addressable_scan:
name: "Scan Effect"
move_interval: 100ms
scan_width: 5
- addressable_random_twinkle:
- addressable_random_twinkle:
name: Random "Twinkle Effect"
twinkle_probability: 15%
progress_interval: 32ms
- logger.log: "LED lights are ON"
on_release:
- script.execute: turn_off
script:
- id: turn_off
mode: restart
then:
- delay: 90s
- light.turn_off:
id: bdrm_led_lights
transition_length: 7.5s
- logger.log: "LED lights are OFF"
ESPHome wont let me save the code because I receive error: [effects] is an invalid option for [light.turn_on]. Did you mean [effect]?
Perhaps there’s something I am missing, or I have completely gone down the wrong road?
Thanks, Mark