I’am writing an automation that take as trigger type a template.
I’ve tested the template code using the development tool, and from there looks like everything is ok.
The template is returning TRUE or FALSE as boolean.
You don’t need to explicitly return true/false. Let the template’s evaluation do that for you. The following template will return true if movieReleaseAge is less than or equal to timeNotification, otherwise it will return false.
Paste a screenshot of what you see in the Template Editor.
On the right hand side of the Template Editor, it shows all the entities that will be used to update the template. If I’m not mistaken, this template will be updated whenever the following entities change state:
Here is what is reported under the result, was cutted from the screenshot, sorry
This template updates at the start of each minute.
This template listens for the following state changed events:
* **Entity** : input_number.plex_minutes_notification
* **Entity** : sensor.recently_added_movies
Home Assistant is updated to the last version: Home Assistant 0.117.1
Are you using version 0.115 or higher? If you are, then your screenshot isn’t showing the information I wanted to see which is underneath the right hand pane of the Template Editor. It reports which entities it listens to. Here’s an example of what I’m looking for:
It indicates the template will be updated whenever any weather entity changes state and when sun.sun changes state.
Perfect, thank you. As expected, it listens to the two entities used in the template. Although it doesn’t say it, it also uses now() to update the template every minute.
Ok, So if I understood correctly, when now() or utcnow() is used in the script, it doesn’t matter when a state is changing because it is overridden by now() or utcnow().
This is probably to avoid to trigger every change of “time”.
So it is not a good practice to use it when scripting. I was reading the documentation and this is the first script/template I’m writing and I missed that part.
I will look for a better validation to avoid it. Probably the script/template it is not working because triggering every minute there are times where the result it is already FALSE.
I’m not sure if I’m misreading what you wrote or if you misunderstood how it works.
Your template will be evaluated every minute (because it includes now) and whenever either of the two entities input_number.plex_minutes_notification and sensor.recently_added_movies change state.
So if neither of the two entities ever change state, you can be assured that the template will be updated at least every minute because it uses now().
If you do not want it to be updated every minute, then you must remove now() and use something else to perform the time calculation.