Native support for negative delay

It’s possible to delay automation action for example by two hours by using “- delay: 02:00:00”. It would be great if it was possible to use negative values in delay, causing action to happen before set time. That would cause automation to check triggers and conditions before given time: for example, “- delay: -02:00:00” would trigger two hours before.

For example, the user has set up time “09:00” on UI. With two hours negative delay, and if possible other conditions are met, this automation triggers at 07:00 instead.

Gilean, you are confusing a service which happens in an action or sequence (delay) with something you can apply to a trigger.
This is not the same and as you have seen on your other thread already possible.
If you already know you want it 2 hours in advance then you can offset the input time (as you currently are doing or
Trigger it two hours early and wait.
Eg I want a light to come on at a random time between 19:00 and 21: and it should stay on for random between 30 and 60 minutes
Then you trigger it at 19:00 determine how long you should wait for it to start then start it, then calc how long to run.

So Always trigger your automation at the start time, look at the temp, if it’s below x turn on, then wait an hou, if it’s below y, turn on
Or just use the examples given

Um, can’t you just change trigger time of the automation to two hours earlier?

Maybe if you post your specific use-case forum members could help you find a solution w/ current functionality?

He’s referring to starting his car heating depending on temp, see other thread

Well, I did a feature request as other user encouraged me to do so… :slight_smile: I began to think this might not work simply as negative delay, but thought that maybe something else would be implemented anyway eventually… :no_mouth:

Ah, so basically you mean if I set up my leaving time at 10:00, then the automation triggers at 07:00 (or, ALWAYS three hours before given time) and then turns on the heater if a condition (temperature) is met, but if not, then wait for one hour and check the temperature again etc? When I think it that way, then yes, the logic must happen in trigger and not in action :slight_smile:

In effect that was the way ALL the other suggestions were pointing you, but they are a bit less than clear as Petro knows this stuff backwards and just goes in at the deepend.
To be honest that was where I was going. You set your trigger and a mx+c graph between 0 houra and 3 hours with your temps at both ends then trigger at (say 07:00 but when can get this as you’ve seen from 10:00) and the calc says ‘wait 51 munutes before turning on
You should continue this on the other thread as no one will vote for this. There are far too many other things we need to get done first.

If I could negative vote, I would. I can’t see the use case for this idea.

2 Likes

I think there should be forum support for down voting, some proposals are simply ridiculous, and generally only ‘seem’ have an application in home automation if you are completely bladdered and viewed from 3.25 parsecs

Edit: in comparison, this one is reasonably sensible, but I still wouldn’t vote for it as I think I can do simple subtraction in my head.

Have a template sensor based off the ui sensor and trigger from that?

Here is a great example where a negative delay would be super useful:
I would create an automation that is triggered when retrieving the lottery results on Saturday evening, then I would set a negative delay of say 12 hours and then have an action to send myself a notification to play those exact numbers when I’m still in the mall on Saturday morning. :partying_face:

Could you not create a template sensor for the current time + 2 hours and compare that to the trigger time?

I use this to run the heater/cooling 15 minutes before my alarm goes off:

      time_plus_15min:
        friendly_name: 'Time +15min'
        value_template: >
          {{ (as_timestamp(now()) | int + 900) | timestamp_custom("%H:%M") }}
        entity_id: sensor.time

Then the automation:

- id: alarm1_execute
  alias: 'Alarm 1 Execution Script'
  hide_entity: True
  initial_state: 'on'
  trigger:
    - platform: template
      value_template: "{% if states.sensor.alarm1_time.state == states.sensor.time_plus_15min.state %}true{% endif %}" 

This will then trigger 15 minutes before my actual alarm goes off.

1 Like