Timed buttons

Hi everyone,

I’m fairly new to Home Assistant and not entirely sure what terms to search for to find the solution I’m looking for—so I’m hoping someone can point me in the right direction.

I have a few devices (like a water heater) that already have automations in place to turn on and off at specific times. However, there are situations where I need to manually turn one of these devices on for just a few minutes, but I often forget to turn it back off.

Ideally, I’d like to create something on my dashboard that allows me to:

  • Select a device (e.g., from a dropdown or entity selector)
  • Set a duration (or have a fixed duration, like 5 or 10 minutes)
  • Have the device turn on immediately and automatically turn off after the set time

Is it possible to create a card with a dropdown to select the device and apply a timer to it? Or do I need to create individual buttons/scripts for each device I want to control this way?

Any advice, examples, or suggestions would be greatly appreciated!

Thanks in advance!

To do a “turn on” action followed by a delayed “turn off” action you will need a script. It will require the use of templates to get the time and entity.

If you have Conversation enabled (it is enabled by default), one easy method is to create a script like:

Conversation-based On/Off script
alias: On/Off with delay using Conversation
description: ""
sequence:
  - action: homeassistant.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: "{{target_entity}}"
  - alias: short delay to make sure target is "on"
    delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - action: conversation.process
    metadata: {}
    data:
      text: >
        turn off {{ state_attr(target_entity, 'friendly_name') }} in
        {{delay_time}} minute{{'s' if delay_time > 1 else ''}}
fields:
  target_entity:
    selector:
      entity:
        filter:
          - domain:
              - light
              - switch
    name: Target Entity
    description: >-
      The light or switch you want to turn on then turn off after a set amount
      of time.
    required: true
  delay_time:
    selector:
      number:
        min: 1
        max: 100
        step: 1
    name: Delay Time
    description: The number of minutes to delay before the target entity is turned off.
    required: true
    default: 1

From initial testing, this method does allow concurrent “timers”. However, I’m not sure what the limit is.

On the frontend you can use basically any card that supports an entity and actions, then set the action to “More Info”.

Basic Tile Card example

image

type: tile
entity: script.on_off_with_delay_using_conversation
icon: mdi:power
name: On/Timed Off
tap_action:
  action: more-info
features_position: bottom
vertical: false
hide_state: true

When the card is clicked, you will get a pop up menu where you can select the entity and the delay minutes like:


While this method is pretty easy, I wouldn’t expect it to be resilient to restarts or reloading the conversation integration. If you need something that is more resilient you would likely need to create a timer entity for each target entity you plan to use, set up a template or variable map in the script to link the target entity to the timer, and use the timer.start action.

2 Likes

Wow! Works like a charm! You are an absolute legend! Really appreciate it!