Automatic cabinet light control with ZHA Aqara contacts and WLED leds

I have a small setup with a big cabinet with two sliding doors. I added an Aqara door sensor to both to see if they are open or closed. There is also a LED strip in each one controlled by WLED on a NodeMCU.

I wrote this sketch to automatically turn on/off the lights based on the contact. Should be usable for all similar projects.

blueprint:
  name: Door-activated cabinet light
  description: Turns on a light when the cabinet is openend, turns it off again onces it is closed
  domain: automation
  source_url: https://github.com/OliverHi/blueprints/cabinet_light.yaml
  input:
    door_entity:
      name: Door magnet open/closed Sensor
      selector:
        entity:
          domain: binary_sensor
          device_class: opening
    light_target:
      name: Light
      selector:
        target:
          entity:
            domain: light

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

trigger:
  - platform: state
    entity_id: !input door_entity
    to: "on"
  - platform: state
    entity_id: !input door_entity
    to: "off"

action:
  - service: light.turn_{{trigger.to_state.state | lower}}
    target: !input light_target

All (possible) updates can be found here: https://github.com/OliverHi/blueprints/blob/be6135e874b7fb015463ca5d37ba4fcb1cb409a7/cabinet_light.yaml

3 Likes

Great idea!

I have an idea to improve it: maybe you could add the safety when the cabinet is not closed after 5 minutes, the lights turn automatically off. In case you forget to close the cabinet.

How would you change it in order to consider that?

1 Like