#Trigger every 10 minutes but only if another value is set

1 messages · Page 1 of 1 (latest)

glass basin
#

I am writing a blueprint that will have many function. One of the optional functions is to rotate an image background every 10 minutes (or user defined time). It is optional so I would like a trigger that will trigger every 10 minutes but only if the user enables the option from the blueprint.

I do not think I can do this with the normal time trigger without using a condition down line. That isn't great as users who do not want the trigger will still see this automation being triggered even if the rotation is not happening. Can a template trigger be used instead? If so, how would it be written so that it fires every X minutes?

royal pelican
#

If you have a condition in the conditions: section of the automation (the “and if” section in the UI) and that condition is not met after a trigger is fired, the automation will generate a trace but it will not update the last_triggered attribute. So the only way a user would know the trigger was fired would be if they looked at the traces.

#

That being said, to answer your question, yes you could do this with a template trigger without any conditions

#

Something like {{ now().minute % 10 == 0 }}

#

That will fire when the minutes of the hour are evenly divisible by 10

glass basin
# royal pelican If you have a condition in the `conditions:` section of the automation (the “and...

Ahhh. Very cool. I had thought about changing the regular trigger value to 23 hours (max value from what I can see) with the trigger condition for those who do not have it enabled to reduce the occurence. From what you have written above I think that would probably be the easiest for me.

The template approach will work but if the user sets to change every 45 minutes or some other oddity it would make this approach problematic. I just used ten minutes as an example.

royal pelican
#

you can do something more general like this:

{% set interval_seconds = 45*60 %} 
{{ now().timestamp() % interval_seconds < 60 }}
#

or whatever units you want, you just have to math it out

{% set interval_minutes = 45 %} 
{{ (now().timestamp() / 60) % interval_minutes < 1 }}