Now I understand why the action isn’t executed.
The following condition means the action will be executed only if the current time it matches the input_datetime whose default value is 20:00:00
.
{{ states('sensor.time') == states('input_datetime.irrigation_auto_time')[0:5] }}
That’s fine but look at what triggers the automation. It triggers when any of the input_booleans change state, which could be at any time and unlikely to occur precisely at 20:00:00
, and sensor.date
which changes at midnight, never at 20:00:00
. In a nutshell, the triggers never occur at 20:00:00
so the condition will never be met and the action is never executed.
Because you want this automation to run at a given time (determined by the input_datetime) the automation must be evaluated every minute. Therefore the simplest solution is to use a Template Trigger that checks if the current time matches the specified time. In other words, the condition you defined ought to be the automation’s trigger.
The resulting automation looks very similar to the original one I proposed. I had mentioned that it would need a more appropriate trigger than simply using sensor.date
and now it does:
automation:
- alias: Irrigation.Irrigate
trigger:
- platform: template
value_template: >-
{{ states('sensor.time') == states('input_datetime.irrigation_auto_time')[0:5] }}
condition:
- condition: template
value_template: >-
{% set entity_id = 'input_boolean.' ~ now().timestamp() | timestamp_custom('%A') | lower %}
{{ is_state(entity_id, 'on') }}
- condition: template
value_template: >-
{{ states('sensor.history_rainy_past_two_days') | int < states('input_number.irrigation_rainthreshold') | int }}
action:
service: script.rainbird_irrigate
So what will trigger this automation? It will trigger when sensor.time
changes state so that’s every minute. It will also trigger when the input_datetime changes state (i.e. you change the desired irrigation time).
It will only proceed to evaluating the conditions if the current time matches the specified irrigation time. If it’s a match, it checks if the today’s input_boolean is enabled and if recent rainfall is less than the threshold value. If both conditions are met, it calls the irrigation script.
NOTE
The two Template Conditions could be combined into one but sometimes, in the interests of clarity, it’s advantageous to keep them separate.