esphome lounge switches and scene control

This commit is contained in:
root
2025-10-08 19:21:28 +13:00
parent 1e1d0571d9
commit e96344e3ad
62 changed files with 4189 additions and 925 deletions
+331
View File
@@ -0,0 +1,331 @@
# yaml-language-server: $schema=null
###############################################################################
# PACKAGE: Lounge scenes (delta-only settings) + manual override
###############################################################################
input_select:
lounge_scene:
name: Lounge Scene
options:
- "Select Scene:"
- Bright
- TV General
- Movie
- Reading On/Off
- Night Light
- Warm Cozy
- All Off
initial: "Select Scene:"
input_boolean:
lounge_manual_override:
name: Lounge Lighting Scene Manual Override
initial: off
input_text:
lounge_last_scene:
name: Lounge Last Scene
initial: "All Off"
max: 40
timer:
lounge_override_timer:
name: Lounge Lighting Scene Override Timer
duration: "02:00:00"
###############################################################################
# SCRIPTS
###############################################################################
script:
lounge_set_scene:
alias: "Lounge: Set scene by name"
mode: restart
fields:
scene_name:
description: One of the options from input_select.lounge_scene
sequence:
- service: input_select.select_option
target: { entity_id: input_select.lounge_scene }
data:
option: "{{ scene_name }}"
# NEW: Wait briefly for HA to commit the new state (avoids race)
- wait_template: "{{ states('input_select.lounge_scene') == scene_name }}"
timeout: "00:00:02"
continue_on_timeout: true
- service: script.lounge_apply_and_reset
lounge_apply_scene:
alias: "Lounge: Apply current scene"
mode: restart
sequence:
- variables:
sel: "{{ states('input_select.lounge_scene') }}"
#####################################################################
# EXCLUDED SCENES (these are temp scenes, not remembered as last)
#####################################################################
excluded_scenes:
- "Select Scene:"
- "Reading On/Off"
#- "Night Light"
#####################################################################
# SCENE SETTINGS (delta only - only list entities you want to change)
#####################################################################
scene_settings:
Bright:
light.esp_lounge6chdimmer_couch_spots_left: 00
light.esp_lounge6chdimmer_couch_spots_right: 00
#light.esp_lounge6chdimmer_dining_table_light: 100
light.esp_lounge6chdimmer_lounge_downlights_centre: 100 # Centre Downlights (x6, dimmable)
light.esp_lounge6chdimmer_lounge_downlights_south: 100 # South Downlights (x4, dimmable)
light.esp_lounge6chdimmer_lounge_rafter_buttons: 100 # Buttons in Rafters (x3, dimmable)
switch.esp_loungemiddleswitch_relay_3_downlights_north: "on" # North Downlights (x2 over stairs, non dimmable)
light.esp_breakfastbarleds_breakfast_bar_leds: 90
light.esp_loungecabinetleds2_lounge_cabinet_leds: 90
light.esp_loungebookshelfleds_lounge_bookshelf_leds: 90
light.tasmo_h801_loungeled1_6180_a: 90
light.tasmo_h801_loungeled1_6180_b: 90
switch.lounge_cupboard_dual_usb_xus09_l2: on
switch.esp_loungesouthleftswitch_relay_1_wall_washer_left: on # Back wall wallwasher Left
switch.esp_loungesouthrightswitch_relay_2_wall_washer_right: on # Back wall wallwasher right
switch.tasmo_ks811t_0702_lounge_3c: on # North Downlights (x2 over stairs, non dimmable)
switch.esp_loungenorthswitch_relay_1_main_lights: on # Single switch to hallway relay output (Pelmet LEDs)
Movie:
#light.esp_lounge6chdimmer_couch_spots_left: 40
#light.esp_lounge6chdimmer_couch_spots_right: 40
#light.esp_lounge6chdimmer_dining_table_light: 100
light.esp_lounge6chdimmer_lounge_downlights_centre: 20 # Centre Downlights (x6, dimmable)
light.esp_lounge6chdimmer_lounge_downlights_south: 20 # South Downlights (x4, dimmable)
light.esp_lounge6chdimmer_lounge_rafter_buttons: 20 # Buttons in Rafters (x3, dimmable)
light.esp_breakfastbarleds_breakfast_bar_leds: 40
light.esp_loungecabinetleds2_lounge_cabinet_leds: 40
light.esp_loungebookshelfleds_lounge_bookshelf_leds: 40
light.tasmo_h801_loungeled1_6180_a: 60
light.tasmo_h801_loungeled1_6180_b: 60
switch.esp_loungemiddleswitch_relay_3_downlights_north: off # North Downlights (x2 over stairs, non dimmable) switch.lounge_cupboard_dual_usb_xus09_l2: "on"
switch.esp_loungesouthleftswitch_relay_1_wall_washer_left: off # Back wall wallwasher Left
switch.esp_loungesouthrightswitch_relay_2_wall_washer_right: off # Back wall wallwasher right
switch.esp_loungenorthswitch_relay_1_main_lights: on # Single switch to hallway relay output (Pelmet LEDs)
Night Light:
#light.esp_lounge6chdimmer_couch_spots_left: 40
#light.esp_lounge6chdimmer_couch_spots_right: 40
#light.esp_lounge6chdimmer_dining_table_light: 100
light.esp_lounge6chdimmer_lounge_downlights_centre: 5 # Centre Downlights (x6, dimmable)
#light.esp_lounge6chdimmer_lounge_downlights_south: 20 # South Downlights (x4, dimmable)
light.esp_lounge6chdimmer_lounge_rafter_buttons: 5 # Buttons in Rafters (x3, dimmable)
switch.esp_loungesouthleftswitch_relay_1_wall_washer_left: off # Back wall wallwasher Left
switch.esp_loungesouthrightswitch_relay_2_wall_washer_right: off # Back wall wallwasher right
Reading On/Off:
light.esp_lounge6chdimmer_couch_spots_left: toggle_75
light.esp_lounge6chdimmer_couch_spots_right: toggle_75
#light.esp_lounge6chdimmer_dining_table_light: 60
#light.esp_lounge6chdimmer_lounge_downlights_centre: 45
#light.esp_lounge6chdimmer_lounge_downlights_south: 35
#light.esp_lounge6chdimmer_lounge_rafter_buttons: 20
#switch.tasmo_ks811t_0702_lounge_3c: on
Warm Cozy:
light.esp_lounge6chdimmer_couch_spots_left: 30
light.esp_lounge6chdimmer_couch_spots_right: 30
light.esp_lounge6chdimmer_lounge_rafter_buttons: 15
light.esp_breakfastbarleds_breakfast_bar_leds: 25
light.esp_loungecabinetleds2_lounge_cabinet_leds: 30
light.esp_loungebookshelfleds_lounge_bookshelf_leds: 30
light.tasmo_h801_loungeled1_6180_a: 25
light.tasmo_h801_loungeled1_6180_b: 25
switch.lounge_cupboard_dual_usb_xus09_l2: on
switch.esp_loungesouthleftswitch_relay_1_wall_washer_left: on # Back wall wallwasher Left
switch.esp_loungesouthrightswitch_relay_2_wall_washer_right: on # Back wall wallwasher right
TV General:
light.esp_lounge6chdimmer_couch_spots_left: 50
light.esp_lounge6chdimmer_couch_spots_right: 50
#light.esp_lounge6chdimmer_dining_table_light: 100
light.esp_lounge6chdimmer_lounge_downlights_centre: 40 # Centre Downlights (x6, dimmable)
light.esp_lounge6chdimmer_lounge_downlights_south: 40 # South Downlights (x4, dimmable)
light.esp_lounge6chdimmer_lounge_rafter_buttons: 40 # Buttons in Rafters (x3, dimmable)
light.esp_breakfastbarleds_breakfast_bar_leds: 60
light.esp_loungecabinetleds2_lounge_cabinet_leds: 60
light.esp_loungebookshelfleds_lounge_bookshelf_leds: 60
light.tasmo_h801_loungeled1_6180_a: 60
light.tasmo_h801_loungeled1_6180_b: 60
switch.esp_loungemiddleswitch_relay_3_downlights_north: off # North Downlights (x2 over stairs, non dimmable) switch.lounge_cupboard_dual_usb_xus09_l2: "on"
switch.esp_loungesouthleftswitch_relay_1_wall_washer_left: off # Back wall wallwasher Left
switch.esp_loungesouthrightswitch_relay_2_wall_washer_right: off # Back wall wallwasher right
switch.esp_loungenorthswitch_relay_1_main_lights: on # Single switch to hallway relay output (Pelmet LEDs)
All Off:
light.esp_lounge6chdimmer_couch_spots_left: 0
light.esp_lounge6chdimmer_couch_spots_right: 0
light.esp_lounge6chdimmer_dining_table_light: 0
light.esp_lounge6chdimmer_lounge_downlights_centre: 0 # Centre Downlights (x6, dimmable)
light.esp_lounge6chdimmer_lounge_downlights_south: 0 # South Downlights (x4, dimmable)
light.esp_lounge6chdimmer_lounge_rafter_buttons: 0 # Buttons in Rafters (x3, dimmable)
switch.esp_loungemiddleswitch_relay_3_downlights_north: "off" # North Downlights (x2 over stairs, non dimmable)
light.esp_breakfastbarleds_breakfast_bar_leds: 0
light.esp_loungecabinetleds2_lounge_cabinet_leds: 0
light.esp_loungebookshelfleds_lounge_bookshelf_leds: 0
light.tasmo_h801_loungeled1_6180_a: 0
light.tasmo_h801_loungeled1_6180_b: 0
switch.lounge_cupboard_dual_usb_xus09_l2: off
switch.esp_loungesouthleftswitch_relay_1_wall_washer_left: off # Back wall wallwasher Left
switch.esp_loungesouthrightswitch_relay_2_wall_washer_right: off # Back wall wallwasher right
switch.esp_loungenorthswitch_relay_1_main_lights: off # Single switch to hallway relay output (Pelmet LEDs)
#####################################################################
#####################################################################
#####################################################################
# Only remember scenes that are not excluded
- choose:
- conditions: "{{ sel not in excluded_scenes }}"
sequence:
- service: input_text.set_value
target: { entity_id: input_text.lounge_last_scene }
data:
value: "{{ sel }}"
- repeat:
for_each: "{{ (scene_settings.get(sel, {})).keys() | list }}"
sequence:
- variables:
ent: "{{ repeat.item }}"
val: "{{ (scene_settings.get(sel, {}))[ent] }}"
is_light: "{{ ent.startswith('light.') }}"
is_switch: "{{ ent.startswith('switch.') }}"
is_num: "{{ val is number }}"
vstr: "{{ (val|string) if not is_num else '' }}"
is_toggle: "{{ (not is_num) and (vstr|lower).startswith('toggle') }}"
toggle_pct: "{{ (vstr.split('_')|last)|int if ('_' in vstr) else 100 }}"
currently_on: "{{ is_state(ent, 'on') }}"
- choose:
# 1) Lights: toggle[_NN] -> if on turn off, else turn on to NN (default 100)
- conditions: "{{ is_light and is_toggle }}"
sequence:
- choose:
- conditions: "{{ currently_on }}"
sequence:
- service: light.turn_off
data:
entity_id: "{{ ent }}"
default:
- service: light.turn_on
data:
entity_id: "{{ ent }}"
brightness_pct: "{{ toggle_pct }}"
# 2) Switches: toggle -> flip state
- conditions: "{{ is_switch and is_toggle }}"
sequence:
- service: switch.toggle
data:
entity_id: "{{ ent }}"
# 3) Lights: numeric brightness (0 = off)
- conditions: "{{ is_light and is_num and (val|int) > 0 }}"
sequence:
- service: light.turn_on
data:
entity_id: "{{ ent }}"
brightness_pct: "{{ val|int }}"
- conditions: "{{ is_light and is_num and (val|int) == 0 }}"
sequence:
- service: light.turn_off
data:
entity_id: "{{ ent }}"
# 4) Lights: textual/boolean on/off
- conditions: "{{ is_light and not is_num and (val in [true, 'on', 'On', 'ON']) }}"
sequence:
- service: light.turn_on
data:
entity_id: "{{ ent }}"
- conditions: "{{ is_light and not is_num and (val in [false, 'off', 'Off', 'OFF']) }}"
sequence:
- service: light.turn_off
data:
entity_id: "{{ ent }}"
# 5) Switches: textual/boolean on/off
- conditions: "{{ is_switch and (val in [true, 'on', 'On', 'ON']) }}"
sequence:
- service: switch.turn_on
data:
entity_id: "{{ ent }}"
- conditions: "{{ is_switch and (val in [false, 'off', 'Off', 'OFF']) }}"
sequence:
- service: switch.turn_off
data:
entity_id: "{{ ent }}"
lounge_apply_and_reset:
alias: "Lounge: Apply scene + reset selector"
mode: restart
sequence:
- service: script.lounge_apply_scene
- delay: "00:00:05"
- service: input_select.select_option
target: { entity_id: input_select.lounge_scene }
data:
option: "Select Scene:"
###############################################################################
# AUTOMATIONS
###############################################################################
automation:
- id: lounge_apply_on_selector_change
alias: "Lounge - Apply when selector changes"
trigger:
- platform: state
entity_id: input_select.lounge_scene
condition:
- condition: state
entity_id: input_boolean.lounge_manual_override
state: "off"
- condition: template
value_template: "{{ trigger.to_state.state != 'Select Scene:' }}"
action:
- service: script.turn_on
target:
entity_id: script.lounge_apply_and_reset
- id: lounge_tv_on_sets_tv_bias
alias: "Lounge - TV on sets TV General (unless override)"
trigger:
- platform: state
entity_id: remote.lounge_tv
to: "on"
for: "00:00:02" #small debounce
condition:
- condition: state
entity_id: input_boolean.lounge_manual_override
state: "off"
- condition: template
value_template: "{{ states('input_text.lounge_last_scene') != 'All Off' }}"
action:
- service: script.lounge_set_scene
data:
scene_name: "TV General"
- id: lounge_tv_off_sets_bright
alias: "Lounge - TV off sets Bright (unless override)"
trigger:
- platform: state
entity_id: remote.lounge_tv
to: "off"
for: "00:00:02" #small debounce
condition:
- condition: state
entity_id: input_boolean.lounge_manual_override
state: "off"
- condition: template
value_template: "{{ states('input_text.lounge_last_scene') != 'All Off' }}"
action:
- service: script.lounge_set_scene
data:
scene_name: "Bright"