Files
zorruno-homeassistant/packages/office_lights_power_backup_occupancy.yaml
T
2026-08-30 00:25:42 +12:00

201 lines
8.1 KiB
YAML

################################################################################
# PACKAGE: Office Power Backup Occupancy Automation
################################################################################
#
# Version:
# - 1.2 - 2026-08-16
# - Removed the spare-button trigger after false presses caused unintended
# power toggles.
# - Retains occupancy-based backup control for Office power supplies.
#
# - 1.1 - 2026-07-25
# - Stripped light control (now handled by direct MQTT)
# - Retains power supply backup control only
#
# - 1.0 - 2026-04-25
# - Initial package version.
# - Backup automation for Office lights and Office power.
# - Uses Office mmWave occupancy as the normal trigger.
# - Uses Office spare button / relay as a backup manual master.
#
# Operation:
# - Turns Office power supplies on when the Office mmWave occupancy sensor
# detects occupancy or movement.
#
# - Turns Office power supplies off after the Office mmWave occupancy sensor
# has been clear for the configured delay period.
#
# Notes:
# - This is treated as a BACKUP automation for POWER SUPPLIES ONLY.
# - Light control is handled by direct ESPHome/MQTT (see device YAMLs).
#
################################################################################
################################################################################
# USER SETTINGS / PACKAGE VARIABLES
################################################################################
input_number:
office_lights_backup_clear_delay_seconds:
name: "Office Power Backup Clear Delay Seconds"
min: 0
max: 3600
step: 1
mode: box
unit_of_measurement: s
icon: mdi:timer-outline
initial: 600
################################################################################
# AUTOMATIONS
################################################################################
automation:
- id: office_power_backup_occupancy_control
alias: "Office Power - Backup Occupancy Control"
description: >
Backup automation for Office power supplies. Turns power on when Office
mmWave occupancy or movement is detected. Turns power off after the
occupancy sensor is clear for the configured delay period. Light control
is handled by direct ESPHome/MQTT sync.
mode: restart
triggers:
##########################################################################
# Occupancy detected.
##########################################################################
- trigger: state
entity_id: binary_sensor.esp_occupancyoffice_mmwave_occupancy_or_movement
to: "on"
id: occupancy_detected
##########################################################################
# Occupancy clear.
##########################################################################
- trigger: state
entity_id: binary_sensor.esp_occupancyoffice_mmwave_occupancy_or_movement
to: "off"
id: occupancy_clear
##########################################################################
# Startup check.
#
# If HA starts while the Office is already clear, this allows the normal
# off-delay logic to run.
##########################################################################
- trigger: homeassistant
event: start
id: ha_startup_check
actions:
- choose:
######################################################################
# ON LOGIC:
# Occupancy detected - turn power supplies on.
######################################################################
- alias: "Occupancy detected - turn Office power on"
conditions:
- condition: trigger
id: occupancy_detected
sequence:
##############################################################
# Power supplies.
##############################################################
- alias: "Turn on Office ELV power supply if needed"
if:
- condition: state
entity_id: switch.esp_officeelvcontrol_office_elv_power_supply
state: "off"
then:
- action: switch.turn_on
target:
entity_id: switch.esp_officeelvcontrol_office_elv_power_supply
- alias: "Turn on Office right hand GPO if needed"
if:
- condition: state
entity_id: switch.esp_officedeskrightgpo_office_right_hand_gpo
state: "off"
then:
- action: switch.turn_on
target:
entity_id: switch.esp_officedeskrightgpo_office_right_hand_gpo
##############################################################
# Manual master/latch relay.
##############################################################
- alias: "Turn on Office spare relay master if needed"
if:
- condition: state
entity_id: switch.esp_officelights_relay_3_spare
state: "off"
then:
- action: switch.turn_on
target:
entity_id: switch.esp_officelights_relay_3_spare
######################################################################
# OFF LOGIC:
# Occupancy clear - wait, re-check, then turn power supplies off.
######################################################################
- alias: "Occupancy clear - wait, re-check, then turn Office power off"
conditions:
- condition: template
value_template: >
{{
trigger.id in [
'occupancy_clear',
'ha_startup_check'
]
}}
- condition: state
entity_id: binary_sensor.esp_occupancyoffice_mmwave_occupancy_or_movement
state: "off"
sequence:
- delay:
seconds: >
{{
states('input_number.office_lights_backup_clear_delay_seconds')
| int(600)
}}
# Re-check after the delay in case occupancy returned.
- condition: state
entity_id: binary_sensor.esp_occupancyoffice_mmwave_occupancy_or_movement
state: "off"
##############################################################
# Power off.
##############################################################
- alias: "Turn off Office right hand GPO if needed"
if:
- condition: state
entity_id: switch.esp_officedeskrightgpo_office_right_hand_gpo
state: "on"
then:
- action: switch.turn_off
target:
entity_id: switch.esp_officedeskrightgpo_office_right_hand_gpo
- alias: "Turn off Office ELV power supply if needed"
if:
- condition: state
entity_id: switch.esp_officeelvcontrol_office_elv_power_supply
state: "on"
then:
- action: switch.turn_off
target:
entity_id: switch.esp_officeelvcontrol_office_elv_power_supply
##############################################################
# Manual master/latch relay off last.
##############################################################
- alias: "Turn off Office spare relay master if needed"
if:
- condition: state
entity_id: switch.esp_officelights_relay_3_spare
state: "on"
then:
- action: switch.turn_off
target:
entity_id: switch.esp_officelights_relay_3_spare