So, just spit balling here. Might not be as much code as you think.
You can use the hass_entities python script to change the timer’s friendly_name.
pmazz/ps_hassio_entities: Python script to handle state and attributes of existing sensors and entities (github.com)
I could not find it in HACS. Add the following to configuration.yaml and you will then find it in HACS:
python_script:
Python Scripts - Home Assistant (home-assistant.io)
And is used like
service: python_script.hass_entities
data:
action: set_attributes
entity_id: "{{ timer_id }}"
attributes:
- friendly_name: "{{ timer_name }}"
The intent could then be something like
Set oven timer for 40 minutes
You could then use something like this to see if a timer name already exists
if states.timer | selectattr('entity_id', 'match', 'timer.timer*') | selectattr('name', 'eq', timer_name) | map(attribute='entity_id') | list | count == 0
If == 0, then it does not exist. If not = 0, then it does exist for pause and cancel (or to error on set).
To get the timer id if it exists
states.timer | selectattr('entity_id', 'match', 'timer.timer*') | selectattr('name', 'eq', timer_name) | map(attribute='entity_id') | list | first
Now, to see if you have an open timer, you could use
if states.timer | selectattr('entity_id', 'match', 'timer.timer*') | selectattr('state', 'eq', 'idle') | map(attribute='entity_id') | list | count > 0
If greater than 0, you have open timers. If = 0, you are out of timers and can return an error.
To get the first open timer id
states.timer | selectattr('entity_id', 'match', 'timer.timer*') | selectattr('state', 'eq', 'idle') | map(attribute='entity_id') | list | first
Now, for the fun part. LOL
You would probably want to rework the rest of your code. You would no longer need to do all of the checks for timer1, timer2, and timer3. And, are now only limited by the number of timers created. To add another timer, just create it and should not have any code changes.
Then, on cancel, stop, or finished, change the name back to match the saved id
service: python_script.hass_entities
data:
action: set_attributes
entity_id: "{{ timer_id }}"
attributes:
- friendly_name: "{{ timer_id | replace('timer.', '') }}"
Then, you could use auto-entites and timer-bar-card to show all of your timers in lovelace.
type: custom:auto-entities
card:
type: custom:timer-bar-card
name: Willow Timers
filter:
include:
- entity_id: timer.timer*
Which looks like:
You could also change the icon based on the current state of the timer.