3d printed LED lamp D1 mini with PIR motion sensor

Fun bathroom lamp project.
Designed and 3d printed a funky LED night light lamp.

AM312 PIR motion sensor $2.50

2812b LED Strip with 27 LED nodes. $5.00
D1 min wifi micro controller. $5.00

5v 4amp power supply $5.00
Home assistant with ESPhome

On bathroom counter

Motion sensor turns it on with automation in node red.
Changes to a warning strobe just before light shuts off if no motion.
Shuts off after no motion for 10 minutes.

Home assistant automation:

alias: motion lamp rainbow on
description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.bathroom_motion2_2
    from: "off"
    to: "on"
condition: []
action:
  - service: light.turn_on
    data:
      brightness_pct: 100
      profile: default
      effect: Rainbow
    target:
      entity_id: light.bathroom_lamp
  - delay:
      hours: 0
      minutes: 9
      seconds: 45
      milliseconds: 0
  - if:
      - condition: device
        type: is_on
        device_id: 5f1902fd3b0047a466f4ae48d19b08fb
        entity_id: light.bathroom_lamp
        domain: light
    then:
      - service: light.turn_on
        data:
          brightness: 255
          effect: Strobe Effect With Custom Values
        target:
          entity_id: light.bathroom_lamp
      - delay:
          hours: 0

I have moved most of my automations from Node Red to HA but here is my old flow.


Node red flow.

[{"id":"712cd2f1.82415c","type":"server-state-changed","z":"6dffafbd.e2808","name":"bathroom motion 10 minutes","server":"ceea5ac5.1b1658","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.bathroom_motion2_2","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"for":"10","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":120,"y":360,"wires":[["40f2b740.5d1c68"],[]]},{"id":"40f2b740.5d1c68","type":"api-call-service","z":"6dffafbd.e2808","name":"turn lamp off","server":"ceea5ac5.1b1658","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.bathroom_lamp","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":350,"y":360,"wires":[[]]},{"id":"7d7ba951.47e3b8","type":"api-call-service","z":"6dffafbd.e2808","name":"strobe warning light will shut off in  15 seconds","server":"ceea5ac5.1b1658","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.bathroom_lamp","data":"{\"effect\": \"Strobe Effect With Custom Values\"}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":480,"y":200,"wires":[[]]},{"id":"16be9d5.1569563","type":"api-call-service","z":"6dffafbd.e2808","name":"rainbow effect bathroom","server":"ceea5ac5.1b1658","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.bathroom_lamp","data":"{\"effect\": \"My rainbow\"}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":370,"y":100,"wires":[[]]},{"id":"fab928d8.832d08","type":"server-state-changed","z":"6dffafbd.e2808","name":"bathroom motion off 9.75 min","server":"ceea5ac5.1b1658","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.bathroom_motion2_2","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"for":"585","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":120,"y":200,"wires":[["28e4533c.489d3c"],[]]},{"id":"28e4533c.489d3c","type":"api-current-state","z":"6dffafbd.e2808","name":"is light on?","server":"ceea5ac5.1b1658","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.bathroom_lamp","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"x":270,"y":260,"wires":[["7d7ba951.47e3b8"],[]]},{"id":"49acc7fd57364b02","type":"comment","z":"6dffafbd.e2808","name":"bathroom LED lamp motion activation","info":"","x":190,"y":40,"wires":[]},{"id":"074e3ecf681d8105","type":"comment","z":"6dffafbd.e2808","name":"strobe worning if in shower for almost 10 min.","info":"","x":170,"y":160,"wires":[]},{"id":"8bcf1562bca4777b","type":"comment","z":"6dffafbd.e2808","name":"shut off lamp if no motion for 10 min.","info":"","x":140,"y":320,"wires":[]},{"id":"ceea5ac5.1b1658","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

** updated ESPhome Code.**

esphome:
  name: bathroom-lamp
  platform: ESP8266
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "eb74a1eb04e91ad5896cd610fdcd1013"

wifi:
  ssid: "smarthome1"
  password: "password"


  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Bathroom-Lamp Fallback Hotspot"
    password: "sLhtIU1ggkcF"

web_server:
  port: 80
      
captive_portal:
binary_sensor:
  - platform: gpio
    pin: D7
    name: "Bathroom Motion2"
    device_class: motion


#light:
  #- platform: neopixelbus
   # id: bathroom_lamp
   # name: "bathroom lamp Light"
   # internal: True
  #  pin: D4
   # num_leds: 27
 #   variant: WS2812
  #  type: GRB
light:
  - platform: neopixelbus
    id: bathroom_lamp
    type: GRB
    variant: WS2812
    pin: D4
    num_leds: 27
    name: "bathroom lamp Light"



 # - platform: fastled_clockless
 #   chipset: WS2812B
 #  pin: D4
 #   num_leds: 27
  #  rgb_order: GRB
  #  name: "FastLED WS2811 Light"       

    effects:
      - addressable_rainbow:
      - addressable_rainbow:
          name: Rainbow Effect With Custom Values
          speed: 20
          width: 75      
      - addressable_rainbow:
          name: My rainbow
          speed: 5
          width: 30     
          
      - addressable_color_wipe:
      - addressable_color_wipe:
          name: Color Wipe Effect With Custom Values
          colors:
            - red: 100%
              green: 100%
              blue: 100%
              num_leds: 1
            - red: 0%
              green: 0%
              blue: 0%
              num_leds: 1
          add_led_interval: 100ms
          reverse: False      
      - addressable_random_twinkle:
      - addressable_random_twinkle:
          name: Random Twinkle Effect With Custom Values
          twinkle_probability: 5%
          progress_interval: 32ms     
     
      - flicker:
      - flicker:
          name: Flicker Effect With Custom Values
          alpha: 95%
          intensity: 1.5%
        
      - strobe:
      - strobe:
          name: Strobe Effect With Custom Values
          colors:
            - state: True
              brightness: 100%
              red: 100%
              green: 90%
              blue: 0%
              duration: 500ms
            - state: False
              duration: 250ms
            - state: True
              brightness: 100%
              red: 0%
              green: 100%
              blue: 0%
              duration: 500ms

      - addressable_scan:
      - addressable_scan:
          name: Scan Effect With Custom Values
          move_interval: 100ms
          scan_width: 1
      - addressable_twinkle:
      - addressable_twinkle:
          name: Twinkle Effect With Custom Values
          twinkle_probability: 5%
          progress_interval: 4ms       

      - addressable_fireworks:
      - addressable_fireworks:
          name: Fireworks Effect With Custom Values
          update_interval: 32ms
          spark_probability: 10%
          use_random_color: false
          fade_out_rate: 120          


#Exposes control buttons
button:
  - platform: restart
    icon: mdi:power-cycle
    name: "ESP Reboot"

time:
  - platform: sntp
    id: time_sntp

sensor:

################ diag ###################   


    #Device UPTIME
  - platform: uptime
    name: Uptime
    id: sys_uptime
    update_interval: 60s
  
    #Device RSSI
  - platform: wifi_signal
    name: RSSI
    id: wifi_signal_db
    update_interval: 60s
    entity_category: "diagnostic"    

3d printing info.
i only had white in PETG would have looked better in PLA.
lamp base1

tinker with tinkercad
[tinkercad ](tinker with tinkercad 3D design LED lamp_3 pieces | Tinkercad)

Thingiverse page.
thingiverse sti file and info

2 Likes

Hi, trying to do something similar. Will be able to share how you connected the led strips and the PIR to the wemos?

Thanks
Fred

I have since changed motion automation from node red to to home assistant UI

alias: motion lamp rainbow on
description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.bathroom_motion2_2
    from: "off"
    to: "on"
condition: []
action:
  - service: light.turn_on
    data:
      brightness_pct: 100
      profile: default
      effect: Rainbow
    target:
      entity_id: light.bathroom_lamp
  - delay:
      hours: 0
      minutes: 9
      seconds: 45
      milliseconds: 0
  - if:
      - condition: device
        type: is_on
        device_id: 5f1902fd3b0047a466f4ae48d19b08fb
        entity_id: light.bathroom_lamp
        domain: light
    then:
      - service: light.turn_on
        data:
          brightness: 255
          effect: Strobe Effect With Custom Values
        target:
          entity_id: light.bathroom_lamp
      - delay:
          hours: 0
          minutes: 0
          seconds: 15
          milliseconds: 0
      - type: turn_off
        device_id: 5f1902fd3b0047a466f4ae48d19b08fb
        entity_id: light.bathroom_lamp
        domain: light
    else: []
mode: restart

Updated ESP home code and automation for HA automation off of Node Red.