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