Wth: one shot timer

I wanted to power on my espresso machine using a one-shot timer from the dashboard. That way I can turn the machine on half an hour before my guests arrive. I was able to achieve this in a very convoluted way, but it works.

  • Create a datetime input helper to hold the start time.
  • Create a script that sets the datetime helper to the current time. I use this to make it easier to enter a time later today without knowing the current date. Once it’s reset I only have to set the time. Because I’ve included the date it will only run once.
  • Create an entities card with a single entity pointing to the datetime helper. I’m using an entities card because it supports tap_action which is calling the script mentioned above.

I think you can get around using a date by setting a boolean flag when a trigger happened and resetting it once a new time has been entered. However, this required some bookkeeping which seemed too much of a hassle to me.

I really hope one-shot timers will be introduced to make this process a whole lot easier!

Entities card

- type: entities
  entities:
    - entity: input_datetime.espressomachine_starttijd
      name: Starttijd
      icon: mdi:refresh
      tap_action:
        action: call-service
        service: script.espressomachine_timer_resetten

Service call

service: input_datetime.set_datetime
data_template:
  datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
target:
  entity_id: input_datetime.espressomachine_starttijd

Sorry, didn’t realise it’s not installed by default. It’s this Conversation - Home Assistant

Based on the documentation for the Conversation integration, it would require a custom intent to be able to handle “turn off the heating at 5am” (because the default intent is restricted to turning an entity on/off now).

I suppose you could create something like “turn [command] the [thing] at [scheduled_time]” but, as you can see, there’s nothing for free and you have to program it before it becomes “partner friendly”.

Yeah that’s true, more of a feature request than a WTH :slightly_smiling_face:

That’s clever, I don’t mind the setup if it means I can quickly toggle switches at a future time. I voted for you.

1 Like

If you’re interested in using an Automation Blueprint, here are two examples:

One-Time Scheduled Action

The first one looks like this:

It allows you choose an action (or more than one action) and the time when it should be performed. The resulting automation will trigger at the scheduled time, perform the action(s) you specified, then disable itself.

BLUEPRINT: One-Time Scheduled Action
blueprint:
  name: One-Time Scheduled Action
  description: Perform an action at a scheduled time.
  domain: automation
  input:
    what:
      name: Action to do
      description: What kind of action?
      selector:
        action:
    when:
      name: When to do it
      description: When should the action occur?
      selector:
        time:
trigger:
  - platform: time
    at: !input when
condition: []
action:
  - choose:
    - conditions: '{{ true }}'
      sequence: !input what
  - service: automation.turn_off
    target:
      entity_id: '{{ this.entity_id }}'

One-Time Scheduled Toggle

The second one looks like this:

It’s designed to simply turn on/off an entity at a chosen time. You specify the command (on or off), the entity, and the time. The resulting automation will trigger at the scheduled time, turn on (or off) the specified entity, then disable itself.

BLUEPRINT: One-Time Scheduled Toggle
blueprint:
  name: One-Time Scheduled Toggle
  description: Turn something on or off at a scheduled time.
  domain: automation
  input:
    what:
      name: Action to do
      description: On or off?
      selector:
        boolean:
    which:
      name: Entity to control
      description: Which entity?
      selector:
        target:
          entity:
            domain:
              - light
              - switch
              - input_boolean
              - climate
    when:
      name: When to do it
      description: When should the action occur?
      selector:
        time:
variables:
  command: !input what
trigger:
  - platform: time
    at: !input when
condition: []
action:
  - service: "homeassistant.turn_{{ iif(command, 'on', 'off') }}"
    target: !input which
  - service: automation.turn_off
    target:
      entity_id: '{{ this.entity_id }}'

The second example is faster to use if all you want to do is turn on/off an entity. If you examine the blueprint, you’ll see it limits the selection of entities to light, switch, input_boolean, and climate. Feel free to add other entity domains that can be turned on/off.


NOTE

As mentioned, the blueprint generates an automation that disables itself after it has executed. For example, it turns on a switch at 11:00 today and never again, because it disables itself. Should you ever want the automation to run again on another day, just re-enable it (before its scheduled time).

2 Likes

It’s at the top of every overview page. Every HA has it. Looks like a microphone, when you hover over it, it says “start conversation”. Might be hardware dependent.

I don’t have that icon. Probably because I’m using Firefox.

image

Do you have a mic? I think it’s specifically for voice to text, so it may look for a microphone. I have one configured (but not on) and when I press the button it claims it cant hear anything and wants me to type.

image

it “works”…

There’s no microphone on my old laptop (Ubuntu/Firefox) so I tried with my phone (definitely has a microphone), with Chrome browser, and there’s no microphone icon in the top-right corner. :man_shrugging:

:man_shrugging:

No worries; just wanted to establish the fact that it seems to need some prerequisites to work in a browser and all of the devices I normally use fail to qualify.

I thought the conversation integration wasn’t enabled by default. Personally, I listed it in my configuration.yaml. Fun little segue lol

would ya look at that, I have it. @123 it’s probably what @bwduncan mentioned. It’s in default config, I have a little scraper that suggests adding integrations to configuration.yaml. Must have added it at some point.

EDIT: It’s not in default config. I must’ve tested it in a beta at some point and forgot about it.

Based on what I have read about the Conversation and Intent Script integrations, I believe they can be used to support a phrase like “turn off the heating at 5am”.

However, if one considers it inconvenient to create an automation then this process wouldn’t be seen as a shortcut.

1 Like

I agree, but setting up the automation once is worthwhile, even if it takes a lot of effort. When I want to go to bed and I just need to toggle a switch while I’m asleep, I need something quick. Sadly I have not had the time even to look at the above suggestions in detail, although they all look promising. Thanks everyone for your support :smiley:

Is that a change of heart? Because it’s not the impression I got from your initial posts:

Is the easiest way to do it really to create an automation and then remember to delete it tomorrow? What the heck?

It’s a lot of taps to get from the dashboard to creating an automation

I was hoping for a more “partner friendly” approach.

Maybe slightly! It’s a similar objection to @CentralCommand 's that having to go to the developer tools is inadequate.

There’s also a big difference between having to navigate a long way to edit an automation and having to remember to disable it tomorrow. The latter is unacceptable. I think you have proposed solutions which avoid this problem neatly.

I think what I’m saying is that a “template” which lets me make a one-shot timer automation (like those proposed above) is acceptable, but creating an entire automation from scratch each time is not.

To be clear, none of the suggestions are for a “one-shot timer”. The word “timer” has special meaning in Home Assistant (an entity that counts down a given duration). What you’re after is something that executes at a scheduled time just once (i.e. doesn’t execute on a daily basis at the scheduled time).

You can achieve it with an automation or a script. For added convenience, a blueprint can be used to generate the automation or script. Of course you first have to create the blueprint itself but that’s been done for you (by CentralCommand for scripts and me for automations).

You can also make it even more convenient than using a blueprint by employ Conversation/Intent Script. Then it becomes as easy as just speaking the phrase. However, first you have to create the means of recognizing/acting on the phrase.