π This project demonstrates a fully dynamic, self-disabling timer automation in Home Assistant, configurable via UI (hours/minutes/seconds).
- β±οΈ HASS - FLEXIBLE TIMER AUTOMATION
- π UI Configuration (hours/minutes/seconds)
- β‘ Self-disabling after execution
- π Reset without restart
- π Stores last execution time
- π‘οΈ Prevents false triggers
input_number:
interval_hours:
name: "Interval - Hours"
min: 0
max: 24
step: 1
unit_of_measurement: "h"
interval_minutes:
name: "Interval - Minutes"
min: 0
max: 59
step: 1
unit_of_measurement: "min"
interval_seconds:
name: "Interval - Seconds"
min: 5 # Minimum 5 sec for stability
max: 59
step: 1
unit_of_measurement: "sec"
π‘ Defines the interval. Values are summed automatically (1h + 30min = 5400 sec).
input_datetime:
last_execution_time:
name: "Last Execution"
has_date: true
has_time: true
β³ This component records when the timer last started. Critical for calculations!
automation:
- alias: "β±οΈ TIMER"
id: auto_flexible_interval
description: "Executes action after set interval"
trigger:
- platform: time_pattern
seconds: "/1" # Checks every second
condition: >
{% set h = states('input_number.interval_hours') | int %}
{% set m = states('input_number.interval_minutes') | int %}
{% set s = states('input_number.interval_seconds') | int %}
{% set interval = h * 3600 + m * 60 + s %}
{% set last = states('input_datetime.last_execution_time') %}
{{ (now() - strptime(last, '%Y-%m-%d %H:%M:%S')).total_seconds() >= interval if last not in ['unknown', 'unavailable'] else false %}
action:
- service: notify.all_devices # π Replace with your service!
data:
message: "π Action executed at {{ now().strftime('%H:%M:%S') }}"
- service: input_datetime.set_datetime
data:
entity_id: input_datetime.last_execution_time
datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
- delay: 00:00:02 # Brief pause before disabling
- service: automation.turn_off # π SELF-DISABLING
target:
entity_id: "{{ this.entity_id }}"
π How It Works?
1οΈβ£ Checks every second if interval has elapsed
2οΈβ£ Calculates total time in seconds
3οΈβ£ Compares with last execution
4οΈβ£ If condition met β executes action and disables itself
script:
start_interval_timer:
alias: "βΆοΈ Start Timer"
sequence:
- service: input_datetime.set_datetime # π Sets initial time
data:
entity_id: input_datetime.last_execution_time
datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
- service: automation.turn_on # π Starts automation
target:
entity_id: automation.auto_flexible_interval
reset_interval_timer:
alias: "π Reset Timer"
sequence:
- service: input_datetime.set_datetime # π Updates time without stopping
data:
entity_id: input_datetime.last_execution_time
datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
type: vertical-stack
cards:
- type: entities
title: "β±οΈ Control Panel"
entities:
- input_number.interval_hours
- input_number.interval_minutes
- input_number.interval_seconds
- input_datetime.last_execution_time
- type: horizontal-stack
cards:
- type: button
name: "βΆοΈ START"
icon: mdi:play
tap_action:
action: call-service
service: script.start_interval_timer
- type: button
name: "π RESET"
icon: mdi:restart
tap_action:
action: call-service
service: script.reset_interval_timer
- type: button
name: "βΉοΈ STOP"
icon: mdi:stop
tap_action:
action: call-service
service: automation.turn_off
target:
entity_id: automation.auto_flexible_interval
π¨ Customize with
card-mod
for 3D buttons and animations!
- π‘οΈ AC: Turn off after 2 hours
- π‘ Lights: Night mode (30min)
- π Notifications: Reminder every 15 minutes
- β±οΈ Precision: Use
seconds: "/1"
for second-level accuracy - π Reset: Always use
reset_interval_timer
script instead of manual setting - π Visualization: Add
history_graph
to track executions
Your timer card will appear as a modern, semi-transparent control panel with three main sections:
-
β±οΈ Interval Settings
- Three columns for hours/minutes/seconds with styled +/- buttons
- Shows current set time (e.g., "0h 5min 30s")
- Bottom row shows last execution (e.g., "5/20 8:30 PM")
-
πΌ START Button
- Green accent (typically)
- Starts timer via
script.reset_interval_timer
- Visible only when automation is off
-
π΄ STOP Button
- Red accent
- Stops automation via
script.turn_on
- Visible only when automation is active
To make the card work, install these add-ons:
# In HACS (Home Assistant Community Store):
- bubble-card (for pop-up effect)
- numberbox-card (for styled numeric inputs)
- card-mod (for CSS customization)
- button-card (for additional effects)
type: custom:bubble-card
name: TIMER
card_type: pop-up # Creates "pop-out" effect
hide_backdrop: true # Hides background
type: custom:numberbox-card
entity: input_number.interval_seconds
name: Seconds
unit: s. # Shows units
card_mod:
style: |
ha-card {
border-radius: 15px; # Rounded corners
box-shadow: 0 4px 8px rgba(0,0,0,0.2); # 3D effect
}
visibility:
- condition: state
entity: automation.taimer
state_not: "on" # Shows START only when timer is off
- Colors: Change
rgba(0, 0, 0, 0.35)
to other colors (e.g.,rgba(25, 25, 112, 0.4)
for midnight blue) - Animations: Add
transition: all 0.3s ease;
for smooth hover effects - Icons: Replace
mdi:restart
with other icons from Material Design Icons
Tip
If you like this project, find more interesting repositories HERE.
For questions or issues, don't hesitate to contact me.