The example I posted simply shows where to put the Template Condition in your existing automation.
It gets processed only when the automation is triggered by its second State Trigger (i.e. the one detecting the binary_sensor’s state-change to off).
If the binary_sensor’s previous state-change (which would have been to on) occured less than 7 hours ago, the actions to send a notification and set the Select entity are executed.
If that’s not what you want then I have misunderstood your stated requirements.
If I add this template condition to the ‘OFF’ action then it will turn off, as long as it was turned on within the last 7 hrs.
However, I need it to be more specific than that…
The intelligent dispatch entity triggers every day at 2330 on, and off at 0530. I have an entire set of schedules configured on an inverter to handle this daily schedule fine, which doesn’t involved HA. I’ve used HA for 3+ years now, and occasionally for what ever reason my battery would not charge as the mode change did not make it to the inverter using node red. This way is more reliable…
However, the intelligent dispatch object may turn on outside these hours, due to various edge cases, and octopus deciding to charge my car. As it stands unless I change the status of the battery to ‘Keep Charged’ my battery will then charge the car… defeating the whole point. Hence the condition on the ‘ON’ trigger to define what is outside the normal charging window…
- condition: time
after: "05:30:00"
before: "23:30:00"
So what I would like is for the OFF action to fire, only if the conditions were met within the last 7 hrs for the ‘ON’ trigger… not the intelligent dispatch entity. This is needed as at the end of the intelligent window I need to change it back to 'Self - BatteryLife` otherwise the inverter schedule keeps it on the ‘keep charged’ mode as that is what is was when it began its schedule…
If I understood your additional requirement correctly, add a third condition that checks if the state of the Select entity is Keep charged (because only the automation is permitted to set it within the allowable time period).
First condition confirms trigger.id is Off.
Second condition confirms the previous state-change occured with the last 7 hours.
Third condition confirms battery mode is Keep charged.
If that doesn’t achieve your goal then, unfortunately, I didn’t understand your explanation.
That ok, I appreciate the help. However, I only want to run the second action if it was the automation that has triggered it in the first place as per the title of the post.
Sure, I can add lots of conditions to the OFF based on the states of other entities but now I’m having to explicitly define all these conditions and edge cases.
I’m going to go for a different path, which is to remove the off, and have it defined as a sequence from the on action… see how that works.
That’s exactly what is accomplished by what I had suggested in my previous post.
Describe a scenario where, using those three conditions, the second actions can be executed if it was NOT the automation that had originally executed the first actions.
Which is the main purpose of conditions. After the automation is triggered, conditions ensure actions are executed only for desired circumstances.
Correct. The time spent idling by a delay, wait_template, or wait_for_trigger represents a window of opportunity to be terminated by a restart.
The best practice is to minimize this “window” and that’s usually done by restructuring the automation to trigger on multiple events.
Just an idea: Can we do two automations, one for each trigger. And then at the start of the sequence of actions of the automation #1, you turn off automation #2, and at the end of the same sequence you turn automation #2 back on…?
That way, the automation #2 would never be able to run during the sequence of actions of automation #1, even if/when trigger #2 being triggered.
Less elegant and ugly 2 separate automations for the same thing… definitely rooms to optimize… but easier to understand and maintain for my simple brain.
That’s not a recommended design pattern plus the problem is likely to be solved with what has already been suggested (however it’s being pre-emptively dismissed without any report that it actually failed during testing).