Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yousaf465/acf3ac301174b4bbfe0da58896b8b8a8 to your computer and use it in GitHub Desktop.
Save yousaf465/acf3ac301174b4bbfe0da58896b8b8a8 to your computer and use it in GitHub Desktop.
Bathroom door light sensor. yaml
blueprint:
name: ZBMINIR2 Control via Door Sensor + 45min Auto-Off
description: >
Turns ON a relay (e.g., Sonoff ZBMINIR2) when a door opens, OFF when door opens again,
or after 45 minutes if left ON. Single automation solution.
domain: automation
input:
door_sensor:
name: Door Sensor
selector:
entity:
domain: binary_sensor
device_class: door
relay_switch:
name: Relay Switch (e.g., ZBMINIR2)
selector:
entity:
domain: switch
auto_off_minutes:
name: Auto-Off Timer (in minutes)
description: Delay after which the relay should be turned off if left ON
default: 45
selector:
number:
min: 1
max: 180
unit_of_measurement: minutes
trigger:
- platform: state
entity_id: !input door_sensor
from: "off"
to: "on"
id: door_opened
- platform: state
entity_id: !input relay_switch
to: "on"
id: relay_on
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: door_opened
sequence:
- service: switch.turn_on
target:
entity_id: !input relay_switch
- wait_for_trigger:
- platform: state
entity_id: !input door_sensor
from: "off"
to: "on"
timeout: !input auto_off_minutes
continue_on_timeout: true
- choose:
- conditions:
- condition: state
entity_id: !input relay_switch
state: "on"
sequence:
- service: switch.turn_off
target:
entity_id: !input relay_switch
- conditions:
- condition: trigger
id: relay_on
sequence:
- wait_for_trigger:
- platform: state
entity_id: !input relay_switch
to: "off"
timeout: !input auto_off_minutes
continue_on_timeout: true
- choose:
- conditions:
- condition: state
entity_id: !input relay_switch
state: "on"
sequence:
- service: switch.turn_off
target:
entity_id: !input relay_switch
mode: restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment