Template condition for all timers

Hi All

I am really bad at templates and normally always manage to put together what I need even if its long winded. Over the years I have created template binary sensors for example to show on/off OR true/false for a group of devices (normally in the same domain) like all external doors for example and then I can easily use this in automation and scripts as a condition.

However as I grow with HA so do the number of devices and entities etc and I wonder if someone can help explain how I could be a little more intelligent by using templates directly in the automation or script as a condition.

For example something I want to do at present is have a template condition that is only true if all timers are not active (idle). Would someone be so kind as to show an example on how I can make this type of template without having to make a sensor like I normally would as in this use case I am highly likely to add more timers and I guess by learning the correct templating I can avoid having to remember to add any new timers to my template binary sensor moving forward.

Thanks in advance

If you are just interested in HA timer helpers then you can use:

{{ states.timer | selectattr('state', 'ne', 'idle') | list | count > 0 }}

1 Like

Thank you, that’s brilliant. It’s always seems so obvious when you read it out after the fact.
Like most new template stuff I learn this gives me lots of stuff I can now tidy up with this and variations of this.

Thanks to your kick start I was able to work out everything I needed so thanks again.

My project to have a Lovelace button that triggers a configuration check, reports back results, checks no timers, scripts and or automations are currently running and then restarts home assistant is now complete.

Big learning curve and a serious amount of hours this weekend but loads of fun none the less.

I just need to go and get out a bit more now :joy: