WTH isn’t there a "queue last" or similar option for script modes?

I am often in a situation where what I want a script or automation mode that is essentially “queue 1 call and keep only the most recent call.” A simple example is a script that sets the brightness of a specific light. If it is called multiple times in succession while still running, the ideal thing would be to finish the current call and then start a new call with only the most recent brightness rather than setting all the settings in between in sequence or, worse, dropping the most recent calls once a queue is filled.

Sometimes “restart” works for this purpose, but sometimes a script has other effects where it would be undesirable to cancel it. The difference between this and a queue of length 1 is that a second call while it’s still running is currently dropped, and I would like that call to replace the old one in the queue. You could generalize this to a “stack,” keeping the most recent n calls (analogous to a queue of length n). I don’t personally have many uses for stacks bigger than 1, but maybe others do, and this would work for my purposes.

And apologies if there’s a way to do this now and I just haven’t found it. Thanks!

Scripts and Automations have a current attribute. You can put that in a condition that requires current to be 1.

I think that should work in your case.

To test you could create a template condition that writes:
{{ is_state_attr('script.<name>','current',1)}}

I guess this you can also use the ‘this’ approach, but I am not sure. So testing by mentioning the actual script is the safest.

The this approach: {{is_state_attr(this.entity_id, 'current',1)}}

1 Like