Trigger automation when values are always == true

Trying to wrap my brain around this… but, it’s that time to take a step back from hours of troubleshooting and hoping someone can help. I understand that when using trigger templates in automations, that the value needs to move from false → true. However, I’d like my automation template to choose which template is true at the time (at least for the actions I’m looking for). Any thoughts on how to get around this? My example is leveraging an automation to choose between 3 conditions, and execute a watering script accordingly based on the “true” value.

Value template:

{% set today = (states('sensor.rain_fc_in_1_hour') | int + 
   states('sensor.rain_fc_in_2_hour') | int +
   states('sensor.rain_fc_in_3_hour') | int +
   states('sensor.rain_fc_in_4_hour') | int +
   states('sensor.rain_fc_in_5_hour') | int +
   states('sensor.rain_fc_in_6_hour') | int) / 6 %}
{% set today_fc = states('sensor.temp_fc_high_today') | int %}
{% set months = now().month %}
{% if (today <= 45 ) and (today_fc >= 80 and today_fc <= 89) and
months == 3 or months == 4 or months == 5 or months == 6
or months == 7 or months == 8 or months == 9 or months == 10%}
{% endif %}

((this renders true, for today - confirmed in developer templates))

This template would always render as just a bunch of whitespace, as there’s nothing inside the if statement. If you want it to render as true or false, then replace the if with something that evaluates to true or false. I’ve also changed the months conditions to be expressed more succinctly. Since everything is an and now, I’ve removed the unnecessary parentheses.

{% set today = (states('sensor.rain_fc_in_1_hour') | int + 
   states('sensor.rain_fc_in_2_hour') | int +
   states('sensor.rain_fc_in_3_hour') | int +
   states('sensor.rain_fc_in_4_hour') | int +
   states('sensor.rain_fc_in_5_hour') | int +
   states('sensor.rain_fc_in_6_hour') | int) / 6 %}
{% set today_fc = states('sensor.temp_fc_high_today') | int %}
{% set months = now().month %}
{{ today <= 45 and today_fc >= 80 and today_fc <= 89 and
months >= 3 and months <= 10 }}

There’s only one template in your question, so I wasn’t sure what you meant by this.

Hi bbow987,

I am always personally shy about putting too much complexity in a trigger template. With limited templates and such it gets real frustrating real fast.

My suggestion is trigger on a simple state change of 'sensor.temp_fc_high_today', then template the hell out of the condition statement using trigger.to_state. You are almost always better off.

I mean that trigger template will evaluate on every change of tthat entity anyway, so there is virtually no performance penalty. And you have all your jinja’s…

Thanks for the feedback!! I think trigger off that and using the template as a conditional statement makes the most sense! I was looking to put NASA specs on a pencil.

1 Like

Two things I knew would come from my post 1) solution and 2) Someone woukd see my janky code and help simplify. Much appreciated, i didnt realize [average] was available in the syntax!!

Much appreciated on the feedback!!