277 lines
9.9 KiB
YAML
277 lines
9.9 KiB
YAML
#:########################################################################################:#
|
|
# TITLE: UNDERHOUSE STORAGE LIGHTS AUTO LIGHTS PACKAGE
|
|
#:########################################################################################:#
|
|
# DESCRIPTION:
|
|
# Replaces the Node-RED automation for the underhouse storage lights.
|
|
# Doors, PIR sensors, a remote switch, and local relay changes can start or
|
|
# extend a 1 hour lighting timer.
|
|
#
|
|
# VERSION:
|
|
# V1.0 2026-05-12
|
|
# - Initial Home Assistant package version.
|
|
#
|
|
# EDIT NOTES:
|
|
# - Add future door contacts in BOTH places marked FUTURE DOOR.
|
|
# - Add future PIR sensors in the PIR group marked FUTURE PIR.
|
|
# - The generated group entities used below should be:
|
|
# binary_sensor.underhouse_storage_door_contacts
|
|
# binary_sensor.underhouse_storage_pir_presence
|
|
#:########################################################################################:#
|
|
|
|
binary_sensor:
|
|
- platform: group
|
|
name: Underhouse Storage Door Contacts
|
|
unique_id: underhouse_storage_door_contacts
|
|
device_class: door
|
|
all: false
|
|
entities:
|
|
- binary_sensor.underhouse_stealth_door_x07rs_contact
|
|
- binary_sensor.underhouse_north_door_door
|
|
# FUTURE DOOR: add the next underhouse storage door contact here.
|
|
# - binary_sensor.underhouse_future_door_contact
|
|
|
|
- platform: group
|
|
name: Underhouse Storage PIR Presence
|
|
unique_id: underhouse_storage_pir_presence
|
|
device_class: occupancy
|
|
all: false
|
|
entities:
|
|
- binary_sensor.underhouse_pir_sensor_south_occupancy
|
|
# FUTURE PIR: uncomment this when the north PIR exists.
|
|
# - binary_sensor.underhouse_pir_sensor_north_occupancy
|
|
|
|
timer:
|
|
underhouse_storage_lights_runtime:
|
|
name: Underhouse Storage Lights Runtime
|
|
duration: "01:00:00"
|
|
restore: true
|
|
icon: mdi:timer-outline
|
|
|
|
script:
|
|
underhouse_storage_lights_start_runtime:
|
|
alias: Underhouse Storage Lights - Start Or Extend Runtime
|
|
mode: restart
|
|
sequence:
|
|
- choose:
|
|
- conditions:
|
|
- condition: state
|
|
entity_id: switch.esp_underhouselights_underhouse_storage_lights
|
|
state: "off"
|
|
sequence:
|
|
- action: switch.turn_on
|
|
target:
|
|
entity_id: switch.esp_underhouselights_underhouse_storage_lights
|
|
|
|
- action: timer.start
|
|
target:
|
|
entity_id: timer.underhouse_storage_lights_runtime
|
|
data:
|
|
duration: "0:20:00"
|
|
|
|
underhouse_storage_lights_stop_runtime:
|
|
alias: Underhouse Storage Lights - Stop Runtime
|
|
mode: restart
|
|
sequence:
|
|
- choose:
|
|
- conditions:
|
|
- condition: state
|
|
entity_id: switch.esp_underhouselights_underhouse_storage_lights
|
|
state: "on"
|
|
sequence:
|
|
- action: switch.turn_off
|
|
target:
|
|
entity_id: switch.esp_underhouselights_underhouse_storage_lights
|
|
|
|
- choose:
|
|
- conditions:
|
|
- condition: template
|
|
value_template: >-
|
|
{{ not is_state('timer.underhouse_storage_lights_runtime', 'idle') }}
|
|
sequence:
|
|
- action: timer.cancel
|
|
target:
|
|
entity_id: timer.underhouse_storage_lights_runtime
|
|
|
|
automation:
|
|
- id: underhouse_storage_lights_start_extend_runtime
|
|
alias: Underhouse Storage Lights - Start Or Extend Runtime
|
|
description: >-
|
|
Turns the storage lights on and starts or restarts the 1 hour timer when
|
|
a door opens, PIR detects occupancy, or the remote switch is pressed.
|
|
mode: restart
|
|
trigger:
|
|
- platform: state
|
|
entity_id: binary_sensor.underhouse_storage_door_contacts
|
|
to: "on"
|
|
- platform: state
|
|
entity_id: binary_sensor.underhouse_storage_pir_presence
|
|
to: "on"
|
|
- platform: state
|
|
entity_id: binary_sensor.esp_underhouselights_underhouse_storage_lights_remote_switch
|
|
to: "on"
|
|
action:
|
|
- action: script.underhouse_storage_lights_start_runtime
|
|
|
|
- id: underhouse_storage_lights_start_timer_when_relay_turned_on
|
|
alias: Underhouse Storage Lights - Start Timer When Relay Turned On
|
|
description: >-
|
|
Starts the timer if the relay is turned on locally by ESPHome or
|
|
by another Home Assistant automation.
|
|
mode: restart
|
|
trigger:
|
|
- platform: state
|
|
entity_id: switch.esp_underhouselights_underhouse_storage_lights
|
|
to: "on"
|
|
action:
|
|
- action: timer.start
|
|
target:
|
|
entity_id: timer.underhouse_storage_lights_runtime
|
|
data:
|
|
duration: "00:20:00"
|
|
|
|
- id: underhouse_storage_lights_timer_finished
|
|
alias: Underhouse Storage Lights - Timer Finished
|
|
description: >-
|
|
Turns the storage lights off after the runtime expires, even if a
|
|
door has been left open.
|
|
mode: single
|
|
trigger:
|
|
- platform: event
|
|
event_type: timer.finished
|
|
event_data:
|
|
entity_id: timer.underhouse_storage_lights_runtime
|
|
action:
|
|
- choose:
|
|
- conditions:
|
|
- condition: state
|
|
entity_id: switch.esp_underhouselights_underhouse_storage_lights
|
|
state: "on"
|
|
sequence:
|
|
- action: switch.turn_off
|
|
target:
|
|
entity_id: switch.esp_underhouselights_underhouse_storage_lights
|
|
|
|
- id: underhouse_storage_lights_cancel_timer_when_relay_off
|
|
alias: Underhouse Storage Lights - Cancel Timer When Relay Off
|
|
description: >-
|
|
Keeps the timer helper tidy if the relay is turned off manually, locally,
|
|
or by another automation.
|
|
mode: restart
|
|
trigger:
|
|
- platform: state
|
|
entity_id: switch.esp_underhouselights_underhouse_storage_lights
|
|
to: "off"
|
|
condition:
|
|
- condition: template
|
|
value_template: >-
|
|
{{ not is_state('timer.underhouse_storage_lights_runtime', 'idle') }}
|
|
action:
|
|
- action: timer.cancel
|
|
target:
|
|
entity_id: timer.underhouse_storage_lights_runtime
|
|
|
|
- id: underhouse_storage_lights_all_doors_closed
|
|
alias: Underhouse Storage Lights - All Doors Closed
|
|
description: >-
|
|
When all door contacts are closed, turn the lights off immediately if no
|
|
PIR occupancy is active. If PIR is still active, the PIR clear automation
|
|
below will turn them off after 60 seconds without occupancy.
|
|
mode: restart
|
|
trigger:
|
|
- platform: state
|
|
entity_id: binary_sensor.underhouse_storage_door_contacts
|
|
from: "on"
|
|
to: "off"
|
|
condition:
|
|
- condition: state
|
|
entity_id: binary_sensor.underhouse_storage_pir_presence
|
|
state: "off"
|
|
action:
|
|
- action: script.underhouse_storage_lights_stop_runtime
|
|
|
|
- id: underhouse_storage_lights_individual_door_closed_check
|
|
alias: Underhouse Storage Lights - Individual Door Closed No Motion Check
|
|
description: >-
|
|
When a real door contact closes, wait 60 seconds and then turn the relay
|
|
off only if all doors are closed and there is no PIR occupancy.
|
|
mode: restart
|
|
trigger:
|
|
- platform: state
|
|
entity_id:
|
|
- binary_sensor.underhouse_stealth_door_x07rs_contact
|
|
- binary_sensor.underhouse_north_door_door
|
|
# FUTURE DOOR: add the next underhouse storage door contact here too.
|
|
# - binary_sensor.underhouse_future_door_contact
|
|
from: "on"
|
|
to: "off"
|
|
action:
|
|
- delay: "00:01:00"
|
|
- condition: state
|
|
entity_id: binary_sensor.underhouse_storage_door_contacts
|
|
state: "off"
|
|
- condition: state
|
|
entity_id: binary_sensor.underhouse_storage_pir_presence
|
|
state: "off"
|
|
- condition: state
|
|
entity_id: switch.esp_underhouselights_underhouse_storage_lights
|
|
state: "on"
|
|
- action: script.underhouse_storage_lights_stop_runtime
|
|
|
|
- id: underhouse_storage_lights_pir_clear_after_doors_closed
|
|
alias: Underhouse Storage Lights - PIR Clear After Doors Closed
|
|
description: >-
|
|
If the doors are closed and PIR occupancy clears for 60 seconds, turn the
|
|
storage lights off.
|
|
mode: restart
|
|
trigger:
|
|
- platform: state
|
|
entity_id: binary_sensor.underhouse_storage_pir_presence
|
|
to: "off"
|
|
for: "00:01:00"
|
|
condition:
|
|
- condition: state
|
|
entity_id: binary_sensor.underhouse_storage_door_contacts
|
|
state: "off"
|
|
- condition: state
|
|
entity_id: switch.esp_underhouselights_underhouse_storage_lights
|
|
state: "on"
|
|
action:
|
|
- action: script.underhouse_storage_lights_stop_runtime
|
|
|
|
- id: underhouse_storage_lights_startup_sync
|
|
alias: Underhouse Storage Lights - Startup Sync
|
|
description: >-
|
|
On Home Assistant startup, re-sync the package state so an already-open
|
|
door or already-active PIR still controls the lights after a restart.
|
|
mode: single
|
|
trigger:
|
|
- platform: homeassistant
|
|
event: start
|
|
action:
|
|
- delay: "00:00:20"
|
|
- choose:
|
|
- conditions:
|
|
- condition: template
|
|
value_template: >-
|
|
{{
|
|
is_state('binary_sensor.underhouse_storage_door_contacts', 'on')
|
|
or is_state('binary_sensor.underhouse_storage_pir_presence', 'on')
|
|
or is_state('binary_sensor.esp_underhouselights_underhouse_storage_lights_remote_switch', 'on')
|
|
}}
|
|
sequence:
|
|
- action: script.underhouse_storage_lights_start_runtime
|
|
|
|
- conditions:
|
|
- condition: state
|
|
entity_id: switch.esp_underhouselights_underhouse_storage_lights
|
|
state: "on"
|
|
- condition: state
|
|
entity_id: timer.underhouse_storage_lights_runtime
|
|
state: "idle"
|
|
sequence:
|
|
- action: timer.start
|
|
target:
|
|
entity_id: timer.underhouse_storage_lights_runtime
|
|
data:
|
|
duration: "00:20:00"
|