Wth: one shot timer

This is really dumb but I just want to say “turn off the heating at 5am”.

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

If you want Home Assistant to do anything based on an event (time, state-change, etc) you’ll have to create an automation.

If it’s designed to perform its action exclusively tomorrow at 05:00 then there’s no need to delete the automation afterwards because it’ll never run again.

Just name the automation “One shot” and you can re-use it in the future for other one-time-only purposes.

As an added touch, you can have the automation disable itself by simply adding the following service call at the very end.

- service: homeassistant.turn_off
  entity_id: '{{ this.entity_id }}'

By doing that, the Automation view will display a prominent “Disabled” tag next to the automation’s name.

1 Like

Thanks. Yeah, I guess that’s the solution. It’s a lot of taps to get from the dashboard to creating an automation for what should be as simple as saying “turn off the heating at 5am” in the conversation box. Is this really how people do it? I was hoping for a more “partner friendly” approach.

I could set up an input helper time/boolean pair for each entity I might want to turn off at a certain time, but this also seems excessive for what seems like a really simple task. Unix has been able to perform a one-shot action at a specific time for decades using at.

I really appreciate your reply and I will try it out, but I’m still left with a general “what the heck” feeling!

(In the end I thought a bit more about what I actually meant tonight, and I have created an automation which switches off the heating when the price of electricity goes above 4p/kWh, which will happen at 5am)

2 Likes

There’s no voice input in Home Assistant to perform tasks so what’s this “conversation box” you mentioned?

It’s in the Android app, at least. Click the three dots and tap the mic icon labelled “start conversation”. It can turn things on and off, I’ve not played with it much further.

It’s there on mobile dashboards too, and I’m pretty sure it’s there on desktop Lovelace as well.

Where exactly?

Ok so you can actually do what I believe you want. But unfortunately you can’t do it in a dashboard right now.

What I believe you want is to make a script like this:

- alias: Turn a light or switch on or off at a time
  mode: parallel
  fields:
    devices:
      name: Devices
      description: List of lights or switches to turn on or off
      example: switch.heater
      selector:
        entity:
          domain:
            - light
            - switch
          multiple: true
    turn_on:
      name: Turn on
      description: True to turn on, false to turn off
      default: true
      example: true
      selector:
        boolean:
    time:
      name: Time
      description: Will turn the switches on or off at the specified time
      example: "05:00:00"
      selector:
        time:
  sequence:
    - alias: Wait until the specified time
      wait_template: "{{ now() >= today_at(time) }}"
    - alias: Turn the things on or off
      service: "homeassistant.turn_{{ 'on' if turn_on else 'off' }}"
      data:
        entity_id: "{{ devices }}"

Because if you make this script and then go to Developer tools → Scripts to run it I think you’ll see its exactly what you’re looking for:

Other then the “go to yaml mode” what you’re looking for right? Select the devices, choose on or off, pick a time and run it, it’ll turn them on or off at the time you picked. Anyone could use this if it was on a dashboard. Can use this same script as many times as you want with different tasks and times and each run just does one thing.

If you’re like me this all sounds great. Until you realize the only place you can see a script like this is in developer tools. If you put this script in a dashboard all you get is a “run script” button with no parameter entry. Useless :angry:

This was my own WTH moment a while ago that I forgot about until you reminded me just now. If you also want this now, feel free to vote for it:

2 Likes

Be advised that if you create a script containing any of the following statements:

  • wait_template
  • wait_for_trigger
  • delay

When running, the script will be terminated if any of the following events occur:

  • Home Assistant is restarted.
  • Reload Scripts is executed.
  • You use the Script Editor to create/modify a script (because it will automatically execute Reload Scripts)

In contrast, an automation with a Time Trigger would not be affected by a restart/reload unless it occurred at the Time Trigger’s scheduled time (and there’s a way to mitigate that).

I’ve often had a thought similar to this.
Say I’m in an area of the house where nobody else is and I need to carry something cumbersome out…I can’t reach the lightswitch to turn off the light and would have to return to that area after moving said cumbersome thing out.
So what if I could select the switch in the companion app or voice assistant (or anywhere) and have HA turn light on for 15 minutes. Then I could do what I need and leave the area knowing the light will go off and I can move on to the next thing without trying to remember to go back and turn off that light.

I’m sure there are many ways to approach this, but I agree that something like this would be nice to see in the UI.

2 Likes

Very true. I fully admit my script could be optimized to eliminate those. Like perhaps by stuffing the date and details into helpers and then having an automation that triggers off them.

My point was really to raise that if you make a script with inputs and selectors you can essentially craft a nice form that does what you want and hides all the technical details from users. But for some reason there’s no way to show that form on a dashboard right now.

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”…