I would really appreciate som help with Jinja2 templating
I want an if-statement that is “Good” at 05:40 or later.
{% if (now().hour >= 5 and now().minute >= 40 ) %}
Good
{% else %}
Bad
{% endif %}
Obviously the example above does only work when the hour is 5 or greater AND when the minutes are 40 or greater. At, let’s say 7:25, I will receive a “Bad” result.
Any ideas of how I can make this simple example work so it will return “Good” every day at 05:40 or later?
It does not have to be an if-statement, any solution will do.
{% set nw = now() %}
{% if nw.hour >= 5 and nw.minute >= 40 or nw.hour >= 6 %}
Good
{% else %}
Bad
{% endif %}
FWIW, I include the first statement so that all of the comparisons use the exact same time. It also makes the expression slightly more compact. Not sure if this is necessary.
And, BTW, you can also do this:
{% set nw = now() %}
{{ 'Good' if nw.hour >= 5 and nw.minute >= 40 or nw.hour >= 6 else 'Bad' }}