Under Bed Motion Sensor and Path-Light

I recently lined my bed with 794 sk6812 addressable LEDs. This has evolved from original white IKEA LEDs, to Hue RGB LED strips, to finally this. With WLED and Home Assistant, you can have a very cool disco-in-the-bedroom. Eventually, I’d like to get them tied into the music and the TV, but those are projects down the road.


This picture does not do the lighting justice.

Watching my partner repeatedly stumble and bang her feet when she got out of bed in the dark gave me an idea to turn the glitz into something utilitarian. I’ve been playing with a variety of different motion sensors in other applications and finally settled on the HC-SR501. These are tunable and work great IF you run the 3.3V power to the pin next to the jumper instead of trying to use 5V through the regulator. This is further described in this YouTube video..

So I took two HC-SR501, one Wemos d1mini and hooked it all together. I positioned the two sensors to point out underneath the bed towards the space on either side. Initially, I had the sensitivity cranked all the way down (7:00), but I’ve settled on 11:00. I have the response pot all the way down for quick response with on and off.


Everything wired up and soldered. I realized later that the blue & purple needed to be swapped, so ignore that. I used D1 and D2 for the sensor inputs on the d1mini.


The two HC-SR501 sensors. Do not use the 5V pin, run 3.3V to the pin next to the jumper.


Everything under the bed and positioned. Powered by the Meanwell 40A 5V supply that powers the LEDs. Extra credit if you make cases for everything. It is somewhat flimsy now in that the sensors could potentially move from their positions and angles.


From outside the bed on one side. You can see the d1mini/QuinnLED-UNO that runs WLED on the right as well as some of the injection wiring for powering the whole strip, and the Meanwell LRS-200-5 40A 5V power supply. Yes, that is a subwoofer to the left.

Here is the esphome code:

substitutions:
  device_name: masterbed_motion
  friendly_name: "Master Bed Motion"

esphome:
  name: ${device_name}
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "WIFI SSID"
  password: "WIFI PASSWORD"

logger:
api:
ota:

status_led:
  pin: GPIO2
  
sensor:
  - platform: wifi_signal
    name: "${friendly_name} WiFi Signal"
    update_interval: 60s

binary_sensor:
  - platform: gpio
    pin: D1
    name: "${friendly_name} West"
    id: ${device_name}_west
    device_class: motion
  - platform: gpio
    pin: D2
    name: "${friendly_name} East"
    id: ${device_name}_east
    device_class: motion

In setting up the automations for Home Assistant, I wanted a number of rules. If WLED was already doing a pattern, I didn’t want it to shift to the muted preset if motion happened. I also didn’t want the path-light to occur if the lights were already on in the room, and if any lights got turned on, to shut off the path-light immediately. This required an input_boolean to determine if WLED had been turned on manually or by motion.

The reason I split this into two different automations for either side of the bed is that I was hoping to use WLED segments to light either side. However, there appears to be a bug in WLED segments that crashes the whole thing if you have as many LEDs as I do and you do more than two segments. I don’t know if they behave any better on a ESP32. It works well enough for me to light the whole strip now.

I’ve found that the “Theater” and the “Candle” effects are good for this, with red & blue colors. It provides enough texture and if the effect is slowed, it isn’t jarring to the midnight eye. I dim the whole thing enough that the light doesn’t disturb the other person in bed.

input_boolean:
  master_bed_motion:
    name: "Master Bed Motion"

automation:
  - alias: Light Master Bed East Motion On
    trigger:
      platform: state
      entity_id:
        - binary_sensor.master_bed_motion_east
      to: 'on'
      from: 'off'
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id:
            - light.master_border
            - light.master_closet
            - light.master_bed_sidetable
            - light.master_bed_lightstrip
            - input_boolean.master_bed_motion
          state: 'off'
        - condition: state  # from sunset until sunrise
          entity_id: sun.sun
          state: 'below_horizon'
    action:
      - service: wled.preset
        data:
          entity_id: light.master_bed_lightstrip
          preset: 6
      - service: light.turn_on
        data:
          entity_id: light.master_bed_lightstrip
          brightness_pct: 20
      - service: input_boolean.turn_on
        entity_id: input_boolean.master_bed_motion
  
  - alias: Light Master Bed East Motion Off
    trigger:
      platform: state
      entity_id:
        - binary_sensor.master_bed_motion_east
      to: 'off'
      for:
        minutes: 5
    condition:
      condition: state
      entity_id: input_boolean.master_bed_motion
      state: 'on'
    action:                   
      - service: light.turn_off
        entity_id: light.master_bed_lightstrip
      - service: input_boolean.turn_off
        entity_id: input_boolean.master_bed_motion
  
  - alias: Light Master Bed West Motion On
    trigger:
      platform: state
      entity_id:
        - binary_sensor.master_bed_motion_west
      to: 'on'
      from: 'off'
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id:
            - light.master_border
            - light.master_closet
            - light.master_bed_sidetable
            - light.master_bed_lightstrip
            - input_boolean.master_bed_motion
          state: 'off'
        - condition: state  # from sunset until sunrise
          entity_id: sun.sun
          state: 'below_horizon'
    action:
      - service: wled.preset
        data:
          entity_id: light.master_bed_lightstrip
          preset: 6
      - service: light.turn_on
        data:
          entity_id: light.master_bed_lightstrip
          brightness_pct: 20
      - service: input_boolean.turn_on
        entity_id: input_boolean.master_bed_motion
  
  - alias: Light Master Bed West Motion Off
    trigger:
      platform: state
      entity_id:
        - binary_sensor.master_bed_motion_west
      to: 'off'
      for:
        minutes: 5
    condition:
      condition: state
      entity_id: input_boolean.master_bed_motion
      state: 'on'
    action:                   
      - service: light.turn_off
        entity_id: light.master_bed_lightstrip
      - service: input_boolean.turn_off
        entity_id: input_boolean.master_bed_motion
        
  - alias: Light Master Any Light On Bed Motion Off
    trigger:
      platform: state
      entity_id:
        - light.master_border
        - light.master_closet
        - light.master_bed_sidetable
      to: 'on'
    condition:
      condition: state
      entity_id: input_boolean.master_bed_motion
      state: 'on'
    action:                   
      - service: light.turn_off
        entity_id: light.master_bed_lightstrip
      - service: input_boolean.turn_off
        entity_id: input_boolean.master_bed_motion
12 Likes

Small note. I eventually got rid of the HC-SR501 in favor of AM312 sensors. There are too many problems with the HC-SR501 sensors to make them useful.