Creating a Dynamic Timer Card for Devices

Recently, I stumbled upon a neat solution to a problem I’ve been dealing with for quite some time—how to create a universal timer for various devices like lights, fans, and switches. I wanted something that could turn off a device after a set amount of time, which is super handy for things like nighttime fans or heaters that I don’t want running all night.

After some experimentation, I came up with an automation using Node-RED that does exactly that. Here’s how it works:

  1. Device Selection: A dropdown menu where I can select any device I want to control. It lists all the entities I’ve set up in Home Assistant, making it easy to choose the right one.
  2. Time Input: A number input field where I set the timer in minutes. It’s simple and straightforward—just type in how long you want the device to stay on.
  3. Start Button: A button that triggers the automation. Once pressed, it starts the timer and turns off the selected device once the time is up.

The automation itself is pretty cool. It uses Node-RED to handle the logic. When the button is pressed, it reads the selected device and the timer value. It then calculates the delay in milliseconds and determines the domain of the device (like light, fan, or switch) so it knows which service to call to turn it off. The delay node waits for the specified time, and then the device is turned off automatically.

While it’s not the prettiest solution, it gets the job done perfectly. I’ve been using it for a while now, and it’s been a lifesaver for managing devices during the night. If anyone has a more elegant way of achieving this or any suggestions for improvements, I’d love to hear about it!

It’s amazing how a little bit of tinkering can solve such a specific problem. I hope this helps someone else who’s looking for a similar solution. Let me know what you think!