Dynamically timed actions

Hello,
Lately I’m becoming a bit annoyed with lack of ability to quickly disable some automation for a specific period of time or turn something on for a specific time and turn it off afterwards. I’m not talking about an automation that would do this on a regular basis. I’m talking about timers similar to what many closed systems like Tuya have. Like I plug something in the power socket and I want it to run 20 minutes, but only this one time. Next time maybe I’ll do 10 minutes or 4 hours. Or I’m sick, so I want to disable my morning alarm routine for the next X days and then have it automatically enabled without having to remember about it.

So… I really hope I’m missing something. Is there any way to do this in HA, without setting up a lot of automations and helpers, basically for each individual action? How do people handle this topic in HA?

You have to set up automations and helpers.
Automations and helpers are the most flexible way, so you can do everything you may wish for.
The locked in solution in Tuya limits you to just the ways they see fit to support.

So it either your way or their way, all the way.

You don’t need to convince me about the disadvantages of Tuya and similar locked solutions. I’m already convinced, that’s why I’m here :smile: Sadly, the automations and helpers are simply too complicated for one-time situations I’m struggling with here. I’m not going to set up an automation that I will just use once, especially since the list gets cluttered so easily. So there is no other solution for this?

There are probably blueprints for it.
I use Node Red for many such things, which is quite easy to set up once you get a hang of it.

I have a bunch of automations that use an input boolean (toggle) helper as a condition. That way, one click from a dashboard, and that automation won’t run again until I say so.

As @WallyR has said, using helpers like this, and timers could do what you want. You’d just have to engineer these into your automations to make them make use of them.

I’ve got automations that also update helpers used by other automations - it’s a bit of a rabbit hole but it’s not too deep and works well! - as well as dashboard helpers to override or disable things

Umm, you don’t need helpers for that. Automations are entities, you can add them directly to the dashboard. I have some in the entities card, works fine. But it’s not what I need. I don’t want to have to manually turn them back on after X minutes. And yes, I could make a script or automation to do that, but I would have to edit it every time.

Right, I know it’s possible like that, but I hoped there was a way to do it on the fly, without needing to create special automations for the specific thing. Like, I have a script that runs water pump for 15 minutes and then disables it. And yeah, I guess with a bit of tweaking and some extra helpers, I could make it so I can adjust the time every time I run this script. And even that seems to me to require a lot of setting up. But that’s just one specific action, and I would want to have this available for any action, any script or automation or service.

I can see how this could be a blueprint. However, correct me if I’m wrong, but blueprints work in such way that you can only create automations from them. So I could have a blueprint that takes as input action that I want to take now, another input for delay, and another for action to take after the delay. That would be nice, but each time I would use it, it would create an automation, which I would then need to run, right? There is no way to have it so the blueprint just runs once with the inputs I give it at that specific time?

You could write a script that disables an automation for a period of time (or permanently), and the automation to be disabled is passed in as a variable, that way the script would be re-usable.

You’d then simply create a dashboard with buttons for the automations you’d want to disable.
You wouldn’t need any helpers or individual automation changes if you went this way.

You’d then need another script, or another variable in the same script to say whether you are turning the automation on or off.

Maybe something like:

alias: Turn on/Off Automation
sequence:
  - service: automation.turn_{{action}}
    data:
      stop_actions: true
    target:
      entity_id: "{{ target_automation }}"

Where you pass in 2 variables, ‘action’ and ‘target_automation’

You could extend this further with a third variable which could pass in the number of minutes you want the automation disabled for.

That would be very useful, but I don’t know how to pass a variable to a script from Lovelace. Can you explain it in more details or point me to the right place in documentation? Thank you!

See the edit above for a rough idea of the script.

As for passing a variable from a lovelace card, check out this post:

Let’s go into more detail with trhis example. In an ideal world what would you want the above to do? And, you want to be able to do it pretty much automatically in a generic way that is reuseable? You could have it work with some logic that would determine the duration from past events - or the current water level - is that what you mean?

Thank you, that’s very interesting. As I understand, this would require to hardcore the variables in the yaml of the Lovelace card with the script, right? Or is there a way to have the input fields in the card itself? Maybe somehow with helpers?

@Fanful - You could create a select helper and list the names of the automation entities in there, then use this to target the automation you want to turn on or off.

I do something similar with turning on scenes in a room with lights like so…

Create an automation that has a trigger like so:

image

platform: state
entity_id:
  - input_select.kitchen_scenes_list
to: null

Which basically means, anytime you change the currently selected value on the input select helper, the automation will fire.
The automation then calls the script (or does it itself… up to you).

In a perfect world I would have a card in Lovelace that would let me select a toggleable entity or automation with a drop-down menu, select time (be it in minutes, hours or days), and then it would turn the entity or automation on for the specified time, then it would disable it. Another card could work the opposite way (disable something and then enable it).

And I would want this to be wife friendly, usage shouldn’t require changing any code.

I guess in a perfect world I would also want this to be logged nicely and it would somehow show not only what was triggered when in the past, but also any actions that are still waiting to be triggered. But that’s much less important.

See my update above. All of this is possible with a bit of work.

Thanks, that is very helpful. I didn’t know half of that is possible. I’ll play around with it.

Yes, I use Text Input Row but there are other options.

I’ve been playing around with scheduling one-off actions by having a card that creates calendar events with an intent sentence saved in the event’s summary. Then an automation, triggered by the event, pipes the intent into the conversation.process service.

image

This method does currently have some annoying limitations…

  1. There aren’t currently built-in intents for a lot of actions, including things you mentioned like enabling/disabling automations so you have to build your own intents and intent scripts for those.
  2. Calendar trigger listeners are only updated every quarter-hour, so any event scheduled less than 15 minutes in the future has to be done so carefully. For example, if it’s currently 15:20 and you want something to happen in 10 minutes, you need to set the event start for 15:31so that it happen after the calendar trigger listener has updated.