Just to clarify, your change didnāt make it skip the condition, I noticed the "\ at the beginning and end, deleted them with the original script and the virtual switch comes on when the phone switch goes off.
Ok, I see now that Iām getting this backwards.
So the state.last_changed doesnāt include the triggered action Iām guessing.
Right now, if the phone switch is on for at least 13 seconds, then I turn it off, the virtual switch goes on. I tried this with different times and it worked when it should and didnāt when it shouldnāt.
So what would I do to get what I wanted? Which is when the phone switch gets turned off, 13 seconds later the virtual switch turns on?
I didnāt mean to say your change did nothing if thatās the way you took it. Just giving facts.
I never mentioned an error message so not sure what you mean. Irrelevant either way.
My goal is to learn templates so your examples arenāt useful at the moment and Iāve already done it that way. Iām just learning HA and trying different things on a ātest (or lab) setupā.
Ok, so it doesnāt include the triggered action, good to know. Is there a way to make it, it being trigger.from_state.last_changed, include the state change in the trigger of the same automation?
Is there another Template that can be used to do what Iām trying?
The reason this fails is an error in logic. The trigger to off occurs immediately after the phone switch changes to off. Because of that, you condition logic will never pass, e.g. it will never have a last changed 13 seconds ago as itās evaluated immediately after turning off. You would need either:
A wait for condition,
Or change the trigger to template and include checking the state is off in what you now have in value_condition. I think this method is what you are inferring when you say āa new way to do thingsā. A template that confirms the entity state is off, and that the last changed was > 13 seconds ago.
Thatās incorrect. The template is using the values from the previous state changeā¦ which could have been days ago. However, I truly doubt that the behavior that will be elicited by that condition is actually what OP wants.
The trigger variable is an object created at the moment your automation is triggered. It contains information about the entity (switch.phone_switch) responsible for triggering your automationās State Trigger, specifically information about the entityās state before (from_state) and after (to_state) it changed.