changes to esphome devices and packages to start removing node red dependencies

This commit is contained in:
root
2026-04-25 21:05:32 +12:00
parent 51bff34d2e
commit 15f348570f
71 changed files with 1322 additions and 202 deletions
@@ -0,0 +1,127 @@
################################################################################
# PACKAGE: Laundry Lights Backup Occupancy Automation
################################################################################
#
# Operation:
# - Turns Laundry lights on when either of these sensors becomes active:
# - Laundry cupboard/wall PIR from ESPHome laundry environment device
# - Backup ceiling PIR from Zigbee
#
# - Turns Laundry lights off only after BOTH PIRs are clear for the configured
# delay period.
#
# Notes:
# - This is treated as a BACKUP automation.
# - The ESPHome devices should normally communicate directly via MQTT.
# - The wall PIR should still operate the lights with MQTT only.
# - This HA automation provides a fallback path using HA entity states.
#
################################################################################
################################################################################
# USER SETTINGS / PACKAGE VARIABLES
################################################################################
input_number:
laundry_lights_backup_clear_delay_seconds:
name: "Laundry Lights Backup Clear Delay Seconds"
min: 0
max: 3600
step: 1
mode: box
unit_of_measurement: s
icon: mdi:timer-outline
initial: 240
################################################################################
# AUTOMATIONS
################################################################################
automation:
- id: laundry_lights_backup_occupancy_control
alias: "Laundry Lights - Backup Occupancy Control"
description: >
Backup automation for Laundry lights. Turns lights on when either the
ESPHome wall/cupboard PIR or Zigbee ceiling PIR detects movement/occupancy.
Turns lights off after both PIRs are clear for the configured delay period.
mode: restart
triggers:
# Either PIR becoming active turns the Laundry lights on.
- trigger: state
entity_id: binary_sensor.esp_laundryenv_laundry_pir
to: "on"
id: laundry_wall_pir_detected
- trigger: state
entity_id: binary_sensor.laundry_ceiling_pir_x03ir_occupancy
to: "on"
id: laundry_ceiling_pir_detected
# Either PIR becoming clear causes a check. The action only continues
# to the off-delay when BOTH PIRs are clear.
- trigger: state
entity_id:
- binary_sensor.esp_laundryenv_laundry_pir
- binary_sensor.laundry_ceiling_pir_x03ir_occupancy
to: "off"
id: laundry_pir_clear_check
# On HA startup, re-evaluate the current state. This prevents lights
# staying on indefinitely if HA restarted while the room was already clear.
- trigger: homeassistant
event: start
id: ha_startup_check
actions:
- choose:
######################################################################
# ON LOGIC:
# If either PIR is active, turn the Laundry lights on immediately.
######################################################################
- alias: "Turn lights on if either Laundry PIR is active"
conditions:
- condition: template
value_template: >
{{
is_state('binary_sensor.esp_laundryenv_laundry_pir', 'on')
or is_state('binary_sensor.laundry_ceiling_pir_x03ir_occupancy', 'on')
}}
sequence:
- action: switch.turn_on
target:
entity_id: switch.esp_laundrylights_relay_1_laundry_lights
######################################################################
# OFF LOGIC:
# Only start the off-delay if BOTH PIRs are clear.
# After the delay, check both PIRs again before switching off.
######################################################################
- alias: "Wait, then turn lights off if both Laundry PIRs remain clear"
conditions:
- condition: template
value_template: >
{{
is_state('binary_sensor.esp_laundryenv_laundry_pir', 'off')
and is_state('binary_sensor.laundry_ceiling_pir_x03ir_occupancy', 'off')
}}
sequence:
- delay:
seconds: >
{{
states('input_number.laundry_lights_backup_clear_delay_seconds') | int(240)
}}
# Re-check after the delay in case either PIR became active again.
- condition: template
value_template: >
{{
is_state('binary_sensor.esp_laundryenv_laundry_pir', 'off')
and is_state('binary_sensor.laundry_ceiling_pir_x03ir_occupancy', 'off')
}}
# Only send OFF if the Laundry lights are currently ON.
- condition: state
entity_id: switch.esp_laundrylights_relay_1_laundry_lights
state: "on"
- action: switch.turn_off
target:
entity_id: switch.esp_laundrylights_relay_1_laundry_lights
@@ -0,0 +1,523 @@
################################################################################
# PACKAGE: Office Lights And Power Backup Occupancy Automation
################################################################################
#
# Version:
# - 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 lights and power on when the Office mmWave occupancy sensor
# detects occupancy or movement.
#
# - Turns Office lights and power off after the Office mmWave occupancy sensor
# has been clear for the configured delay period.
#
# - Provides a backup manual control path using the Office spare button.
# This is useful if the occupancy sensor is offline.
#
# Notes:
# - This is treated as a BACKUP automation.
# - The standard method should still be the direct ESPHome/MQTT control path.
# - This HA automation provides a fallback path using HA entity states.
# - The physical spare button is read using:
# binary_sensor.esp_officelights_button_3_spare
# - The spare relay is used as the manual master/latch state:
# switch.esp_officelights_relay_3_spare
#
################################################################################
################################################################################
# USER SETTINGS / PACKAGE VARIABLES
################################################################################
input_number:
office_lights_backup_clear_delay_seconds:
name: "Office Lights 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_lights_power_backup_occupancy_control
alias: "Office Lights And Power - Backup Occupancy Control"
description: >
Backup automation for Office lights and power. Turns required devices on
when Office mmWave occupancy or movement is detected. Turns them off after
the occupancy sensor is clear for the configured delay period. Also allows
manual backup toggling using the Office spare button and spare relay.
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
##########################################################################
# Manual backup button press.
#
# The spare relay state is used as the master/latch:
# - If spare relay is OFF when the button is pressed, turn everything ON.
# - If spare relay is ON when the button is pressed, turn everything OFF.
##########################################################################
- trigger: state
entity_id: binary_sensor.esp_officelights_button_3_spare
from: "off"
to: "on"
id: backup_button_pressed
##########################################################################
# 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 everything on.
######################################################################
- alias: "Occupancy detected - turn Office lights and power on"
conditions:
- condition: trigger
id: occupancy_detected
sequence:
##############################################################
# Power first.
##############################################################
- 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
- alias: "Turn on Office USB Hub if needed"
if:
- condition: state
entity_id: switch.esp_officeusbhubpower_usb_hub_power_supply
state: "off"
then:
- action: switch.turn_on
target:
entity_id: switch.esp_officeusbhubpower_usb_hub_power_supply
##############################################################
# Lights.
##############################################################
- alias: "Turn on Office right hand bunker light if needed"
if:
- condition: state
entity_id: light.esp_officeduallights_light_1_right_hand_bunker_light
state: "off"
then:
- action: light.turn_on
target:
entity_id: light.esp_officeduallights_light_1_right_hand_bunker_light
- alias: "Turn on Office cool white overhead lights if needed"
if:
- condition: state
entity_id: light.esp_officeduallights_light_2_cool_white_overhead_lights
state: "off"
then:
- action: light.turn_on
target:
entity_id: light.esp_officeduallights_light_2_cool_white_overhead_lights
- alias: "Turn on Office nighttime lights relay if needed"
if:
- condition: state
entity_id: switch.esp_officelights_relay_1_nighttime_lights
state: "off"
then:
- action: switch.turn_on
target:
entity_id: switch.esp_officelights_relay_1_nighttime_lights
- alias: "Turn on Office daytime lights relay if needed"
if:
- condition: state
entity_id: switch.esp_officelights_relay_2_daytime_lights
state: "off"
then:
- action: switch.turn_on
target:
entity_id: switch.esp_officelights_relay_2_daytime_lights
##############################################################
# 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 everything off.
######################################################################
- alias: "Occupancy clear - wait, re-check, then turn Office lights and 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"
##############################################################
# Lights off first.
##############################################################
- alias: "Turn off Office right hand bunker light if needed"
if:
- condition: state
entity_id: light.esp_officeduallights_light_1_right_hand_bunker_light
state: "on"
then:
- action: light.turn_off
target:
entity_id: light.esp_officeduallights_light_1_right_hand_bunker_light
- alias: "Turn off Office cool white overhead lights if needed"
if:
- condition: state
entity_id: light.esp_officeduallights_light_2_cool_white_overhead_lights
state: "on"
then:
- action: light.turn_off
target:
entity_id: light.esp_officeduallights_light_2_cool_white_overhead_lights
- alias: "Turn off Office nighttime lights relay if needed"
if:
- condition: state
entity_id: switch.esp_officelights_relay_1_nighttime_lights
state: "on"
then:
- action: switch.turn_off
target:
entity_id: switch.esp_officelights_relay_1_nighttime_lights
- alias: "Turn off Office daytime lights relay if needed"
if:
- condition: state
entity_id: switch.esp_officelights_relay_2_daytime_lights
state: "on"
then:
- action: switch.turn_off
target:
entity_id: switch.esp_officelights_relay_2_daytime_lights
##############################################################
# Power off after lights.
##############################################################
- 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
- alias: "Turn off Office USB Hub power supply if needed"
if:
- condition: state
entity_id: switch.esp_officeusbhubpower_usb_hub_power_supply
state: "on"
then:
- action: switch.turn_off
target:
entity_id: switch.esp_officeusbhubpower_usb_hub_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
######################################################################
# MANUAL BACKUP LOGIC:
# Button pressed while spare relay master is ON - turn everything OFF.
######################################################################
- alias: "Backup button pressed - spare relay on, turn everything off"
conditions:
- condition: trigger
id: backup_button_pressed
- condition: state
entity_id: switch.esp_officelights_relay_3_spare
state: "on"
sequence:
##############################################################
# Lights off first.
##############################################################
- alias: "Turn off Office right hand bunker light if needed"
if:
- condition: state
entity_id: light.esp_officeduallights_light_1_right_hand_bunker_light
state: "on"
then:
- action: light.turn_off
target:
entity_id: light.esp_officeduallights_light_1_right_hand_bunker_light
- alias: "Turn off Office cool white overhead lights if needed"
if:
- condition: state
entity_id: light.esp_officeduallights_light_2_cool_white_overhead_lights
state: "on"
then:
- action: light.turn_off
target:
entity_id: light.esp_officeduallights_light_2_cool_white_overhead_lights
- alias: "Turn off Office nighttime lights relay if needed"
if:
- condition: state
entity_id: switch.esp_officelights_relay_1_nighttime_lights
state: "on"
then:
- action: switch.turn_off
target:
entity_id: switch.esp_officelights_relay_1_nighttime_lights
- alias: "Turn off Office daytime lights relay if needed"
if:
- condition: state
entity_id: switch.esp_officelights_relay_2_daytime_lights
state: "on"
then:
- action: switch.turn_off
target:
entity_id: switch.esp_officelights_relay_2_daytime_lights
##############################################################
# Power off after lights.
##############################################################
- 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
- alias: "Turn off Office USB Hub power supply if needed"
if:
- condition: state
entity_id: switch.esp_officeusbhubpower_usb_hub_power_supply
state: "on"
then:
- action: switch.turn_off
target:
entity_id: switch.esp_officeusbhubpower_usb_hub_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
######################################################################
# MANUAL BACKUP LOGIC:
# Button pressed while spare relay master is OFF - turn everything ON.
#
# No off timer is started from this manual press. If the occupancy
# sensor later changes to clear, the normal clear-delay logic will run.
######################################################################
- alias: "Backup button pressed - spare relay off, turn everything on"
conditions:
- condition: trigger
id: backup_button_pressed
- condition: state
entity_id: switch.esp_officelights_relay_3_spare
state: "off"
sequence:
##############################################################
# Power first.
##############################################################
- 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
- alias: "Turn on Office USB Hub power supply if needed"
if:
- condition: state
entity_id: switch.esp_officeusbhubpower_usb_hub_power_supply
state: "off"
then:
- action: switch.turn_on
target:
entity_id: switch.esp_officeusbhubpower_usb_hub_power_supply
##############################################################
# Lights.
##############################################################
- alias: "Turn on Office right hand bunker light if needed"
if:
- condition: state
entity_id: light.esp_officeduallights_light_1_right_hand_bunker_light
state: "off"
then:
- action: light.turn_on
target:
entity_id: light.esp_officeduallights_light_1_right_hand_bunker_light
- alias: "Turn on Office cool white overhead lights if needed"
if:
- condition: state
entity_id: light.esp_officeduallights_light_2_cool_white_overhead_lights
state: "off"
then:
- action: light.turn_on
target:
entity_id: light.esp_officeduallights_light_2_cool_white_overhead_lights
- alias: "Turn on Office nighttime lights relay if needed"
if:
- condition: state
entity_id: switch.esp_officelights_relay_1_nighttime_lights
state: "off"
then:
- action: switch.turn_on
target:
entity_id: switch.esp_officelights_relay_1_nighttime_lights
- alias: "Turn on Office daytime lights relay if needed"
if:
- condition: state
entity_id: switch.esp_officelights_relay_2_daytime_lights
state: "off"
then:
- action: switch.turn_on
target:
entity_id: switch.esp_officelights_relay_2_daytime_lights
##############################################################
# 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