jtroberts
(Jonathan Roberts)
July 30, 2025, 2:54pm
1
Trying to do a simple automation at 6AM and then add a template based on Unix epoch to define odd day or even day. AKA: every other day. So If I set an “ID:0” in the template for even days and ID:1 for the odd template I can then use “CHOOSE” in the “DO” section.
Even template: "{{ (now() - as_datetime(‘1970-01-01T00:00:00Z’)).days % 2 == 0 }}
Odd template: "{{ (now() - as_datetime(‘1970-01-01T00:00:00Z’)).days % 2 == 1 }}
I’m just trying to create a way to to do X on even days and Y on odd days in a single automation
Ohh and I can’t flip it to set the 2 templates and ID’s as a trigger and then have a simple “AND at 6AM” because the time options under the AND CONDITION are are before and after, It would be great if I could just do AT 6AM for the AND CONDITION block.
Appreciate all the help in advance
Hi @jtroberts
Assuming you templates produce the require true or false, I think you should…
Have your time based trigger. No conditions in the And If section, then…
Put an if-then action in the actions and use one of your templates as the condition for the if-then.
That way, you don’t need trigger IDs because the if-then action simply chooses the next step based on the output of your template.
Let me know if you need more detail
jtroberts
(Jonathan Roberts)
July 30, 2025, 3:35pm
3
nice! ok I see how that works in the GUI and that should 100% work.
I hate to say this but I used AI to assist and helped point me in this direction. I’ll see which makes most sense but I think the right code is the code that works
Thanks for the reply
alias: Water The Lawn
description: ""
triggers:
- at: "06:00:00"
trigger: time
actions:
- choose:
- conditions:
- condition: template
value_template: "{{ (now() - as_datetime('1970-01-01T00:00:00Z')).days % 2 == 0 }}"
sequence:
- action: notify.mobile_app_jonathans_iphone
metadata: {}
data:
title: Irrigation Even Day
message: LKN Irrigation Started
- type: turn_on
device_id: 1dc708a205f9d00327c5455196843e6c
entity_id: de55c77722088c7297a0ac3eef6c7b2a
domain: switch
- action: switch.turn_on
metadata: {}
data: {}
target:
entity_id: switch.irrigation_back_yard
enabled: false
- delay:
hours: 0
minutes: 6
seconds: 0
milliseconds: 0
enabled: true
- action: switch.turn_off
metadata: {}
data: {}
target:
entity_id: switch.irrigation_back_yard
enabled: true
- action: switch.turn_on
metadata: {}
data: {}
target:
entity_id: switch.irrigation_right_side_yard
- delay:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
- action: switch.turn_off
metadata: {}
data: {}
target:
entity_id: switch.irrigation_right_side_yard
- type: turn_on
device_id: 1dc708a205f9d00327c5455196843e6c
entity_id: c3da9152345aafe98c07f32339a980e7
domain: switch
- delay:
hours: 0
minutes: 15
seconds: 0
milliseconds: 0
- type: turn_off
device_id: 1dc708a205f9d00327c5455196843e6c
entity_id: c3da9152345aafe98c07f32339a980e7
domain: switch
- type: turn_on
device_id: 1dc708a205f9d00327c5455196843e6c
entity_id: 2d35919b651dfce0a07cd904d276c04e
domain: switch
- delay:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
- type: turn_off
device_id: 1dc708a205f9d00327c5455196843e6c
entity_id: 2d35919b651dfce0a07cd904d276c04e
domain: switch
- type: turn_on
device_id: 9cd65978ce8350c18fe7109785c3a10d
entity_id: fa668113ed6e7a05be30c5b6f9f982fc
domain: switch
- delay:
hours: 0
minutes: 5
seconds: 0
milliseconds: 0
- type: turn_off
1 Like
AllHailJ
(J Gent)
July 30, 2025, 5:01pm
4
I only get to water my lawn on certain days which are not even or odd but days of week. I created a template sensor to do this.
#--------------------------------------------------------------------------------------------------
# Day to Water
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "watering_day"
unique_id: "watering_day"
state: >
{% if states('sensor.my_weekday') == '0' %}
1
{% elif states('sensor.my_weekday') == '2' %}
1
{% elif states('sensor.my_weekday') == '4' %}
1
{% else %}
0
{% endif %}
then my watering schedule to prevent runoff
- id: '1627491913964'
alias: Water Lawn with repeat
description: Water all zones with repeat
trigger:
- platform: time
at: input_datetime.cycle1
- platform: time
at: input_datetime.cycle2
- platform: time
at: input_datetime.cycle3
- platform: time
at: input_datetime.cycle4
- platform: time
at: input_datetime.cycle5
- platform: time
at: input_datetime.cycle6
condition:
- condition: state
entity_id: sensor.watering_day
state: '1'
- condition: state
entity_id: input_boolean.run_irrigation
state: 'on'
action:
- repeat:
count: '11'
sequence:
- variables:
zone: switch.zone_{{ repeat.index }}
- service: switch.turn_on
target:
entity_id: '{{ zone }}'
- delay:
minutes: '{{ states(''input_number.zone'' ~ repeat.index) | int }}'
- service: switch.turn_off
target:
entity_id: '{{ zone }}'
mode: single
I control all the times through input variables.