TL;DR: I wanted to use timers (plural) to visualize the running time of two scripts which are mutually exclusive, and bashed my head against the wall in the process. Turns out it’s possible to have a single timer and change its duration before you start it with
timer.start
(nottimer.change
).
<rant>
As many times it goes, my idea is simple but HA doesn’t seem to help out :sigh:
I have a simple towel heater and I bought with it a smart plug and a button.
The idea is to have actions to run it for 2 and 4 hours, both on the HA panel and with the button.
This is a common feature on “end user” systems, such as the eWeLink (sonoff) or SmartLife (Tuya) apps, and some people have already thought this should be baked in HA.
This was straightforward at first with the knowledge I already had; I had created scripts with delays between on and off, and it was triggered directly by the UI and automations related to the physical buttons. However… delays doesn’t make it easy to see how much time is left. Then I discovered timers, and thought it would be easy to replace the script with a timer…
Oh boy, I was wrong in so many ways.
Here’s the tiny list of issues I stumbled upon through the many hours I spent trying to get a simple idea going:
- it doesn’t seem possible to have a timer turn off the other in this scenario. When a timer goes off, the heater goes off too; making a timer turn the other off while turning the heater on doesn’t seem to work, not even with a small time delay in between - I guess the consecutive actions cause the last to be ignored.
- It gets VERY complicated to setup the UI since there’s no
timer.toggle
action, and thus I have to create two buttons for each action (start and stop), and you got to repeat yourself between them. - I also tried using
timer.change
to set a single timer entity and set its duration on demand, but then I discovered the service should actually be namedtimer.add
ortimer.subtract
.- EDIT: as explained below, you can only freely change the duration of the timer before you start it with
timer.start
. Definitely not straightforward.
- EDIT: as explained below, you can only freely change the duration of the timer before you start it with
- not to mention it’s possible to add triggers for multiple events at once, but not for multiple entities - what means every timer must have its own on and off triggers on the automation; again, repetition.
I thought that adding a timer
to my flow would make it cleaner and better; turns out, as with many things in HA, going with workarounds is sadly better. I wish I had made a backup of the script, interface and automation before trying “something new” (not that you can really make an easy backup of UI code, since friendly Lovelace strips out any comments you leave, unless by “backup” you mean “copy stuff into notepad”).
This also reminds me of an old topic where someone was being heavily criticized when he criticized HA for being so complicated in so many ways when there was an opportunity to be smarter. I understand this is probably due to giving people options, but then you end up complicating so much it scares people off.
</rant>
How would you create two timers which turn something on/off and also cancel each other?