various tidyups and esphome adds

This commit is contained in:
root
2026-02-16 22:13:42 +13:00
parent d7884770fe
commit 83e4040b84
16 changed files with 2251 additions and 113 deletions
@@ -0,0 +1,120 @@
# ------------------------------
# TIMER HELPER (define in YAML so it definitely exists)
# ------------------------------
timer:
master_bedroom_climate_timer:
name: Master Bedroom Climate Timer
duration: "00:00:00"
# ------------------------------
# DROPDOWN (sleep timer)
# ------------------------------
input_select:
master_bedroom_climate_timer_duration:
name: Master Bedroom Aircon Sleep
options:
- "1 hour"
- "2 hours"
- "3 hours"
- "6 hours"
- "Cancel timer"
initial: "Cancel timer"
icon: mdi:timer-outline
# ------------------------------
# LIVE REMAINING (updates immediately on selection, and every minute)
# ------------------------------
template:
- trigger:
# Update once per minute (suits hh:mm display)
- platform: time_pattern
minutes: "/1"
# Update when timer STATE changes (idle/active/paused)
- platform: state
entity_id: timer.master_bedroom_climate_timer
# Update immediately when user changes the dropdown
- platform: state
entity_id: input_select.master_bedroom_climate_timer_duration
sensor:
- name: "Master Bedroom Climate Timer Remaining"
unique_id: master_bedroom_climate_timer_remaining
icon: mdi:timer
state: >-
{% set st = states('timer.master_bedroom_climate_timer') | lower %}
{% if st == 'idle' %}
0:00
{% else %}
{% set fa = state_attr('timer.master_bedroom_climate_timer', 'finishes_at') %}
{% if fa %}
{% set end = as_datetime(fa) %}
{% set sec = (end - now()).total_seconds() | int(0) %}
{% if sec < 0 %}{% set sec = 0 %}{% endif %}
{% set hh = (sec // 3600) | int %}
{% set mm = ((sec % 3600) // 60) | int %}
{{ hh }}:{{ '%02d' | format(mm) }}
{% else %}
0:00
{% endif %}
{% endif %}
# ------------------------------
# AUTOMATION: start/cancel timer when dropdown changes
# ------------------------------
automation:
- alias: "Start or Cancel Master Bedroom Climate Timer"
mode: restart
trigger:
- platform: state
entity_id: input_select.master_bedroom_climate_timer_duration
variables:
opt: "{{ states('input_select.master_bedroom_climate_timer_duration') }}"
dur_map:
"1 hour": "01:00:00"
"2 hours": "02:00:00"
"3 hours": "03:00:00"
"6 hours": "06:00:00"
action:
- choose:
- conditions:
- condition: template
value_template: "{{ opt in dur_map }}"
sequence:
- service: timer.cancel
target:
entity_id: timer.master_bedroom_climate_timer
- delay: "00:00:01"
- service: timer.start
target:
entity_id: timer.master_bedroom_climate_timer
data:
duration: "{{ dur_map[opt] }}"
- conditions:
- condition: state
entity_id: input_select.master_bedroom_climate_timer_duration
state: "Cancel timer"
sequence:
- service: timer.cancel
target:
entity_id: timer.master_bedroom_climate_timer
- alias: "Turn Off Master Bedroom Climate on Timer Completion"
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.master_bedroom_climate_timer
action:
- service: climate.turn_off
target:
entity_id: climate.master_bedroom
- service: input_select.select_option
target:
entity_id: input_select.master_bedroom_climate_timer_duration
data:
option: "Cancel timer"